Trait shapefile::record::traits::HasXY[][src]

pub trait HasXY {
    fn x(&self) -> f64;
fn y(&self) -> f64; }

Trait to access the x, and y values of a point

Examples

use shapefile::record::traits::HasXY;
use shapefile::{Point, NO_DATA, PointZ};
fn mean_x_y<PointType: HasXY>(points: &[PointType]) -> (f64, f64) {
    let (sum_x, sum_y) = points.iter()
                               .fold((0.0, 0.0),
                                      |acc, point| (acc.0 + point.x(), acc.1 + point.y()));

    (sum_x / points.len() as f64, sum_y / points.len() as f64)
}
let points = vec![PointZ::new(1.0, 2.0, 3.0, NO_DATA), PointZ::new(1.0, 2.0, 5.0, NO_DATA)];
assert_eq!(mean_x_y(&points), (1.0, 2.0));

Required methods

fn x(&self) -> f64[src]

Returns the value of the x dimension

fn y(&self) -> f64[src]

Returns the value of the y dimension

Loading content...

Implementors

impl HasXY for Point[src]

impl HasXY for PointM[src]

impl HasXY for PointZ[src]

Loading content...