Skip to content

Better distance computation - #6

Merged
patrickbr merged 46 commits into
masterfrom
dist-experiments
Jul 24, 2026
Merged

Better distance computation#6
patrickbr merged 46 commits into
masterfrom
dist-experiments

Conversation

@patrickbr

@patrickbr patrickbr commented Jul 21, 2026

Copy link
Copy Markdown
Member
  • add XSortedCollection, which is a collection of arbitrary XSorted geometries.
  • use XSortedCollection for MULTI geometries to avoid naive n * m checks between predicates on multigeoms
  • add withinDist() methods in two flavors: withinDist(geoma, geomb, maxDist) (euclidean distance), and withinDist(geoma, geomb, maxDist, paddingFunc, maxEculideanDist, distFunc), where paddingFunc is used to compute a euclidean search padding based on current bounds. This function is present for each combination of geometry (xsorted and normal)
    • add dist() methods, basically aliases for withinDist() with maxDist set to inf, also comes in the two flavors described above
  • add meterDist() methods, based on the methods above, with automatic padding and using the haversine formula for compute the meter distance
  • for various internal distance methods, add a distSquared method which is often sufficient if we only compare distances and saves a sqrt() call
  • In the dist methods for unsorted geometries, use a threshhold to fall back to a XSortedGeometry comparison
  • add a ton of tests for these methods
  • split the huge GeoTest.cpp into several smaller compilation units and drop the -O3 optimization for the tests (use -O0) to speed up compilation
  • Change the withinDist() function which previously used an internal ring buffer to trace the OUT events for the padded side during the sweep with a variant proposed by @joka921 which does not use any additional data structure but index pointers into the original sweep event lists

Missing: hierarchical sorted geometries, will be a separate PR

patrickbr and others added 30 commits December 12, 2025 12:33
…uting the current maximum euclideanDistance from the maxDist, (b) dynamically update the maxDist parameter during execution if a lower distance is found, (c) provide default arguments if only a max dist is given (then euclidean distance is assumed and the distance func and euclideanMaxDistance func parameters are set to simple functions assuming euclidean distance)
…start, dynamically update the upper distance bound (= the sweep padding) during sweep, redesign the API and add convenience methods for calculating the euclidean distance directly, also fix some minor bugs which caused unnecessarily large padding in some rare cases
…the basis for MULTI-Geometries / Collection holding XSortedGeometries, with an additional bbox index for faster operations involving a multi-XSorted geometry on one side
…ds for mercator/haversine distortion, simplify code by storing bboxes and areas directly in the XSorted geometry classes instead of optionally passing them to the various functions using them
…pairs, one test involving distance between multipoly and multipoint currently still failing
This reverts commit a5a43a4.
patrickbr and others added 16 commits May 27, 2026 12:26
…l deferredOut queue (but with markers into the orignal list instead
…on raw geom withinDists() based on numb of expected comparisons, on the side avoid a copy in simplify() for lines
…b and boundedAdd to better handle adding and substracting padding values in Geo.tpp for small integer types like uint16, add tests for these types down to bool, split the GeoTest.cpp into more managable smaller files, also disable optimization for the test glue code to speed up test compile time
…y types (returns empty list for points and lines)
@patrickbr
patrickbr merged commit e151970 into master Jul 24, 2026
4 checks passed
@patrickbr
patrickbr deleted the dist-experiments branch July 24, 2026 09:47
@ullingerc ullingerc mentioned this pull request Jul 24, 2026
yarox-1 pushed a commit to yarox-1/util that referenced this pull request Jul 24, 2026
…d-freiburg#6's rewrite

PR ad-freiburg#5 (CRS/projection support: CRSType, getCRSType, *FromWKTProj with
CRS-aware overloads, projectToCRS/CRS84/WGS84/WebMerc, lngLat<->latLng
swap) predates ad-freiburg#6's large distance-computation rewrite, which touched
the same WKT-parsing machinery and split the monolithic GeoTest.cpp
into per-feature files. Master's (ad-freiburg#6) conventions were kept wherever
the two overlapped:

- CMakeLists.txt: kept ad-freiburg#6's standalone-build setup over ad-freiburg#5's temporary
  local scaffold.
- geo/Geo.{h,tpp}: kept ad-freiburg#6's F&& forwarding-reference convention for
  the std::string WKT-wrapper overloads; also fixed three latent
  naming bugs where ad-freiburg#6's own .tpp definitions had dropped the "Proj"
  suffix (multiLineFromWKT/multiPolygonFromWKT/collectionFromWKT
  instead of ...WKTProj), leaving ad-freiburg#5's correctly-named declarations
  undefined.
- Replaced ad-freiburg#5's `if constexpr`/`std::is_invocable_r_v`-based dispatch
  (used to detect whether a projFunc takes just a Point or also a
  CRSType) with a C++11-compatible SFINAE overload pair, since ad-freiburg#6's
  CMakeLists.txt targets C++11 for downstream compatibility.
- Fixed a pre-existing (and now newly-exposed) declaration/definition
  mismatch for the std::string overload of pointFromWKTProj, latent in
  ad-freiburg#6 itself, now surfaced as an ambiguous-call by aligning it to the
  same F&& convention used everywhere else.
- tests/GeoTest.cpp: restored ad-freiburg#6's minimal split-runner file; moved
  ad-freiburg#5's new coverage (IRI/CRS-type detection, CRS conversions, and
  CRS-aware WKT parsing for every geometry type) into a new
  tests/GeoTestCRS.cpp, following ad-freiburg#6's one-file-per-feature split.

Full standalone build and test suite verified passing.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant