Skip to main content

Module centroid

Module centroid 

Source
Expand description

CentroidStrategy<G> — geometric centre of a geometry.

Mirrors the per-CS centroid-strategy concept from boost/geometry/strategies/centroid/services.hpp plus the Cartesian implementations in boost/geometry/strategies/cartesian/centroid_*.hpp and the per-kind dispatch in boost/geometry/algorithms/centroid.hpp. Per-kind Cartesian formulas:

  • Segment, Box → midpoint of endpoints / corners
  • Linestring → length-weighted midpoint of segments
  • Ring (closed) / Polygon → area-weighted Bashein–Detmer formula
  • MultiPoint → arithmetic mean of points

Each per-kind impl lives behind a different strategy unit-struct so coherence stays disjoint — the same distinct-struct-per-kind trick as area (see strategies/cartesian/area.hpp and the module docs of crate::area). Rust cannot prove a single type is not both a Ring and a Polygon, so a single strategy carrying overlapping impl CentroidStrategy<G> blocks keyed off the open traits would be rejected (E0119); the sibling unit-structs below each carry a single concept-bounded impl (impl<G: Ring> … for CartesianRingCentroid, …) — distinct Self, so no overlap. The [CentroidStrategyForKind] picker then routes G::Kind (the tag Geometry::Kind already carries) to the right struct, disjoint on the tag. This opens every kind to any concept-adapted foreign type, not just the geometry-model structs.

Structs§

CartesianBoxCentroid
Cartesian centroid for a geometry_trait::Box — corner midpoint per dimension.
CartesianLinestringCentroid
Cartesian centroid for a geometry_trait::Linestring — length-weighted midpoint of each segment, summed and divided by total length.
CartesianMultiPointCentroid
Cartesian centroid for a geometry_trait::MultiPoint — arithmetic mean of the member points.
CartesianPolygonCentroid
Cartesian centroid for a geometry_trait::Polygon — the CartesianRingCentroid formula applied to every ring (exterior plus interiors), combined by signed area.
CartesianRingCentroid
Cartesian centroid for a geometry_trait::Ring — the Bashein–Detmer formula (signed-area-weighted vertex pairs).
CartesianSegmentCentroid
Cartesian centroid for a geometry_trait::Segment(start + end) / 2.

Traits§

CentroidStrategy
A strategy for computing the centroid of G.