Trait geo::algorithm::coords_iter::CoordsIter [−][src]
pub trait CoordsIter<'a> {
type Iter: Iterator<Item = Coordinate<Self::Scalar>>;
type ExteriorIter: Iterator<Item = Coordinate<Self::Scalar>>;
type Scalar: CoordNum;
fn coords_iter(&'a self) -> Self::Iter;
fn coords_count(&'a self) -> usize;
fn exterior_coords_iter(&'a self) -> Self::ExteriorIter;
}
Expand description
Iterate over geometry coordinates.
Associated Types
type Iter: Iterator<Item = Coordinate<Self::Scalar>>
type ExteriorIter: Iterator<Item = Coordinate<Self::Scalar>>
Required methods
fn coords_iter(&'a self) -> Self::Iter
fn coords_iter(&'a 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(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::Coordinate { x: -10., y: 0. }), iter.next());
assert_eq!(Some(geo::Coordinate { x: 20., y: 20. }), iter.next());
assert_eq!(Some(geo::Coordinate { x: 30., y: 40. }), iter.next());
assert_eq!(None, iter.next());
fn coords_count(&'a self) -> usize
fn coords_count(&'a 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());
fn exterior_coords_iter(&'a self) -> Self::ExteriorIter
fn exterior_coords_iter(&'a 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::Coordinate { x: 1., y: 0. }), iter.next());
assert_eq!(Some(geo::Coordinate { x: 2., y: 1. }), iter.next());
assert_eq!(Some(geo::Coordinate { x: 1., y: 2. }), iter.next());
assert_eq!(Some(geo::Coordinate { x: 0., y: 1. }), iter.next());
assert_eq!(Some(geo::Coordinate { x: 1., y: 0. }), iter.next());
assert_eq!(None, iter.next());