-
Notifications
You must be signed in to change notification settings - Fork 110
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
CHANGE triangulation_earclip #1253
CHANGE triangulation_earclip #1253
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good, I didn't check the math though. But it is missing tests, and since you mention that the previous algo failed in some cases, I would like to see those failing cases added as unit tests + some non-edge cases.
Co-authored-by: Gonzalo Casas <[email protected]>
Co-authored-by: Gonzalo Casas <[email protected]>
Co-authored-by: Gonzalo Casas <[email protected]>
"""Initialize an Ear instance. | ||
|
||
Parameters | ||
---------- | ||
points : list | ||
List of points representing the polygon. | ||
indexes : list | ||
List of indices of the points representing the polygon. | ||
ind : int | ||
Index of the vertex of the Ear triangle. | ||
|
||
Attributes | ||
---------- | ||
index : int | ||
Index of the vertex of the Ear triangle. | ||
coords : list | ||
Coordinates of the vertex of the Ear triangle. | ||
next : int | ||
Index of the next vertex of the Ear triangle. | ||
prew : int | ||
Index of the previous vertex of the Ear triangle. | ||
neighbour_coords : list | ||
Coordinates of the next and previous vertices of the Ear triangle. | ||
|
||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add to class docstring
|
||
Returns | ||
------- | ||
bool : True, if the point is a vertex of the Ear triangle, False otherwise. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool
True, if ...
|
||
Returns | ||
------- | ||
bool: True if the Ear triangle is valid, False otherwise. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
|
||
Returns | ||
------- | ||
bool: True if the Ear triangle is convex, False otherwise. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
|
||
Returns | ||
------- | ||
list: List of vertex indices forming the Ear triangle. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
"""Initialize an Earcut instance with the input points. | ||
|
||
Parameters | ||
---------- | ||
points : list | ||
List of points representing the polygon. | ||
|
||
Attributes | ||
---------- | ||
vertices : list | ||
List of points representing the polygon. | ||
ears : list | ||
List of Ear objects representing the Ears of the polygon. | ||
neighbours : list | ||
List of indices of the neighbouring vertices. | ||
triangles : list | ||
List of triangles forming the triangulation of the polygon. | ||
length : int | ||
Number of vertices of the polygon. | ||
|
||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add to class docstring
Thank you for a review, the changes have been made, including pytest, and pushed once more. |
can you merge main back in please... |
|
CHANGELOG.md
Outdated
* Changed `compas.geometry.earclip_polygon` algorithm because the current one does not work in several cases. | ||
* Changed the docstrings in `compas.geometry.earclip_polygon` are corrected. The orientation to the XY Frame has been removed since it is handled by the `polygon.to_vertices_and_faces` method. Additionally, the test_polygon.py file has been modified with a new test for the ear_clip called `test_polygon_to_vertices_and_faces`. The `object` has been added to all `Ear` classes. | ||
* Changed the docstrings in `compas.geometry.earclip_polygon` is merged back, meaning the polygon is transformed to XY frame. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need to add tests and docstring stuff to the changelog, the changelog is only for users of the library that need to understand what has changed
self.add_ear(next_ear_new) | ||
continue | ||
|
||
return self.triangles | ||
|
||
|
||
def earclip_polygon(polygon): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unit test added does not explicitly test the earclip algorithm, and actually I find it hard to see the link from the code. I would add an additiona tests/compas/geometry/test_triangulation_earclip.py
that tests directly the relevant methods of this module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have just made a new push to a new file: tests/compas/geometry/test_triangulation_earclip.py
for testing.
I added one small detail to handle simple triangles.
…esting only the algorithm
CHANGELOG.md
Outdated
@@ -82,6 +82,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
* Moved `compas.numerical.matrices` to `compas.topology.matrices`. | |||
* Moved `compas.numerical.linalg` to `compas.geometry.linalg`. | |||
* Changed `watchdog` dependency to be only required for platforms other than `emscripten`. | |||
* Changed `compas.geometry.earclip_polygon` algorithm because the current one does handle several cases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny typo ;)
* Changed `compas.geometry.earclip_polygon` algorithm because the current one does handle several cases. | |
* Changed `compas.geometry.earclip_polygon` algorithm because the current one does not handle several cases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me! Besides the little typo, there's some linting required (the build is failing because of that). Once the build is green, I think this is good to go!
@petrasvestartas run |
to apply |
The change of
compas\src\compas\geometry\triangulation_earclip.py
code to a new one.The issue with the current algorithm is described in the following forum thread:
COMPAS FORUM
The function name stays the same:
What type of change is this?
Checklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.CHANGELOG.md
file in theUnreleased
section under the most fitting heading (e.g.Added
,Changed
,Removed
).invoke test
).invoke lint
).compas.datastructures.Mesh
.