Trait geo::algorithm::map_coords::MapCoordsInPlace
source · pub trait MapCoordsInPlace<T> {
// Required methods
fn map_coords_in_place(
&mut self,
func: impl Fn(Coord<T>) -> Coord<T> + Copy
)
where T: CoordNum;
fn try_map_coords_in_place<E>(
&mut self,
func: impl Fn(Coord<T>) -> Result<Coord<T>, E>
) -> Result<(), E>
where T: CoordNum;
}
Required Methods§
sourcefn map_coords_in_place(&mut self, func: impl Fn(Coord<T>) -> Coord<T> + Copy)where
T: CoordNum,
fn map_coords_in_place(&mut self, func: impl Fn(Coord<T>) -> Coord<T> + Copy)where T: CoordNum,
Apply a function to all the coordinates in a geometric object, in place
Examples
use geo::MapCoordsInPlace;
use geo::{Coord, Point};
use approx::assert_relative_eq;
let mut p = Point::new(10., 20.);
p.map_coords_in_place(|Coord { x, y }| Coord { x: x + 1000., y: y * 2. });
assert_relative_eq!(p, Point::new(1010., 40.), epsilon = 1e-6);
sourcefn try_map_coords_in_place<E>(
&mut self,
func: impl Fn(Coord<T>) -> Result<Coord<T>, E>
) -> Result<(), E>where
T: CoordNum,
fn try_map_coords_in_place<E>( &mut self, func: impl Fn(Coord<T>) -> Result<Coord<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::Coord;
let mut p1 = geo::point!{x: 10u32, y: 20u32};
p1.try_map_coords_in_place(|Coord { x, y }| -> Result<_, &str> {
Ok(Coord {
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},
);