[][src]Trait geo::algorithm::centroid::Centroid

pub trait Centroid<T: Float> {
    type Output;
    fn centroid(&self) -> Self::Output;
}

Calculation of the centroid. The centroid is the arithmetic mean position of all points in the shape. Informally, it is the point at which a cutout of the shape could be perfectly balanced on the tip of a pin. The geometric centroid of a convex object always lies in the object. A non-convex object might have a centroid that is outside the object itself.

Examples

use geo::prelude::*;
use geo::{LineString, Point, Polygon};

// rhombus shaped polygon
let polygon = Polygon::new(
    LineString::from(vec![
       (-2., 1.),
       (1., 3.),
       (4., 1.),
       (1., -1.),
       (-2., 1.),
    ]),
    vec![],
);

assert_eq!(
    Point::from((1., 1.)),
    polygon.centroid().unwrap(),
);

Associated Types

type Output

Loading content...

Required methods

fn centroid(&self) -> Self::Output

See: https://en.wikipedia.org/wiki/Centroid

Examples

use geo::{Point, LineString};
use geo::algorithm::centroid::Centroid;

let mut vec = Vec::new();
vec.push(Point::new(40.02f64, 116.34));
vec.push(Point::new(40.02f64, 118.23));
let linestring = LineString::from(vec);

assert_eq!(linestring.centroid().unwrap(), Point::new(40.02, 117.285));
Loading content...

Implementors

impl<T> Centroid<T> for Line<T> where
    T: Float
[src]

type Output = Point<T>

impl<T> Centroid<T> for LineString<T> where
    T: Float
[src]

type Output = Option<Point<T>>

impl<T> Centroid<T> for MultiPoint<T> where
    T: Float
[src]

use geo::{MultiPoint, Point};
use geo::algorithm::centroid::Centroid;

let empty: Vec<Point<f64>> = Vec::new();
let empty_multi_points: MultiPoint<_> = empty.into();
assert_eq!(empty_multi_points.centroid(), None);

let points: MultiPoint<_> = vec![(5., 1.), (1., 3.), (3., 2.)].into();
assert_eq!(points.centroid(), Some(Point::new(3., 2.)));

type Output = Option<Point<T>>

impl<T> Centroid<T> for MultiPolygon<T> where
    T: Float + FromPrimitive + Sum
[src]

type Output = Option<Point<T>>

impl<T> Centroid<T> for Point<T> where
    T: Float
[src]

type Output = Point<T>

impl<T> Centroid<T> for Polygon<T> where
    T: Float + FromPrimitive + Sum
[src]

type Output = Option<Point<T>>

impl<T> Centroid<T> for Rect<T> where
    T: Float
[src]

type Output = Point<T>

Loading content...