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

Turf::intersection does not observe edge cases #118

Open
westnordost opened this issue Oct 31, 2020 · 1 comment
Open

Turf::intersection does not observe edge cases #118

westnordost opened this issue Oct 31, 2020 · 1 comment
Labels

Comments

@westnordost
Copy link

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)
@1ec5
Copy link
Contributor

1ec5 commented Nov 3, 2020

public func intersection(_ line1: LineSegment, _ line2: LineSegment) -> CLLocationCoordinate2D? {
// Ported from https://github.com/Turfjs/turf/blob/142e137ce0c758e2825a260ab32b24db0aa19439/packages/turf-point-on-line/index.js, in turn adapted from http://jsfiddle.net/justin_c_rounds/Gd2S2/light/

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°.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants