pub trait Centroid {
    type Output;

    // Required method
    fn centroid(&self) -> Self::Output;
}
Expand description

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::Centroid;
use geo::{point, polygon};

// rhombus shaped polygon
let polygon = polygon![
    (x: -2., y: 1.),
    (x: 1., y: 3.),
    (x: 4., y: 1.),
    (x: 1., y: -1.),
    (x: -2., y: 1.),
];

assert_eq!(
    Some(point!(x: 1., y: 1.)),
    polygon.centroid(),
);

Required Associated Types§

Required Methods§

source

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

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

§Examples
use geo::Centroid;
use geo::{line_string, point};

let line_string = line_string![
    (x: 40.02f64, y: 116.34),
    (x: 40.02f64, y: 118.23),
];

assert_eq!(
    Some(point!(x: 40.02, y: 117.285)),
    line_string.centroid(),
);

Implementors§

source§

impl<T> Centroid for Geometry<T>
where T: GeoFloat,

§

type Output = Option<Point<T>>

source§

impl<T> Centroid for GeometryCollection<T>
where T: GeoFloat,

§

type Output = Option<Point<T>>

source§

impl<T> Centroid for Line<T>
where T: GeoFloat,

§

type Output = Point<T>

source§

impl<T> Centroid for LineString<T>
where T: GeoFloat,

§

type Output = Option<Point<T>>

source§

impl<T> Centroid for MultiLineString<T>
where T: GeoFloat,

§

type Output = Option<Point<T>>

source§

impl<T> Centroid for MultiPoint<T>
where T: GeoFloat,

§

type Output = Option<Point<T>>

source§

impl<T> Centroid for MultiPolygon<T>
where T: GeoFloat,

§

type Output = Option<Point<T>>

source§

impl<T> Centroid for Point<T>
where T: GeoFloat,

§

type Output = Point<T>

source§

impl<T> Centroid for Polygon<T>
where T: GeoFloat,

§

type Output = Option<Point<T>>

source§

impl<T> Centroid for Rect<T>
where T: GeoFloat,

§

type Output = Point<T>

source§

impl<T> Centroid for Triangle<T>
where T: GeoFloat,

§

type Output = Point<T>