Trait geo::algorithm::MapCoordsInPlace
source · [−]pub trait MapCoordsInPlace<T> {
fn map_coords_in_place(
&mut self,
func: impl Fn(Coordinate<T>) -> Coordinate<T> + Copy
)
where
T: CoordNum;
fn try_map_coords_in_place<E>(
&mut self,
func: impl Fn(Coordinate<T>) -> Result<Coordinate<T>, E>
) -> Result<(), E>
where
T: CoordNum;
}
Required Methods
fn map_coords_in_place(
&mut self,
func: impl Fn(Coordinate<T>) -> Coordinate<T> + Copy
) where
T: CoordNum,
fn map_coords_in_place(
&mut self,
func: impl Fn(Coordinate<T>) -> Coordinate<T> + Copy
) where
T: CoordNum,
Apply a function to all the coordinates in a geometric object, in place
Examples
use geo::MapCoordsInPlace;
use geo::{Coordinate, Point};
use approx::assert_relative_eq;
let mut p = Point::new(10., 20.);
p.map_coords_in_place(|Coordinate { x, y }| Coordinate { x: x + 1000., y: y * 2. });
assert_relative_eq!(p, Point::new(1010., 40.), epsilon = 1e-6);
fn try_map_coords_in_place<E>(
&mut self,
func: impl Fn(Coordinate<T>) -> Result<Coordinate<T>, E>
) -> Result<(), E> where
T: CoordNum,
fn try_map_coords_in_place<E>(
&mut self,
func: impl Fn(Coordinate<T>) -> Result<Coordinate<T>, E>
) -> Result<(), E> where
T: CoordNum,
Map a fallible function over all the coordinates in a geometry, in place, returning a Result
.
Upon encountering an Err
from the function, try_map_coords_in_place
immediately returns
and the geometry is potentially left in a partially mapped state.
Examples
use geo::MapCoordsInPlace;
use geo::Coordinate;
let mut p1 = geo::point!{x: 10u32, y: 20u32};
p1.try_map_coords_in_place(|Coordinate { x, y }| -> Result<_, &str> {
Ok(Coordinate {
x: x.checked_add(1000).ok_or("Overflow")?,
y: y.checked_mul(2).ok_or("Overflow")?,
})
})?;
assert_eq!(
p1,
geo::point!{x: 1010u32, y: 40u32},
);