georust / geo

Geospatial primitives and algorithms for Rust
https://crates.io/crates/geo
Other
1.55k stars 199 forks source link

Determining a cut-off for brute-force distance calculations #225

Open urschrei opened 6 years ago

urschrei commented 6 years ago

Currently, our strategy for calculating LineString-LineString, Polygon-LineString, and Polygon-Polygon distance is as follows:

LineString-LineString:

LineString-Polygon

Polygon-Polygon:

The issue is that loading Lines into the trees (I suspect massively) dominates the running time up to a certain threshold, at which point it becomes reasonable again, because the algorithm as described above is quadratic without the use of the tree.

I don't have empirical data for this, but my strong suspicion is that use-cases are ~bimodally distributed:

  1. geometries derived from physical geography (lots and lots of vertices)
  2. everything else (a few hundred vertices at most)

For (2), we should just brute-force the search. As an added bonus, we could even try parallelising it using two threads (although again, spinning up a thread may be much slower than just two searches)

We should write some benchmarks, and see if we can determine the total number of vertices above which we use the tree.

michaelkirk commented 3 years ago

This seems a little nuanced, so removing the "good first issue".