We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fcab497 commit afaeecdCopy full SHA for afaeecd
src/area.rs
@@ -1,13 +1,14 @@
1
use crate::{Float, Pt};
2
3
pub fn area(ring: &[Pt]) -> Float {
4
- let mut i = 0;
5
- let n = ring.len() - 1;
+ let n = ring.len();
6
let mut area = ring[n - 1].y * ring[0].x - ring[n - 1].x * ring[0].y;
7
- while i < n {
8
- i += 1;
+ for i in 1..n {
9
area += ring[i - 1].y * ring[i].x - ring[i - 1].x * ring[i].y;
10
}
+ // Note that in the shoelace formula you need to divide this result by 2 to get the actual area.
+ // Here we skip this division because we only use this area formula to calculate the winding
11
+ // order of polygons and to compare their relative sizes.
12
area
13
14
0 commit comments