Signed area of a ring (Shoelace formula). Positive = CCW, Negative = CW.
(ring: &[[f64; 2]])
| 136 | |
| 137 | /// Signed area of a ring (Shoelace formula). Positive = CCW, Negative = CW. |
| 138 | fn 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. |
| 153 | fn check_ring_self_intersection(ring: &[[f64; 2]], label: &str, issues: &mut Vec<String>) { |
no test coverage detected