locationtech / jts

The JTS Topology Suite is a Java library for creating and manipulating vector geometry.
Other
1.98k stars 443 forks source link

Fix RelateOp for a snapped line boundary point #839

Closed dr-jts closed 2 years ago

dr-jts commented 2 years ago

Recently two issues were reported in PostGIS (this and this) about inconsistent results between the intersects and PreparedGeometry.intersects predicates.

The cases involve two line segments which cross very close to a segment endpoint which is also a boundary point of a line. The lines intersect according to the robust orientation tests (visible in the TestBuilder Magnify Topology mode). The intersects result is incorrect, because the IM matrix is being computed incorrectly, as shown here:

A: LINESTRING (-57.2681216 49.4063466, -57.267725199999994 49.406617499999996, -57.26747895046037 49.406750916517765)
B: LINESTRING (-57.267475399999995 49.4067465, -57.2675701 49.406864299999995, -57.267989 49.407135399999994)

image

The problem is that roundoff causes the computed intersection point to be equal to the boundary point. The intersection detection logic in SegmentIntersector.addIntersections was not handling this case correctly. (The reason that PreparedGeometry.intersects works is that it uses different and simpler logic.)

Note that there is an unavoidable inconsistency between the robust orientation predicates and the computed intersection point (which is subject to roundoff). The fix takes the computed point as being correct (thus effectively introducing an implicit, very small tolerance). This causes the computed IM to report touches as true as well.

image

Also logged as GEOS-565.

Patch also removes some obsolete code to simplify logic.

Signed-off-by: Martin Davis mtnclimb@gmail.com