Skip to content

Commit e31b532

Browse files
committed
fix polygon and earclip tests
1 parent 4284bf2 commit e31b532

File tree

2 files changed

+48
-28
lines changed

2 files changed

+48
-28
lines changed

tests/compas/geometry/test_polygon.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,26 @@ def test_polygon__setitem__():
8787
assert polygon[4] == point
8888
assert isinstance(polygon[4], Point)
8989
assert polygon.lines[-2].end == point
90+
91+
92+
def test_polygon_normal_direction():
93+
points = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]]
94+
polygon = Polygon(points)
95+
assert polygon.normal.dot([0, 0, 1]) > 0
96+
97+
points = [[0, 0, 0], [0, 1, 0], [1, 1, 0], [1, 0, 0]]
98+
polygon = Polygon(points)
99+
assert polygon.normal.dot([0, 0, 1]) < 0
100+
101+
102+
@pytest.mark.parametrize(
103+
"points",
104+
[
105+
[[0, 0, 0], [0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]],
106+
[[0, 0, 0], [1, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]],
107+
[[0, 0, 0], [1, 0, 0], [1, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]],
108+
],
109+
)
110+
def test_polygon_duplicate_removal(points):
111+
polygon = Polygon(points)
112+
assert len(polygon.points) == 4

tests/compas/geometry/test_triangulation_earclip.py

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import pytest
21
from compas.geometry import Polygon
32
from compas.geometry.triangulation_earclip import earclip_polygon
43

@@ -62,38 +61,37 @@ def test_earclip_polygon_wrong_winding():
6261
]
6362

6463
polygon = Polygon(points)
65-
polygon.points.reverse()
6664

6765
faces = earclip_polygon(polygon)
6866

6967
assert faces == [
68+
[0, 28, 27],
7069
[26, 25, 24],
7170
[23, 22, 21],
7271
[21, 20, 19],
73-
[16, 15, 14],
74-
[14, 13, 12],
75-
[11, 10, 9],
76-
[9, 8, 7],
77-
[7, 6, 5],
78-
[5, 4, 3],
79-
[1, 0, 28],
72+
[19, 18, 17],
73+
[17, 16, 15],
74+
[15, 14, 13],
75+
[10, 9, 8],
76+
[8, 7, 6],
77+
[4, 3, 2],
8078
[27, 26, 24],
81-
[21, 19, 18],
82-
[14, 12, 11],
83-
[5, 3, 2],
84-
[28, 27, 24],
85-
[16, 14, 11],
86-
[7, 5, 2],
87-
[28, 24, 23],
88-
[16, 11, 9],
89-
[7, 2, 1],
90-
[28, 23, 21],
91-
[17, 16, 9],
92-
[9, 7, 1],
93-
[28, 21, 18],
94-
[17, 9, 1],
95-
[28, 18, 17],
96-
[17, 1, 28],
79+
[24, 23, 21],
80+
[17, 15, 13],
81+
[11, 10, 8],
82+
[4, 2, 1],
83+
[27, 24, 21],
84+
[19, 17, 13],
85+
[5, 4, 1],
86+
[27, 21, 19],
87+
[19, 13, 12],
88+
[6, 5, 1],
89+
[27, 19, 12],
90+
[6, 1, 0],
91+
[27, 12, 11],
92+
[8, 6, 0],
93+
[0, 27, 11],
94+
[11, 8, 0],
9795
]
9896

9997

@@ -108,8 +106,7 @@ def test_earclip_polygon_coincident_points():
108106
]
109107
)
110108

111-
with pytest.raises(IndexError):
112-
earclip_polygon(self_intersecting_polygon)
109+
earclip_polygon(self_intersecting_polygon)
113110

114111

115112
def test_earclip_polygon_when_reversed():
@@ -129,4 +126,4 @@ def test_earclip_polygon_when_reversed():
129126

130127
polygon.points.reverse()
131128
triangles = earclip_polygon(polygon)
132-
assert triangles == [[0, 5, 4], [3, 2, 1], [0, 4, 3], [3, 1, 0]]
129+
assert triangles == [[5, 0, 1], [1, 2, 3], [3, 4, 5], [5, 1, 3]]

0 commit comments

Comments
 (0)