Skip to main content

is_valid_polygon

Function is_valid_polygon 

Source
pub fn is_valid_polygon<G, P>(polygon: &G) -> Result<(), ValidityFailure>
Expand description

Validate a polygon: its exterior ring (with exterior orientation expectations), each interior ring (with interior orientation expectations), and all exterior/interior and interior/interior ring-pair topology constraints.

Mirrors the polygon arm of boost::geometry::is_valid (detail/is_valid/polygon.hpp).

§Errors

Returns a ValidityFailure describing the first rule the polygon violates, including failures for outside, nested, crossing, or disconnecting interior rings.

§Examples

use geometry_cs::Cartesian;
use geometry_model::{polygon, Point2D, Polygon};
use geometry_overlay::validity::is_valid_polygon;

type P = Point2D<f64, Cartesian>;
let pg: Polygon<P> = polygon![[(0.0, 0.0), (0.0, 4.0), (4.0, 4.0), (4.0, 0.0), (0.0, 0.0)]];
assert!(is_valid_polygon(&pg).is_ok());