Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewMckee4 committed Jan 28, 2025
1 parent 662581e commit e8147d8
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/kfactory/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,9 @@ def irotate(self, angle: int, center: tuple[int, int] | None = None) -> Self:
self.transform(t)
return self

def imirror(self, p1: tuple[int, int], p2: tuple[int, int]) -> Self:
def imirror(
self, p1: tuple[int, int] = (1000, 0), p2: tuple[int, int] = (0, 0)
) -> Self:
"""Mirror self at a line."""
p1_ = kdb.Point(p1[0], p1[1]).to_dtype(self.kcl.dbu)
p2_ = kdb.Point(p2[0], p2[1]).to_dtype(self.kcl.dbu)
Expand All @@ -511,12 +513,12 @@ def imirror(self, p1: tuple[int, int], p2: tuple[int, int]) -> Self:

return self

def imirror_x(self, x: int) -> Self:
def imirror_x(self, x: int = 0) -> Self:
"""Mirror self at an y-axis at position x."""
self.transform(kdb.Trans(2, True, 2 * x, 0))
return self

def imirror_y(self, y: int) -> Self:
def imirror_y(self, y: int = 0) -> Self:
"""Mirror self at an x-axis at position y."""
self.transform(kdb.Trans(0, True, 0, 2 * y))
return self
Expand Down Expand Up @@ -699,7 +701,9 @@ def drotate(self, angle: float, center: tuple[float, float] | None = None) -> Se
self.transform(t)
return self

def dmirror(self, p1: tuple[float, float], p2: tuple[float, float]) -> Self:
def dmirror(
self, p1: tuple[float, float] = (1, 0), p2: tuple[float, float] = (0, 0)
) -> Self:
"""Mirror self at a line."""
p1_ = kdb.DPoint(p1[0], p1[1])
p2_ = kdb.DPoint(p2[0], p2[1])
Expand All @@ -722,12 +726,12 @@ def dmirror(self, p1: tuple[float, float], p2: tuple[float, float]) -> Self:
return self

def dmirror_x(self, x: float = 0) -> Self:
"""Mirror self at an x-axis."""
"""Mirror self at an y-axis at position x."""
self.transform(kdb.DCplxTrans(1, 180, True, 2 * x, 0))
return self

def dmirror_y(self, y: float = 0) -> Self:
"""Mirror self at an y-axis."""
"""Mirror self at an x-axis at position y."""
self.transform(kdb.DCplxTrans(1, 0, True, 0, 2 * y))
return self

Expand Down
63 changes: 63 additions & 0 deletions tests/test_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,5 +448,68 @@ def test_center(dbu_instance_tuple: _DBUInstanceTuple) -> None:
assert _instances_equal(instance1, instance3)


def test_mirror_y_default_arg(dbu_instance_tuple: _DBUInstanceTuple) -> None:
instance1, instance2, instance3 = dbu_instance_tuple

instance1.mirror_y()
instance2.dmirror_y()
instance3.imirror_y()

assert _instances_equal(instance1, instance2)
assert _instances_equal(instance1, instance3)


def test_mirror_x_default_arg(dbu_instance_tuple: _DBUInstanceTuple) -> None:
instance1, instance2, instance3 = dbu_instance_tuple

instance1.mirror_x()
instance2.dmirror_x()
instance3.imirror_x()

assert _instances_equal(instance1, instance2)
assert _instances_equal(instance1, instance3)


def test_mirror_default_arg(dbu_instance_tuple: _DBUInstanceTuple) -> None:
instance1, instance2, instance3 = dbu_instance_tuple

instance1.mirror()
instance2.dmirror()
instance3.imirror()

assert _instances_equal(instance1, instance2)
assert _instances_equal(instance1, instance3)


def test_mirror_x_equal() -> None:
cell = kf.kcell.DKCell()
layer = kf.kdb.LayerInfo(1, 0)
cell.shapes(layer).insert(kf.kdb.DBox(-5, -5, 5, 5))
parent_cell = kf.kcell.DKCell()
_ = parent_cell << cell
ref2 = parent_cell << cell
ref3 = parent_cell << cell

ref2.dmirror_x()
ref3.imirror_x()

assert parent_cell.bbox() == kf.kdb.DBox(-5, -5, 5, 5)


def test_mirror_y_equal() -> None:
cell = kf.kcell.DKCell()
layer = kf.kdb.LayerInfo(1, 0)
cell.shapes(layer).insert(kf.kdb.DBox(-5, -5, 5, 5))
parent_cell = kf.kcell.DKCell()
_ = parent_cell << cell
ref2 = parent_cell << cell
ref3 = parent_cell << cell

ref2.dmirror_y()
ref3.imirror_y()

assert parent_cell.bbox() == kf.kdb.DBox(-5, -5, 5, 5)


if __name__ == "__main__":
pytest.main([__file__])

0 comments on commit e8147d8

Please sign in to comment.