turf-swift icon indicating copy to clipboard operation
turf-swift copied to clipboard

Turf::intersection does not observe edge cases

Open westnordost opened this issue 5 years ago • 1 comments

I think this function does not observe the following edge cases:

  • both lines are colinear (denominator == 0): the line segments could still intersect - the intersection would be another line segment
  • what about the 180th meridian? what about line segments crossing the north and south pole?
  • the current algorithm does not seem to count the start end end point as part of the line segment. This is a matter of definition, but usually at least the start point is counted as part of the line (i.e. the line segment is then closed-open)

westnordost avatar Oct 31 '20 22:10 westnordost

https://github.com/mapbox/turf-swift/blob/19d184102927cfc6dba49647850c6fd3e1f5f336/Sources/Turf/Turf.swift#L15-L16

turf-point-on-line has since been replaced by turf-nearest-point-on-line, which calls out to turf-line-intersect, which at a glance seems to handle two of these issues.

what about the 180th meridian? what about line segments crossing the north and south pole?

This is a good point; geometries that straddle the antimeridian probably aren’t handled well by other methods in this library either. GeoJSON technically represents such geometries as multi-geometries, but many clients including the Mapbox Maps SDK work around this limitation by allowing longitudes to extend beyond ±180°.

1ec5 avatar Nov 03 '20 16:11 1ec5