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

Function expand_bbox

nodedb/src/data/executor/handlers/spatial.rs:352–363  ·  view source on GitHub ↗

Expand a bounding box by a distance in meters.

(bbox: &nodedb_types::BoundingBox, meters: f64)

Source from the content-addressed store, hash-verified

350
351/// Expand a bounding box by a distance in meters.
352fn expand_bbox(bbox: &nodedb_types::BoundingBox, meters: f64) -> nodedb_types::BoundingBox {
353 let lat_delta = meters / 111_320.0;
354 let avg_lat = ((bbox.min_lat + bbox.max_lat) / 2.0).to_radians();
355 let lng_delta = meters / (111_320.0 * avg_lat.cos().max(0.001));
356
357 nodedb_types::BoundingBox::new(
358 bbox.min_lng - lng_delta,
359 bbox.min_lat - lat_delta,
360 bbox.max_lng + lng_delta,
361 bbox.max_lat + lat_delta,
362 )
363}
364
365#[cfg(test)]
366mod tests {

Callers 1

execute_spatial_scanMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected