[−][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::algorithm::centroid::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(), );
Associated Types
Loading content...Required methods
pub fn centroid(&self) -> Self::Output
[src]
See: https://en.wikipedia.org/wiki/Centroid
Examples
use geo::algorithm::centroid::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
impl<T> Centroid for Line<T> where
T: Float,
[src]
T: Float,
impl<T> Centroid for LineString<T> where
T: Float,
[src]
T: Float,
impl<T> Centroid for MultiLineString<T> where
T: Float + FromPrimitive + Sum,
[src]
T: Float + FromPrimitive + Sum,
type Output = Option<Point<T>>
pub fn centroid(&self) -> Self::Output
[src]
The Centroid of a MultiLineString is the mean of the centroids of all the constituent linestrings, weighted by the length of each linestring
impl<T> Centroid for MultiPoint<T> where
T: Float,
[src]
T: Float,
use geo::algorithm::centroid::Centroid; use geo::{MultiPoint, Point}; 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 for MultiPolygon<T> where
T: Float + FromPrimitive + Sum,
[src]
T: Float + FromPrimitive + Sum,
impl<T> Centroid for Point<T> where
T: Float,
[src]
T: Float,
impl<T> Centroid for Polygon<T> where
T: Float + FromPrimitive + Sum,
[src]
T: Float + FromPrimitive + Sum,
impl<T> Centroid for Rect<T> where
T: Float,
[src]
T: Float,