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

Function offset_segment

nodedb-spatial/src/operations.rs:251–266  ·  view source on GitHub ↗
(a: [f64; 2], b: [f64; 2], meters: f64)

Source from the content-addressed store, hash-verified

249type OffsetPair = (([f64; 2], [f64; 2]), ([f64; 2], [f64; 2]));
250
251fn offset_segment(a: [f64; 2], b: [f64; 2], meters: f64) -> OffsetPair {
252 let normal = edge_outward_normal(a, b);
253 let dlat = meters / 110_540.0;
254 let mid_lat = ((a[1] + b[1]) / 2.0).to_radians().cos().max(0.001);
255 let dlng = meters / (111_320.0 * mid_lat);
256
257 let left = (
258 [a[0] + normal[0] * dlng, a[1] + normal[1] * dlat],
259 [b[0] + normal[0] * dlng, b[1] + normal[1] * dlat],
260 );
261 let right = (
262 [a[0] - normal[0] * dlng, a[1] - normal[1] * dlat],
263 [b[0] - normal[0] * dlng, b[1] - normal[1] * dlat],
264 );
265 (left, right)
266}
267
268/// Outward-pointing unit normal for an edge (a→b).
269///

Callers 1

buffer_linestringFunction · 0.85

Calls 1

edge_outward_normalFunction · 0.85

Tested by

no test coverage detected