Open s6ch13 opened 8 months ago
This is definitely a numerical robustness issue.
This code is using the old overlay implementation, which is more subject to robustness issues. It's better to change to using OverlayNG. You can do this via setting the system property jts.overlayng
, or calling OverlayNGRobust
directly.
Calculating difference and intersection between two polygons is resulting in a polygon having incorrect shape. Could have something to do with PrecisionModel. This is seen with v1.19 and also the latest 1.20 snapshot.
Result : input POLYGON ((3.5 2, 3 3.5, 5 2.5, 3.5 2)) POLYGON ((3 2.5, 5 2.5, 5 3.5, 3 3.5, 3 2.5)) Geometry intersection POLYGON ((3.3333333333333335 2.5, 3 3.5, 5 2.5, 3.3333333333333335 2.5)) polygon difference 1 POLYGON ((3.5 2, 3 3.5, 3.3333333333333335 2.5, 5 2.5, 3.5 2))
Expected result : polygon difference 1 should be POLYGON((3.3333333333333335 2.5, 5 2.5, 3.5 2, 3.3333 2.5))
This may have something to do with precision model. This works correctly If i set the geometry factory to
GeometryFactory gf = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING_SINGLE));
But there are other similar cases which work with default precision model fail with PrecisionModel.FLOATING_SINGLE.
This issue may be related to https://github.com/locationtech/jts/issues/990