Replace normal_triangle with normal_polygon for robust concave polygon handling #1498
+74
−36
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Polygon.normalwas calculating normals usingnormal_trianglewith the centroid and first two points, which fails for concave polygons when those points lie on concave ears.Changes
src/compas/geometry/polygon.pynormal_triangle([self.centroid] + self.points[:2])withnormal_polygon(self.points)in theplanepropertytests/compas/geometry/test_polygon.pytest_polygon_normal_concavevalidating L-shape and arrow-shape concave polygons with both winding orderstests/compas/geometry/test_triangulation_earclip.pytest_earclip_polygon_wrong_windingexpected faces to reflect correct normal calculation for the complex concave polygonExample
The improved normal calculation also affects earclip triangulation orientation since it depends on
polygon.normalto establish the transformation plane. The new triangulation is equally valid but differs in vertex ordering.Original prompt
Polygon.normalwithnormal_polygoninstead ofnormal_triangle? #1487✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.