Skip to content

Commit 0f891b9

Browse files
fix point_in_polygon method when the asum was a multiple of 2*phi (#4495)
Co-authored-by: maxcapodi78 <Shark78> Co-authored-by: adimaria <[email protected]>
1 parent b45cf01 commit 0f891b9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

pyaedt/modeler/geometry_operators.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,8 @@ def point_in_polygon(point, polygon, tolerance=1e-8):
15581558
15591559
The method implements the radial algorithm (https://es.wikipedia.org/wiki/Algoritmo_radial)
15601560
1561+
This version supports also self-intersecting polygons.
1562+
15611563
point : List
15621564
List of ``[x, y]`` coordinates.
15631565
polygon : List
@@ -1591,9 +1593,10 @@ def point_in_polygon(point, polygon, tolerance=1e-8):
15911593
if abs(abs(a) - math.pi) < tol:
15921594
return 0
15931595
asum += a
1596+
r = asum % (2*math.pi)
15941597
if abs(asum) < tol:
15951598
return -1
1596-
elif abs(abs(asum) - 2*math.pi) < tol:
1599+
elif r < tol or (2*math.pi - r) < tol:
15971600
return 1
15981601
else: # pragma: no cover
15991602
raise Exception("Unexpected error!")

0 commit comments

Comments
 (0)