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

Ensure GeometryUtil.toJts() returns valid geometry #4668

Merged

Conversation

kwvanderlinde
Copy link
Collaborator

@kwvanderlinde kwvanderlinde commented Jan 27, 2024

Identify the Bug or Feature request

Improves on #4506

Description of the Change

With the recent changes to how we build AreaTree, certain edge case geometries started being treated differently and would stop vision and pathfinding from working properly. These edge cases include ultra-precise artifacts that the user cannot see but are enough to confuse JTS about what counts as the interior of the VBL.

This change attempts to avoid these problems by adding unit tests for Geometry.toJtsPolygons() and Geometry.toJts() that make sure we get topologically correct results. The precision was adjusted to make sure all these cases result in geometry that agrees with what the user sees, making sure vision and pathfinding to behave as the user expects. Geometry.toJts() to now based on Geometry.toJtsPolygons() so that we can guarantee a valid MultiPolygon is returned, saving the callers from having to check it themselves.

Also included is a change to the DTO mapping for Area so that we keep full double precision instead of truncating to single precision. This ensures that clients each receive the same topology (and other Area) as the original.

Possible Drawbacks

I guarantee someone else's weird VBL will break now. But at least we can add any new cases to the test suite.

Documentation Notes

N/A

Release Notes

N/A


This change is Reviewable

These cover some tricky cases that have been tested manually so far. Test inputs are specified in full precision, but
will be truncated according to the current precision model. The tests make sure that a specific topology is returned for
each case.
Partly this is just a matter of picking a more reasonable precision. But we also now make `GeometryUtil.toJtsPolygons()`
the authoritative source for geometry, with `GeometryUtil.toJts()` merely packaging that as a `MultiPolygon`. A
defensive change to flatten any curved areas also guards against future usage that might run afoul of the current
assumption that that input is only polygonal areas.
This avoids precision loss in VBL (and other shapes) when sent to other clients. This increase precision applies to
`Mapper.map(Area)`, as well as `Mapper.map(AreaDto)`. The latter has also be simplified by directly building a `Path2D`
instead of going through a customer `PathIterator` intermediary.
@kwvanderlinde kwvanderlinde force-pushed the bugfix/4506-precision-sensitivity branch from 1b57040 to ae2d229 Compare January 30, 2024 15:45
@cwisniew cwisniew added the performance A performance or quality of life improvement label Feb 1, 2024
@cwisniew cwisniew added this pull request to the merge queue Feb 1, 2024
Merged via the queue into RPTools:develop with commit 0101961 Feb 1, 2024
4 checks passed
@kwvanderlinde kwvanderlinde deleted the bugfix/4506-precision-sensitivity branch May 28, 2024 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance A performance or quality of life improvement
Projects
Development

Successfully merging this pull request may close these issues.

2 participants