Skip to main content

Module area

Module area 

Source
Expand description

Strategy for computing the area of a Cartesian geometry.

Mirrors three pieces of Boost.Geometry that collaborate to make boost::geometry::area(g) work for any ring / polygon / box / multi-polygon in any coordinate system:

  • boost/geometry/strategies/area/services.hpp — the services::default_strategy<G> metafunction that picks the per-CS area strategy.
  • boost/geometry/strategies/area/cartesian.hppstrategies::area::cartesian<> plus its services::default_strategy<Geometry, cartesian_tag> specialisation; the umbrella strategy hands out strategy::area::cartesian<> for ring / polygon geometries and strategy::area::cartesian_box<> for boxes.
  • boost/geometry/strategy/cartesian/area.hpp:91-120 — the trapezoidal-rule accumulation (x1 + x2) * (y1 - y2) summed over consecutive segments and halved at the end. The Boost code wraps the ring in closed_clockwise_view first so a counter-clockwise declared ring traversed in its declared order still produces a positive area; the Rust port mirrors that by flipping the sign when PointOrder::CounterClockwise is declared.

T34 lands the Cartesian implementation only — Boost’s Spherical / Geographic area strategies arrive alongside the Haversine / geographic distance work in later tasks (T40+).

§Coherence note

Rust’s coherence rules cannot prove that no single type is both a Ring and a Polygon (or a Box / MultiPolygon) at the same time, so a single ShoelaceArea carrying four impl AreaStrategy<G> blocks keyed off G: Ring, G: Polygon, G: Box, G: MultiPolygon is rejected as overlapping. Boost sidesteps this with tag dispatch (strategy::area::cartesian vs. strategy::area::cartesian_box, plus the per-tag dispatch::area arms in algorithms/area.hpp:131-187); we mirror that split with four sibling unit-structs below, each implementing AreaStrategy for exactly one geometry kind.

Structs§

ShoelaceArea
Cartesian shoelace area for a Ring.
ShoelaceBoxArea
Cartesian area for a Box: (xmax - xmin) * (ymax - ymin).
ShoelaceMultiPolygonArea
Cartesian shoelace area for a MultiPolygon — sum of the areas of its member polygons.
ShoelacePolygonArea
Cartesian shoelace area for a Polygon — outer ring area minus the sum of interior-ring areas.

Traits§

AreaStrategy
A strategy for computing the area of a geometry.
DefaultArea
“Which (polygon) area strategy do we pick by default for this CS family?”

Type Aliases§

DefaultAreaStrategy
Type alias resolving the default area strategy for geometry G by walking G -> G::Point -> Cs -> Family -> DefaultArea::Strategy.