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§
Sourcefn centroid(&self) -> Self::Output
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(),
);