Trait geo::algorithm::coords_iter::CoordsIter
source · pub trait CoordsIter {
type Iter<'a>: Iterator<Item = Coord<Self::Scalar>>
where Self: 'a;
type ExteriorIter<'a>: Iterator<Item = Coord<Self::Scalar>>
where Self: 'a;
type Scalar: CoordNum;
// Required methods
fn coords_iter(&self) -> Self::Iter<'_>;
fn coords_count(&self) -> usize;
fn exterior_coords_iter(&self) -> Self::ExteriorIter<'_>;
}
Expand description
Iterate over geometry coordinates.
Required Associated Types§
type Iter<'a>: Iterator<Item = Coord<Self::Scalar>> where Self: 'a
type ExteriorIter<'a>: Iterator<Item = Coord<Self::Scalar>> where Self: 'a
type Scalar: CoordNum
Required Methods§
sourcefn coords_iter(&self) -> Self::Iter<'_>
fn coords_iter(&self) -> Self::Iter<'_>
Iterate over all exterior and (if any) interior coordinates of a geometry.
Examples
use geo::coords_iter::CoordsIter;
let multi_point = geo::MultiPoint::new(vec![
geo::point!(x: -10., y: 0.),
geo::point!(x: 20., y: 20.),
geo::point!(x: 30., y: 40.),
]);
let mut iter = multi_point.coords_iter();
assert_eq!(Some(geo::coord! { x: -10., y: 0. }), iter.next());
assert_eq!(Some(geo::coord! { x: 20., y: 20. }), iter.next());
assert_eq!(Some(geo::coord! { x: 30., y: 40. }), iter.next());
assert_eq!(None, iter.next());
sourcefn coords_count(&self) -> usize
fn coords_count(&self) -> usize
Return the number of coordinates in a geometry.
Examples
use geo::coords_iter::CoordsIter;
use geo::line_string;
let ls = line_string![
(x: 1., y: 2.),
(x: 23., y: 82.),
(x: -1., y: 0.),
];
assert_eq!(3, ls.coords_count());
sourcefn exterior_coords_iter(&self) -> Self::ExteriorIter<'_>
fn exterior_coords_iter(&self) -> Self::ExteriorIter<'_>
Iterate over all exterior coordinates of a geometry.
Examples
use geo::coords_iter::CoordsIter;
use geo::polygon;
// a diamond shape
let polygon = polygon![
exterior: [
(x: 1.0, y: 0.0),
(x: 2.0, y: 1.0),
(x: 1.0, y: 2.0),
(x: 0.0, y: 1.0),
(x: 1.0, y: 0.0),
],
interiors: [
[
(x: 1.0, y: 0.5),
(x: 0.5, y: 1.0),
(x: 1.0, y: 1.5),
(x: 1.5, y: 1.0),
(x: 1.0, y: 0.5),
],
],
];
let mut iter = polygon.exterior_coords_iter();
assert_eq!(Some(geo::coord! { x: 1., y: 0. }), iter.next());
assert_eq!(Some(geo::coord! { x: 2., y: 1. }), iter.next());
assert_eq!(Some(geo::coord! { x: 1., y: 2. }), iter.next());
assert_eq!(Some(geo::coord! { x: 0., y: 1. }), iter.next());
assert_eq!(Some(geo::coord! { x: 1., y: 0. }), iter.next());
assert_eq!(None, iter.next());
Object Safety§
This trait is not object safe.