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

Test polygons are valid after constructing them #156

Merged
merged 1 commit into from
Sep 10, 2024
Merged

Conversation

mx-moth
Copy link
Contributor

@mx-moth mx-moth commented Sep 5, 2024

This came about after #154 which was generating invalid polygons which were not picked up. This PR introduces a post-processing step on the Convention.polygons property which checks the polygons to ensure they are valid polygons. Invalid polygons will spoil other operations so it is good to be certain.

This change effectively requires any implementing conventions to rename their polygon property to a _make_polygons() method. The base Convention class now includes a polygon property which calls this new method and post-processes the results. A new 'hotfix' concept is being trialled here which can adapt a Convention with a polygon property and without a _make_polygons() method to the new interface. This is novel but honestly there is only one plugin for emsarray so possibly this is unnecessary extra complications. Still, it is a problem I had been mulling over for some time and I am happy I found a workable solution if only for my own education!

Checking for polygon validity will slow things down, but not by a huge amount. The additional safety is worth it. If this safety check becomes burdensome in the future we could consider adding a 'strict' / 'non-strict' mode which enables / disables these sorts checks. In 'non-strict' mode loading datasets would be faster but any errors in the geometry would not be picked up, potentially giving invalid results or otherwise causing errors.

@mx-moth mx-moth self-assigned this Sep 5, 2024
src/emsarray/conventions/_fixes.py Outdated Show resolved Hide resolved
src/emsarray/conventions/_fixes.py Outdated Show resolved Hide resolved
src/emsarray/conventions/_registry.py Outdated Show resolved Hide resolved
src/emsarray/conventions/_registry.py Outdated Show resolved Hide resolved
src/emsarray/conventions/_base.py Show resolved Hide resolved
@mx-moth mx-moth force-pushed the test-valid-polygons branch from 8a2781d to d186913 Compare September 10, 2024 01:10
`Convention.polygons` is now defined on the base `Convention` class. It
calls a new abstract method `Convention._make_polygons()`. This allows
us to do some post processing of the polygons as part of generating
them.

Invalid polygons generate a warning and are dropped as part of
generation. Non-simple polygons generate a warning but are kept.

This means the triangulation code doesn't need to perform this step. It
doesn't save any time overall, as the polygons still need to be tested
either way.
@mx-moth mx-moth force-pushed the test-valid-polygons branch from d186913 to 0bcc612 Compare September 10, 2024 01:18
@mx-moth mx-moth merged commit 19e1574 into main Sep 10, 2024
15 checks passed
@mx-moth mx-moth deleted the test-valid-polygons branch September 10, 2024 01:26
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.

1 participant