peterstace / simplefeatures

Simple Features is a pure Go Implementation of the OpenGIS Simple Feature Access Specification
MIT License
130 stars 19 forks source link

Use symmetric line/line intersection #574

Closed peterstace closed 10 months ago

peterstace commented 10 months ago

While debugging https://github.com/peterstace/simplefeatures/issues/569, I stumbled across an unrelated bug.

The line vs. line intersection method is (unexpectedly not symmetric, i.e. doesn't produce the same output when its inputs are reversed. Because the line vs. line intersection calculation is performed once in each direction for each unique pair of lines that could intersect, re-nodding anomalies can occur if the two results are sufficiently different.

There are two possible solutions:

  1. During the line vs. line intersection calculation, first reorder the inputs in a deterministic way.
  2. Use a calculation that is completely symmetric (which may be difficult since there are a lot of float64 operations involved, which aren't inherently symmetric).

This issue is potentially the root cause of others, e.g.: