Skip to content

Remove duplicate vertices in Prism object#1905

Closed
oskooi wants to merge 1 commit intoNanoComp:masterfrom
oskooi:prism_dupl_vertices
Closed

Remove duplicate vertices in Prism object#1905
oskooi wants to merge 1 commit intoNanoComp:masterfrom
oskooi:prism_dupl_vertices

Conversation

@oskooi
Copy link
Copy Markdown
Collaborator

@oskooi oskooi commented Jan 14, 2022

Closes #1520.

@ahoenselaar
Copy link
Copy Markdown
Contributor

Wouldn't one want to only consider consecutive vertices?

@stevengj
Copy link
Copy Markdown
Collaborator

Also, shouldn't this happen in libctl in the low-level constructor?

@oskooi
Copy link
Copy Markdown
Collaborator Author

oskooi commented Jan 15, 2022

Wouldn't one want to only consider consecutive vertices?

This is true in the case of a GDS file for which the shapes must be weakly simple polygons. This means that the polygon has segments which can intersect but not cross. This also means that representing holes requires connecting their boundary to the boundary of the enclosing shape which can give rise to duplicate vertices that are not consecutive.

In the general definition of a prism which involves convexity, any duplicate vertex would need to be removed whether it is consecutive or not.

Also, shouldn't this happen in libctl in the low-level constructor?

Sure, we can move this feature to libctl and then add a test in Meep.

@ianwilliamson
Copy link
Copy Markdown
Contributor

This is true in the case of a GDS file for which the shapes must be weakly simple polygons. This means that the polygon has segments which can intersect but not cross. This also means that representing holes requires connecting their boundary to the boundary of the enclosing shape which can give rise to duplicate vertices that are not consecutive.

In the general definition of a prism which involves convexity, any duplicate vertex would need to be removed whether it is consecutive or not.

Does the issue described in #1520 actually extend to the case of having any duplicated vertices? I only showed the segfault with the duplicated first / last vertex while having subpixel smoothing enabled. Though, I could also see how there would be issues with having consecutive vertices.

Support for GDS-style polygons in the prism strikes me as being particularly useful given #1501, but if you do want to move forward with this approach, I would suggest raising an error instead of silently removing vertices. This would be quite confusing for users.

@stevengj
Copy link
Copy Markdown
Collaborator

To me, a polygon with duplicate consecutive vertices seems like a well-defined limiting case, that seems like a polygon with one fewer vertex. (e.g. the limit of a quadrilateral as a side length goes to zero should be a triangle, not an error)

@stevengj
Copy link
Copy Markdown
Collaborator

e.g. matlab polyshape automatically deletes duplicate and even co-linear vertices. https://www.mathworks.com/matlabcentral/answers/606836-why-does-the-polyshape-function-deletes-the-vertices-in-the-input-when-there-are-no-duplicated-poi … and it seems pretty common in geometry packages to support deleting consecutive duplicate vertices, even if they are only approximately equal.

@oskooi oskooi deleted the prism_dupl_vertices branch February 2, 2022 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prism objects with duplicated vertices cause a segfault

4 participants