[−][src]Trait geo::algorithm::centroid::Centroid
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
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));
Implementors
impl<T> Centroid<T> for Line<T> where
T: Float,
[src]
T: Float,
impl<T> Centroid<T> for LineString<T> where
T: Float,
[src]
T: Float,
impl<T> Centroid<T> for MultiPoint<T> where
T: Float,
[src]
T: Float,
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.)));
impl<T> Centroid<T> for MultiPolygon<T> where
T: Float + FromPrimitive + Sum,
[src]
T: Float + FromPrimitive + Sum,
impl<T> Centroid<T> for Point<T> where
T: Float,
[src]
T: Float,
impl<T> Centroid<T> for Polygon<T> where
T: Float + FromPrimitive + Sum,
[src]
T: Float + FromPrimitive + Sum,
impl<T> Centroid<T> for Rect<T> where
T: Float,
[src]
T: Float,