Skip to content
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

Do not discard minimum-length paths in FlexPath::remove_overlapping_points() #278

Merged
merged 2 commits into from
Nov 23, 2024

Conversation

jatoben
Copy link
Collaborator

@jatoben jatoben commented Nov 23, 2024

Currently, FlexPath::remove_overlapping_points() removes points from a path if the length is less than or equal to the path's tolerance. But the equality test discards a minimum-length path, which is exactly one database unit in length.

I believe this is what's occurred in #268 and #277, both of which contain paths that have a length of 0.001 microns. That's the value for path tolerance when the library has the default unit and precision values of 1e-6 and 1e-9, respectively.

This PR updates remove_overlapping_points() to discard points only if the computed length is strictly less than the tolerance, and adds a couple of tests.

@jatoben
Copy link
Collaborator Author

jatoben commented Nov 23, 2024

Separately, I have another local patch which adds an EmptyPath error code value, and returns it from FlexPath's ::to_gds(), ::to_oas(), and ::to_polygons() methods when an empty path is detected (the ::to_polygons() change is needed to catch the non-simple path case). The Python bindings raise a warning if this error code is returned, allowing callers to detect a path of less-than-minimum length when writing out a library.

I'm not quite sure about this change though, since FlexPath seems to intentionally return no error when the path has too few points.

gdstk/src/flexpath.cpp

Lines 916 to 921 in 18167ef

ErrorCode FlexPath::to_oas(OasisStream& out, OasisState& state) {
ErrorCode error_code = ErrorCode::NoError;
remove_overlapping_points();
if (spine.point_array.count < 2) return error_code;

gdstk/src/flexpath.cpp

Lines 240 to 242 in 18167ef

ErrorCode FlexPath::to_polygons(bool filter, Tag tag, Array<Polygon*>& result) {
remove_overlapping_points();
if (spine.point_array.count < 2) return ErrorCode::NoError;

@heitzmann, let me know what you think about the error handling here -- I'm happy to send in the change as a follow-up PR if you'd like.

@heitzmann heitzmann merged commit 1b36890 into heitzmann:main Nov 23, 2024
6 checks passed
@heitzmann
Copy link
Owner

@jatoben Thanks for looking into the issue!

Yes, your changes to add EmptyPath error make sense to me. Feel free to open a PR for them!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants