Skip to content

Commit d4ac78b

Browse files
committed
fix(geometry): Fix subtle bug in remove_colinear_vertices
1 parent d892cb4 commit d4ac78b

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

ladybug_geometry/geometry2d/polygon.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ def remove_colinear_vertices(self, tolerance):
624624
for i, _v in enumerate(self.vertices):
625625
_v2, _v1 = self[i - 2 - skip], self[i - 1]
626626
_a = _v2.determinant(_v1) + _v1.determinant(_v) + _v.determinant(_v2)
627-
b_dist = _v.distance_to_point(_v2)
627+
b_dist = max(_v.distance_to_point(_v2), _v.distance_to_point(_v1))
628628
b_dist = tolerance if b_dist < tolerance else b_dist
629629
tri_tol = (b_dist * tolerance) / 2 # area of triangle with tolerance height
630630
if abs(_a) >= tri_tol: # triangle area > tolerance; not colinear
@@ -641,7 +641,7 @@ def remove_colinear_vertices(self, tolerance):
641641
'There must be at least 3 vertices for a Polygon2D.'
642642
_v2, _v1, _v = self[-2 - skip], self[-1], self[first_skip]
643643
_a = _v2.determinant(_v1) + _v1.determinant(_v) + _v.determinant(_v2)
644-
b_dist = _v.distance_to_point(_v2)
644+
b_dist = max(_v.distance_to_point(_v2), _v.distance_to_point(_v1))
645645
b_dist = tolerance if b_dist < tolerance else b_dist
646646
tri_tol = (b_dist * tolerance) / 2 # area of triangle with tolerance height
647647
if abs(_a) >= tri_tol: # triangle area > area tolerance; not colinear

ladybug_geometry/geometry2d/polyline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def remove_colinear_vertices(self, tolerance):
155155
for i, _v in enumerate(self.vertices[1:-1]):
156156
_v2, _v1 = self[i - skip], self[i + 2]
157157
_a = _v2.determinant(_v) + _v.determinant(_v1) + _v1.determinant(_v2)
158-
b_dist = _v1.distance_to_point(_v2)
158+
b_dist = max(_v2.distance_to_point(_v1), _v2.distance_to_point(_v))
159159
b_dist = tolerance if b_dist < tolerance else b_dist
160160
tri_tol = (b_dist * tolerance) / 2 # area of triangle with tolerance height
161161
if abs(_a) >= tri_tol: # triangle area > tolerance; not colinear

ladybug_geometry/geometry3d/face.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3037,7 +3037,7 @@ def _remove_colinear(self, pts_3d, pts_2d, tolerance):
30373037
for i, _v in enumerate(pts_2d):
30383038
_v2, _v1 = pts_2d[i - 2 - skip], pts_2d[i - 1]
30393039
_a = _v2.determinant(_v1) + _v1.determinant(_v) + _v.determinant(_v2)
3040-
b_dist = _v.distance_to_point(_v2)
3040+
b_dist = max(_v.distance_to_point(_v2), _v.distance_to_point(_v1))
30413041
b_dist = tolerance if b_dist < tolerance else b_dist
30423042
tri_tol = (b_dist * tolerance) / 2 # area of triangle with tolerance height
30433043
if abs(_a) >= tri_tol: # triangle area > area tolerance; not colinear
@@ -3054,7 +3054,7 @@ def _remove_colinear(self, pts_3d, pts_2d, tolerance):
30543054
'There must be at least 3 vertices for a Face3D.'
30553055
_v2, _v1, _v = pts_2d[-2 - skip], pts_2d[-1], pts_2d[first_skip]
30563056
_a = _v2.determinant(_v1) + _v1.determinant(_v) + _v.determinant(_v2)
3057-
b_dist = _v.distance_to_point(_v2)
3057+
b_dist = max(_v.distance_to_point(_v2), _v.distance_to_point(_v1))
30583058
b_dist = tolerance if b_dist < tolerance else b_dist
30593059
tri_tol = (b_dist * tolerance) / 2 # area of triangle with tolerance height
30603060
if abs(_a) >= tri_tol: # triangle area > area tolerance; not colinear

ladybug_geometry/geometry3d/polyline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def remove_colinear_vertices(self, tolerance):
143143
for i, _v in enumerate(self.vertices[1:-1]):
144144
_v2, _v1 = self[i - skip], self[i + 2]
145145
_a = (_v2 - _v).cross(_v1 - _v).magnitude
146-
b_dist = _v1.distance_to_point(_v2)
146+
b_dist = max(_v2.distance_to_point(_v1), _v2.distance_to_point(_v))
147147
b_dist = tolerance if b_dist < tolerance else b_dist
148148
tri_tol = (b_dist * tolerance) / 2 # area of triangle with tolerance height
149149
if abs(_a) >= tri_tol: # triangle area > tolerance; not colinear

0 commit comments

Comments
 (0)