macro_rules! polygon {
[ [ $( ( $($outer_pt:expr),+ $(,)? ) ),* $(,)? ]
$(, [ $( ( $($inner_pt:expr),+ $(,)? ) ),* $(,)? ] )*
$(,)?
] => { ... };
}Expand description
Construct a crate::Polygon from a bracketed list whose
first element is the outer ring and the rest are holes (interior
rings).
Each ring is written as a bracketed, comma-separated list of (x, y)
tuples; tuples expand through point!.
§Examples
use geometry_cs::Cartesian;
use geometry_model::{polygon, Point2D, Polygon};
use geometry_trait::{Polygon as _, Ring as _};
let p: Polygon<Point2D<f64, Cartesian>> = polygon![
[(0.0, 0.0), (4.0, 0.0), (4.0, 3.0), (0.0, 3.0), (0.0, 0.0)]
];
assert_eq!(p.exterior().points().count(), 5);
assert_eq!(p.interiors().count(), 0);§Polygons with holes
The outer ring comes first, then zero or more inner rings (holes) each as their own bracketed list:
use geometry_cs::Cartesian;
use geometry_model::{polygon, Point2D, Polygon};
use geometry_trait::{Polygon as _, Ring as _};
let p: Polygon<Point2D<f64, Cartesian>> = polygon![
// Outer ring: a 5×5 square.
[(0.0, 0.0), (5.0, 0.0), (5.0, 5.0), (0.0, 5.0), (0.0, 0.0)],
// Hole: a 1×1 square inside it.
[(1.0, 1.0), (2.0, 1.0), (2.0, 2.0), (1.0, 2.0), (1.0, 1.0)],
];
assert_eq!(p.exterior().points().count(), 5);
assert_eq!(p.interiors().count(), 1);
assert_eq!(p.interiors().next().unwrap().points().count(), 5);Mirrors the C++ “polygon with hole” example in
boost/geometry/doc/src/examples/quick_start.cpp lines 121-129,
rebuilt against the Rust crate::Polygon constructor.