Skip to content

New EntityList functions to construct and determine the properties of EntityLists #528

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

aidanc-ansys
Copy link
Collaborator

@aidanc-ansys aidanc-ansys commented Jun 11, 2025

Implements and fixes functions to check the geometric properties of EntityLists, as well as an EntityList constructor to generate an EntityList when given points.

…ns, as well as a Region constructor to generate a Region when given points
@aidanc-ansys aidanc-ansys added bug Something isn't working enhancement New features or code improvements labels Jun 11, 2025
Copy link

codecov bot commented Jun 11, 2025

Codecov Report

Attention: Patch coverage is 98.57143% with 1 line in your changes missing coverage. Please review.

Project coverage is 89.00%. Comparing base (e2ee617) to head (b2d8314).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #528      +/-   ##
==========================================
+ Coverage   88.62%   89.00%   +0.37%     
==========================================
  Files          21       21              
  Lines        2479     2546      +67     
==========================================
+ Hits         2197     2266      +69     
+ Misses        282      280       -2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@james-packer
Copy link
Contributor

@aidanc-ansys, not directly related to this PR, but it's worth being aware of the (slightly confusingly named) return_entity_list method of geometry_fitting (https://motorcad.docs.pyansys.com/version/dev/methods/_autosummary_geometry_fitting/ansys.motorcad.core.geometry_fitting.return_entity_list.html), which performs a related function. The geometry_fitting one takes a list of points, and returns a combination of arcs and lines that fits these points within a certain tolerance.

Copy link
Collaborator

@matthewAnsys matthewAnsys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good. A few comments to address

@@ -164,6 +164,65 @@ def from_coordinate_list(cls):
"""
pass

@classmethod
def from_points_linear(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename to include polygon? I Quite like Region.polygon()

What was your thinking for this name?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also feel most of this should belong to the EntityList class, This is where the function name Polygon would work nicely

xcenter = sum(list(point.x for point in points)) / len(points)
ycenter = sum(list(point.y for point in points)) / len(points)

def to_relative_coords(point):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make to_relative_coords and to_real_coords part of the Coordinate class, I expect these functions will be useful outside of here.

for i in range(0, len(self._entities))
)
else:
return False
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make sure this line is tested. Should be a super easy test to validate


is_closed = get_entities_have_common_coordinate(entity_first, entity_last)
def is_nonintersecting(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer is_self_intersecting() or just self_intersecting(). Also make this a property e.g.
image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the implementation of this should be in EntityList

"""
side_pairs = []
# Create a set of all non-neighbor pairs of lines/arcs in the region
for entity in self.entities:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice implementation, a line sweep algorithm would be more efficient but more complicated to implement

return is_closed
else:
return False
def is_anticlockwise(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting implementation, would you be able to provide info on the implementation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intuition is that if you're on the outermost edge of a closed shape, the drawing direction at that edge will also be the direction of the overall polygon. This implementation finds an outermost edge by looking for the lowest point, then determines the direction there using the ingoing and outgoing entities

@aidanc-ansys aidanc-ansys changed the title New Region functions to construct and determine the properties of Regions New EntityList functions to construct and determine the properties of EntityLists Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New features or code improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants