pub struct Polygon { /* private fields */ }Expand description
A set of vertices with a topology type and orientation query.
Mirrors the C++ Polygon<Vector> template. The base Polygon::is_valid
requires at least one vertex; crate::Wgs84Polygon wraps this and
overrides validity to require at least three.
Implementations§
Source§impl Polygon
impl Polygon
Sourcepub fn new(polygon_type: PolygonType) -> Self
pub fn new(polygon_type: PolygonType) -> Self
Construct an empty polygon of the given type.
Sourcepub fn with_vertices(polygon_type: PolygonType, vertices: Vec<Wgs84>) -> Self
pub fn with_vertices(polygon_type: PolygonType, vertices: Vec<Wgs84>) -> Self
Construct a polygon of the given type with the supplied vertices.
Sourcepub fn add_vertex(&mut self, position: Wgs84)
pub fn add_vertex(&mut self, position: Wgs84)
Append a single vertex.
Sourcepub fn add_vertices(&mut self, vertices: &[Wgs84])
pub fn add_vertices(&mut self, vertices: &[Wgs84])
Append a list of vertices, in order.
Sourcepub fn get(&self, index: usize) -> Wgs84
pub fn get(&self, index: usize) -> Wgs84
Get a vertex by index (panics on out-of-bounds, like C++ operator[]).
Sourcepub fn polygon_type(&self) -> PolygonType
pub fn polygon_type(&self) -> PolygonType
Get the polygon type.
Sourcepub fn set_type(&mut self, polygon_type: PolygonType)
pub fn set_type(&mut self, polygon_type: PolygonType)
Set the polygon type.
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Whether this is a valid polygon.
Base implementation: at least one vertex. crate::Wgs84Polygon
requires at least three.
Sourcepub fn vertices_mut(&mut self) -> &mut Vec<Wgs84>
pub fn vertices_mut(&mut self) -> &mut Vec<Wgs84>
Get the mutable Vec of vertices.
Sourcepub fn orientation(&self) -> Orientation
pub fn orientation(&self) -> Orientation
Compute the winding order via the signed shoelace formula.
Only works for SimplePolygon and a single-triangle TriangleList
(exactly 3 vertices). All other types return InvalidOrientation
without computing area. Collinear vertices (zero area) also return
InvalidOrientation.
Uses raw (lon, lat) doubles; no normalization.