logo
pub trait MapCoords<T, NT> {
    type Output;

    fn map_coords(
        &self,
        func: impl Fn(&(T, T)) -> (NT, NT) + Copy
    ) -> Self::Output
    where
        T: CoordNum,
        NT: CoordNum
; }
Expand description

Map a function over all the coordinates in an object, returning a new one

Required Associated Types

Required Methods

Apply a function to all the coordinates in a geometric object, returning a new object.

Examples
use geo::algorithm::map_coords::MapCoords;
use geo::Point;
use approx::assert_relative_eq;

let p1 = Point::new(10., 20.);
let p2 = p1.map_coords(|&(x, y)| (x + 1000., y * 2.));

assert_relative_eq!(p2, Point::new(1010., 40.), epsilon = 1e-6);

You can convert the coordinate type this way as well


let p1: Point<f32> = Point::new(10.0f32, 20.0f32);
let p2: Point<f64> = p1.map_coords(|&(x, y)| (x as f64, y as f64));

assert_relative_eq!(p2, Point::new(10.0f64, 20.0f64), epsilon = 1e-6);

Implementors