MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / st_dwithin

Function st_dwithin

nodedb-spatial/src/predicates/distance.rs:105–120  ·  view source on GitHub ↗

ST_DWithin(a, b, distance_meters) — are A and B within the given distance? Optimized: uses bbox expansion pre-filter to avoid expensive exact distance computation when geometries are clearly far apart.

(a: &Geometry, b: &Geometry, distance_meters: f64)

Source from the content-addressed store, hash-verified

103/// Optimized: uses bbox expansion pre-filter to avoid expensive exact
104/// distance computation when geometries are clearly far apart.
105pub fn st_dwithin(a: &Geometry, b: &Geometry, distance_meters: f64) -> bool {
106 // Fast path for points: just haversine.
107 if let (Geometry::Point { coordinates: ca }, Geometry::Point { coordinates: cb }) = (a, b) {
108 return haversine_distance(ca[0], ca[1], cb[0], cb[1]) <= distance_meters;
109 }
110
111 // Bbox pre-filter: expand A's bbox by distance, check if B's bbox intersects.
112 let a_bb = geometry_bbox(a).expand_meters(distance_meters);
113 let b_bb = geometry_bbox(b);
114 if !a_bb.intersects(&b_bb) {
115 return false;
116 }
117
118 // Exact check.
119 st_distance(a, b) <= distance_meters
120}
121
122// ── Distance helpers ──
123

Callers 4

spatial_prefilterFunction · 0.85
spatial_joinFunction · 0.85
eval_geo_functionFunction · 0.85
apply_predicateFunction · 0.85

Calls 5

haversine_distanceFunction · 0.85
geometry_bboxFunction · 0.85
st_distanceFunction · 0.85
expand_metersMethod · 0.80
intersectsMethod · 0.45

Tested by

no test coverage detected