Skip to content

Commit 10a2a6e

Browse files
chriswmackeyChris Mackey
authored and
Chris Mackey
committed
fix(polygon): Catch edge case where self-intersecting reads as convex
1 parent 5d6453d commit 10a2a6e

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

ladybug_geometry/geometry2d/polygon.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -404,17 +404,16 @@ def is_self_intersecting(self):
404404
"""
405405
if self._is_self_intersecting is None:
406406
self._is_self_intersecting = False
407-
if self.is_convex is False:
408-
_segs = self.segments
409-
for i, _s in enumerate(_segs[1: len(_segs) - 1]):
410-
_skip = (i, i + 1, i + 2)
411-
_other_segs = [x for j, x in enumerate(_segs) if j not in _skip]
412-
for _oth_s in _other_segs:
413-
if _s.intersect_line_ray(_oth_s) is not None: # intersection!
414-
self._is_self_intersecting = True
415-
break
416-
if self._is_self_intersecting is True:
407+
_segs = self.segments
408+
for i, _s in enumerate(_segs[1: len(_segs) - 1]):
409+
_skip = (i, i + 1, i + 2)
410+
_other_segs = [x for j, x in enumerate(_segs) if j not in _skip]
411+
for _oth_s in _other_segs:
412+
if _s.intersect_line_ray(_oth_s) is not None: # intersection!
413+
self._is_self_intersecting = True
417414
break
415+
if self._is_self_intersecting is True:
416+
break
418417
return self._is_self_intersecting
419418

420419
@property

tests/polygon2d_test.py

+17
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,23 @@ def test_is_self_intersecting():
259259
assert polygon_2.is_self_intersecting
260260

261261

262+
def test_is_self_intersecting_complex_clockwise():
263+
"""Test the is_self_intersecting property on a more complex shape."""
264+
pts_3 = (
265+
(355.665006, -49.844883),
266+
(298.354434, 4.142452),
267+
(280.207456, 59.649202),
268+
(336.988767, 88.694148),
269+
(348.680933, 44.475185),
270+
(342.255592, 52.129292),
271+
(373.115776, 106.898085),
272+
(421.261481, 55.706056),
273+
(355.665006, -49.844883)
274+
)
275+
polygon = Polygon2D.from_array(pts_3)
276+
assert polygon.is_self_intersecting
277+
278+
262279
def test_is_valid():
263280
"""Test the is_valid property."""
264281
pts_1 = (Point2D(0, 0), Point2D(2, 0), Point2D(2, 2))

0 commit comments

Comments
 (0)