pub struct Polygon2 {
pub vertices: Vec<Point2>,
}Expand description
A simple polygon in the XY-plane, without holes.
The closing edge is implicit, so the last vertex joins the first. Repeating the first vertex at the end creates a zero-length edge rather than closing the ring, which is a common source of degenerate imported data.
Simplicity – no self-intersection – is assumed and not checked: that is a tolerance-dependent judgement, and the types here hold data rather than enforce policy. A polygon set with holes is a different concept; see the planar overlay crate’s region type for that.
Fields§
§vertices: Vec<Point2>Boundary vertices in order. The closing edge is implicit.
Implementations§
Source§impl Polygon2
impl Polygon2
Sourcepub fn signed_area2(&self) -> Scalar
pub fn signed_area2(&self) -> Scalar
Twice the signed area by the shoelace formula.
Summed about the first vertex rather than the origin. The two agree mathematically, but a polygon in georeferenced coordinates sits far from the origin, where the terms are large and nearly cancel; rebasing keeps the terms the size of the polygon instead of the size of the coordinate system.
Fewer than three vertices enclose nothing and give zero.
Sourcepub fn signed_area(&self) -> Scalar
pub fn signed_area(&self) -> Scalar
Signed area: positive counter-clockwise, negative clockwise.
Sourcepub fn is_counter_clockwise(&self) -> bool
pub fn is_counter_clockwise(&self) -> bool
Whether the vertex order is counter-clockwise.
A degenerate polygon has no winding; this reports false for it rather
than inventing one.