Skip to content

Commit

Permalink
Fixed OddEvenRowsColumnsPosition. Added tests for placers `.rotatio…
Browse files Browse the repository at this point in the history
…n()`.
  • Loading branch information
errno authored and yaqwsx committed Mar 10, 2024
1 parent 28689df commit 49363ea
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 6 deletions.
8 changes: 3 additions & 5 deletions kikit/panelize.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ def position(self, i: int, j: int, boardSize: Optional[BOX2I]) -> VECTOR2I:
"""
raise NotImplementedError("GridPlacerBase.position has to be overridden")

def rotation(self, i: int, j: int) -> int:
def rotation(self, i: int, j: int) -> KiAngle:
"""
Given row and col coords of a board, return the orientation of the board
"""
return 0
return EDA_ANGLE(0, pcbnew.DEGREES_T)

class BasicGridPosition(GridPlacerBase):
"""
Expand Down Expand Up @@ -93,8 +93,6 @@ def position(self, i: int, j: int, boardSize: Optional[BOX2I]) -> VECTOR2I:
hbonecount * (self.hbonewidth + self.verSpace)
return toKiCADPoint((xPos, yPos))

def rotation(self, i: int, j: int) -> KiAngle:
return EDA_ANGLE(0, pcbnew.DEGREES_T)

class OddEvenRowsPosition(BasicGridPosition):
"""
Expand All @@ -120,7 +118,7 @@ class OddEvenRowsColumnsPosition(BasicGridPosition):
"""
def rotation(self, i: int, j: int) -> KiAngle:
if (i % 2) == (j % 2):
return 0
return EDA_ANGLE(0, pcbnew.DEGREES_T)
return EDA_ANGLE(180, pcbnew.DEGREES_T)


Expand Down
62 changes: 61 additions & 1 deletion test/units/test_panelize.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,69 @@
import pytest
from kikit.panelize import prolongCut
from pcbnewTransition.pcbnew import EDA_ANGLE, DEGREES_T
from kikit.common import KiAngle
from kikit.panelize import (
GridPlacerBase, BasicGridPosition, OddEvenRowsPosition,
OddEvenColumnPosition, OddEvenRowsColumnsPosition, prolongCut
)
from shapely.geometry import LineString
from math import sqrt


def test_grid_place_base_rotation():
placer = GridPlacerBase()
for (i, j) in ((0, 0), (0, 1), (1, 0), (1, 1), (2, 0), (2, 1)):
rotation = placer.rotation(i, j)
assert isinstance(rotation, KiAngle)
assert rotation.AsDegrees() == EDA_ANGLE(0, DEGREES_T).AsDegrees()


def test_basic_grid_position_rotation():
placer = GridPlacerBase()
for (i, j) in ((0, 0), (0, 1), (1, 0), (1, 1), (2, 0), (2, 1)):
rotation = placer.rotation(i, j)
assert isinstance(rotation, KiAngle)
assert rotation.AsDegrees() == EDA_ANGLE(0, DEGREES_T).AsDegrees()


def test_odd_even_rows_position_rotation():
placer = OddEvenRowsPosition(0, 0)
for (i, j, expected_rot) in ((0, 0, EDA_ANGLE(0, DEGREES_T)),
(0, 1, EDA_ANGLE(0, DEGREES_T)),
(1, 0, EDA_ANGLE(180, DEGREES_T)),
(1, 1, EDA_ANGLE(180, DEGREES_T)),
(2, 0, EDA_ANGLE(0, DEGREES_T)),
(2, 1, EDA_ANGLE(0, DEGREES_T))):
rotation = placer.rotation(i, j)
assert isinstance(rotation, KiAngle)
assert rotation.AsDegrees() == expected_rot.AsDegrees()


def test_odd_even_column_position_rotation():
placer = OddEvenColumnPosition(0, 0)
for (i, j, expected_rot) in ((0, 0, EDA_ANGLE(0, DEGREES_T)),
(0, 1, EDA_ANGLE(180, DEGREES_T)),
(1, 0, EDA_ANGLE(0, DEGREES_T)),
(1, 1, EDA_ANGLE(180, DEGREES_T)),
(2, 0, EDA_ANGLE(0, DEGREES_T)),
(2, 1, EDA_ANGLE(180, DEGREES_T))):
rotation = placer.rotation(i, j)
assert isinstance(rotation, KiAngle)
assert rotation.AsDegrees() == expected_rot.AsDegrees()


def test_odd_even_column_position_rotation():
placer = OddEvenRowsColumnsPosition(0, 0)
for (i, j, expected_rot) in ((0, 0, EDA_ANGLE(0, DEGREES_T)),
(0, 1, EDA_ANGLE(180, DEGREES_T)),
(1, 0, EDA_ANGLE(180, DEGREES_T)),
(1, 1, EDA_ANGLE(0, DEGREES_T)),
(2, 0, EDA_ANGLE(0, DEGREES_T)),
(2, 1, EDA_ANGLE(180, DEGREES_T))):
rotation = placer.rotation(i, j)
assert isinstance(rotation, KiAngle)
assert rotation.AsDegrees() == expected_rot.AsDegrees()


def test_prolongCut():
line = LineString([(0, 0), (1, 1)])
prolonged = prolongCut(line, 0.5)
Expand Down

0 comments on commit 49363ea

Please sign in to comment.