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

Function edge_outward_normal

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

Outward-pointing unit normal for an edge (a→b). For CCW rings (standard exterior), the outward direction is the right normal (dy, -dx). This is correct because CCW traversal has the interior on the left.

(a: [f64; 2], b: [f64; 2])

Source from the content-addressed store, hash-verified

271/// normal (dy, -dx). This is correct because CCW traversal has the
272/// interior on the left.
273fn edge_outward_normal(a: [f64; 2], b: [f64; 2]) -> [f64; 2] {
274 let dx = b[0] - a[0];
275 let dy = b[1] - a[1];
276 let len = (dx * dx + dy * dy).sqrt().max(1e-12);
277 // Right normal: (dy, -dx) normalized — outward for CCW rings.
278 [dy / len, -dx / len]
279}
280
281/// Direction angle (radians) from a to b.
282fn direction(a: [f64; 2], b: [f64; 2]) -> f64 {

Callers 2

buffer_polygonFunction · 0.85
offset_segmentFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected