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

pub trait MapCoords<T, NT> {
    type Output;
    fn map_coords(&self, func: &Fn(&(T, T)) -> (NT, NT)) -> Self::Output
    where
        T: CoordinateType,
        NT: CoordinateType
; }

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::Point;
use geo::algorithm::map_coords::MapCoords;

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