# This file is part of the faebryk project
# SPDX-License-Identifier: MIT

import unittest

import faebryk.library._F as F  # noqa: F401
from faebryk.exporters.pcb.kicad.transformer import PCB_Transformer
from faebryk.libs.kicad.fileformats import Property, kicad
from faebryk.libs.test.fileformats import PCBFILE
from faebryk.libs.util import find


class TestTransformer(unittest.TestCase):
    def test_bbox(self):
        pcb = kicad.loads(kicad.pcb.PcbFile, PCBFILE)
        fp = find(
            pcb.kicad_pcb.footprints,
            lambda f: Property.get_property(f.propertys, "Reference") == "R1",
        )
        bbox_pads = PCB_Transformer.get_footprint_pads_bbox(fp)
        self.assertEqual(bbox_pads, ((-0.715, -0.27), (0.715, 0.27)))

        bbox_silk = PCB_Transformer.get_footprint_silkscreen_bbox(fp)
        self.assertEqual(bbox_silk, ((-0.94, -0.5), (0.94, 0.5)))
