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

Function buffer_point

nodedb-spatial/src/operations.rs:110–125  ·  view source on GitHub ↗

Buffer a point into an approximate circle polygon.

(lng: f64, lat: f64, meters: f64, segments: usize)

Source from the content-addressed store, hash-verified

108
109/// Buffer a point into an approximate circle polygon.
110fn buffer_point(lng: f64, lat: f64, meters: f64, segments: usize) -> Geometry {
111 let dlat = meters / 110_540.0;
112 let dlng = meters / (111_320.0 * lat.to_radians().cos().max(0.001));
113
114 let mut ring = Vec::with_capacity(segments + 1);
115 for i in 0..segments {
116 let angle = 2.0 * std::f64::consts::PI * (i as f64) / (segments as f64);
117 ring.push([lng + dlng * angle.cos(), lat + dlat * angle.sin()]);
118 }
119 // Close the ring.
120 ring.push(ring[0]);
121
122 Geometry::Polygon {
123 coordinates: vec![ring],
124 }
125}
126
127/// Buffer a linestring by creating a corridor (parallel offset on both sides + end caps).
128fn buffer_linestring(line: &[[f64; 2]], meters: f64, segments: usize) -> Geometry {

Callers 2

st_bufferFunction · 0.85
buffer_linestringFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected