logo

Trait geo::algorithm::map_coords::MapCoords[][src]

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

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;

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

assert_eq!(p2, Point::new(1010., 40.));

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_eq!(p2, Point::new(10.0f64, 20.0f64));

Implementors