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

Function signed_area

nodedb-spatial/src/validate.rs:138–150  ·  view source on GitHub ↗

Signed area of a ring (Shoelace formula). Positive = CCW, Negative = CW.

(ring: &[[f64; 2]])

Source from the content-addressed store, hash-verified

136
137/// Signed area of a ring (Shoelace formula). Positive = CCW, Negative = CW.
138fn signed_area(ring: &[[f64; 2]]) -> f64 {
139 let n = ring.len();
140 if n < 3 {
141 return 0.0;
142 }
143 let mut sum = 0.0;
144 for i in 0..n {
145 let j = (i + 1) % n;
146 sum += ring[i][0] * ring[j][1];
147 sum -= ring[j][0] * ring[i][1];
148 }
149 sum / 2.0
150}
151
152/// Check if any non-adjacent edges of a ring intersect.
153fn check_ring_self_intersection(ring: &[[f64; 2]], label: &str, issues: &mut Vec<String>) {

Callers 1

validate_recursiveFunction · 0.85

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected