Skip to content

Commit 49363ea

Browse files
errnoyaqwsx
authored andcommitted
Fixed OddEvenRowsColumnsPosition. Added tests for placers .rotation().
1 parent 28689df commit 49363ea

File tree

2 files changed

+64
-6
lines changed

2 files changed

+64
-6
lines changed

kikit/panelize.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ def position(self, i: int, j: int, boardSize: Optional[BOX2I]) -> VECTOR2I:
5656
"""
5757
raise NotImplementedError("GridPlacerBase.position has to be overridden")
5858

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

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

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

9997
class OddEvenRowsPosition(BasicGridPosition):
10098
"""
@@ -120,7 +118,7 @@ class OddEvenRowsColumnsPosition(BasicGridPosition):
120118
"""
121119
def rotation(self, i: int, j: int) -> KiAngle:
122120
if (i % 2) == (j % 2):
123-
return 0
121+
return EDA_ANGLE(0, pcbnew.DEGREES_T)
124122
return EDA_ANGLE(180, pcbnew.DEGREES_T)
125123

126124

test/units/test_panelize.py

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,69 @@
11
import pytest
2-
from kikit.panelize import prolongCut
2+
from pcbnewTransition.pcbnew import EDA_ANGLE, DEGREES_T
3+
from kikit.common import KiAngle
4+
from kikit.panelize import (
5+
GridPlacerBase, BasicGridPosition, OddEvenRowsPosition,
6+
OddEvenColumnPosition, OddEvenRowsColumnsPosition, prolongCut
7+
)
38
from shapely.geometry import LineString
49
from math import sqrt
510

611

12+
def test_grid_place_base_rotation():
13+
placer = GridPlacerBase()
14+
for (i, j) in ((0, 0), (0, 1), (1, 0), (1, 1), (2, 0), (2, 1)):
15+
rotation = placer.rotation(i, j)
16+
assert isinstance(rotation, KiAngle)
17+
assert rotation.AsDegrees() == EDA_ANGLE(0, DEGREES_T).AsDegrees()
18+
19+
20+
def test_basic_grid_position_rotation():
21+
placer = GridPlacerBase()
22+
for (i, j) in ((0, 0), (0, 1), (1, 0), (1, 1), (2, 0), (2, 1)):
23+
rotation = placer.rotation(i, j)
24+
assert isinstance(rotation, KiAngle)
25+
assert rotation.AsDegrees() == EDA_ANGLE(0, DEGREES_T).AsDegrees()
26+
27+
28+
def test_odd_even_rows_position_rotation():
29+
placer = OddEvenRowsPosition(0, 0)
30+
for (i, j, expected_rot) in ((0, 0, EDA_ANGLE(0, DEGREES_T)),
31+
(0, 1, EDA_ANGLE(0, DEGREES_T)),
32+
(1, 0, EDA_ANGLE(180, DEGREES_T)),
33+
(1, 1, EDA_ANGLE(180, DEGREES_T)),
34+
(2, 0, EDA_ANGLE(0, DEGREES_T)),
35+
(2, 1, EDA_ANGLE(0, DEGREES_T))):
36+
rotation = placer.rotation(i, j)
37+
assert isinstance(rotation, KiAngle)
38+
assert rotation.AsDegrees() == expected_rot.AsDegrees()
39+
40+
41+
def test_odd_even_column_position_rotation():
42+
placer = OddEvenColumnPosition(0, 0)
43+
for (i, j, expected_rot) in ((0, 0, EDA_ANGLE(0, DEGREES_T)),
44+
(0, 1, EDA_ANGLE(180, DEGREES_T)),
45+
(1, 0, EDA_ANGLE(0, DEGREES_T)),
46+
(1, 1, EDA_ANGLE(180, DEGREES_T)),
47+
(2, 0, EDA_ANGLE(0, DEGREES_T)),
48+
(2, 1, EDA_ANGLE(180, DEGREES_T))):
49+
rotation = placer.rotation(i, j)
50+
assert isinstance(rotation, KiAngle)
51+
assert rotation.AsDegrees() == expected_rot.AsDegrees()
52+
53+
54+
def test_odd_even_column_position_rotation():
55+
placer = OddEvenRowsColumnsPosition(0, 0)
56+
for (i, j, expected_rot) in ((0, 0, EDA_ANGLE(0, DEGREES_T)),
57+
(0, 1, EDA_ANGLE(180, DEGREES_T)),
58+
(1, 0, EDA_ANGLE(180, DEGREES_T)),
59+
(1, 1, EDA_ANGLE(0, DEGREES_T)),
60+
(2, 0, EDA_ANGLE(0, DEGREES_T)),
61+
(2, 1, EDA_ANGLE(180, DEGREES_T))):
62+
rotation = placer.rotation(i, j)
63+
assert isinstance(rotation, KiAngle)
64+
assert rotation.AsDegrees() == expected_rot.AsDegrees()
65+
66+
767
def test_prolongCut():
868
line = LineString([(0, 0), (1, 1)])
969
prolonged = prolongCut(line, 0.5)

0 commit comments

Comments
 (0)