macro_rules! register_linestring {
($Ty:ty, $Point:ty, |$s:ident| $iter:expr) => { ... };
}Expand description
Register a user-owned linestring type whose storage is iterable as
&Point via a user-supplied expression.
Emits impl Geometry for $Ty with Kind = LinestringTag and
Point = $Point, plus impl Linestring for $Ty whose points()
returns the iterator the closure-shaped argument produces.
Mirrors BOOST_GEOMETRY_REGISTER_LINESTRING from
boost/geometry/geometries/register/linestring.hpp. The Boost
macro only has to specialise traits::tag<G> because the rest of
the linestring concept rides on boost::range for free; the Rust
counterpart has to spell the iterator out, which is why the
macro takes a closure-shaped expression for the iteration.
The iterator expression must yield an
ExactSizeIterator<Item = &$Point> + Clone — the same bound
geometry_trait::Linestring::points requires. For the common
case of a Vec<$Point> field, |s| s.field.iter() is the right
shape.
§Example
use geometry_adapt::register_linestring;
use geometry_cs::Cartesian;
use geometry_model::Point2D;
use geometry_trait::Linestring;
struct MyLineString { points: Vec<Point2D<f64, Cartesian>> }
register_linestring!(MyLineString, Point2D<f64, Cartesian>, |s| s.points.iter());
let ls = MyLineString {
points: vec![Point2D::new(0.0, 0.0), Point2D::new(1.0, 1.0)],
};
assert_eq!(ls.points().count(), 2);