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

Function min_dist_point_bbox

nodedb-spatial/src/rtree/search.rs:136–160  ·  view source on GitHub ↗

Minimum distance from point to bbox (in degrees, approximate).

(lng: f64, lat: f64, bbox: &BoundingBox)

Source from the content-addressed store, hash-verified

134
135/// Minimum distance from point to bbox (in degrees, approximate).
136fn min_dist_point_bbox(lng: f64, lat: f64, bbox: &BoundingBox) -> f64 {
137 let dlat = if lat < bbox.min_lat {
138 bbox.min_lat - lat
139 } else if lat > bbox.max_lat {
140 lat - bbox.max_lat
141 } else {
142 0.0
143 };
144
145 let dlng = if bbox.crosses_antimeridian() {
146 if lng >= bbox.min_lng || lng <= bbox.max_lng {
147 0.0
148 } else {
149 (bbox.min_lng - lng).min(lng - bbox.max_lng).max(0.0)
150 }
151 } else if lng < bbox.min_lng {
152 bbox.min_lng - lng
153 } else if lng > bbox.max_lng {
154 lng - bbox.max_lng
155 } else {
156 0.0
157 };
158
159 (dlat * dlat + dlng * dlng).sqrt()
160}
161
162fn insert_sorted(results: &mut Vec<NnResult>, item: NnResult, k: usize) {
163 let pos = results

Callers 1

nearestFunction · 0.85

Calls 1

crosses_antimeridianMethod · 0.80

Tested by

no test coverage detected