Skip to content

FEAT: New version of point_in_polygon for higher performances #6283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/6283.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
New version of point_in_polygon for higher performances
25 changes: 17 additions & 8 deletions src/ansys/aedt/core/modeler/geometry_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@
def v_angle_sign_2D(va, vb, right_handed=True):
"""Evaluate the signed angle between two 2D geometry vectors.

Iit the 2D version of the ``GeometryOperators.v_angle_sign`` considering vn = [0,0,1].
It is the 2D version of the ``GeometryOperators.v_angle_sign`` considering vn = [0,0,1].
In case of opposite vectors, it returns an angle equal to 180deg (always positive).

Parameters
Expand Down Expand Up @@ -1430,21 +1430,30 @@
if len(point) != 2: # pragma: no cover
raise ValueError("Point must be a list in the form [x, y].")
pl = len(polygon[0])
if pl <= 3: # pragma: no cover
raise ValueError("Polygon must have at least 3 points.")
if len(polygon[1]) != pl: # pragma: no cover
raise ValueError("Polygon x and y lists must be the same length")
raise ValueError("Polygon x and y lists must be the same length.")

asum = 0
for i in range(pl):
vj = [polygon[0][i-1], polygon[1][i-1]]
vi = [polygon[0][i], polygon[1][i]]
if GeometryOperators.points_distance(point, vi) < tol:
vj = (polygon[0][i - 1], polygon[1][i - 1])
vi = (polygon[0][i], polygon[1][i])
d = math.sqrt((vi[0]-point[0]) ** 2 + (vi[1]-point[1]) ** 2)
if d < tol:

Check warning on line 1443 in src/ansys/aedt/core/modeler/geometry_operators.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/geometry_operators.py#L1440-L1443

Added lines #L1440 - L1443 were not covered by tests
return 0 # point is one of polyline vertices
vpj = GeometryOperators.v_points(point, vj)
vpi = GeometryOperators.v_points(point, vi)
a = GeometryOperators.v_angle_sign_2D(vpj, vpi)
vpj = (vj[0]-point[0], vj[1]-point[1])
vpi = (vi[0]-point[0], vi[1]-point[1])

Check warning on line 1446 in src/ansys/aedt/core/modeler/geometry_operators.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/geometry_operators.py#L1445-L1446

Added lines #L1445 - L1446 were not covered by tests

cross = vpj[0]*vpi[1] - vpj[1]*vpi[0]
dot = vpj[0]*vpi[0] + vpj[1]*vpi[1]
a = math.atan2(cross, dot)

Check warning on line 1450 in src/ansys/aedt/core/modeler/geometry_operators.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/geometry_operators.py#L1448-L1450

Added lines #L1448 - L1450 were not covered by tests

if abs(abs(a) - math.pi) < tol:
return 0
asum += a
r = asum % (2*math.pi)

if abs(asum) < tol:
return -1
elif r < tol or (2*math.pi - r) < tol:
Expand Down
Loading