boost_geometry
A Rust port of Boost.Geometry following its philosophy: dimension-agnostic, coordinate-system-agnostic, bring-your-own-type, strategy-pluggable.
The library's algorithms are written against concept traits
(Point, Ring, Polygon, …), not concrete structs — so your own
domain types participate directly, exactly like
BOOST_GEOMETRY_REGISTER_* in C++.
- Edition: Rust 2024, MSRV 1.85
- Safety:
unsafe_code = "forbid"across the whole workspace - Docs: see
docs/for the architecture, the tag-dispatch pattern, and the overlay engine
Quick start — your own polygon type, buffered and validated
Add the dependency:
With #[derive(Point)]
Derive Point on your own coordinate struct, register your own ring
and polygon types with one macro declaration each, run
is_valid_polygon on them directly, and buffer
(runnable as cargo run --example parcel_buffer):
use Point;
use ;
use ;
use *;
// Your own geometry types — no wrapper, no conversion trait, and no
// library point type: the derive turns your struct into a Point.
// One declaration each and the library's algorithms accept them.
register_ring!;
register_polygon!;
Output:
parcel valid: Ok(())
buffered valid: Ok(())
area 4.000 -> 15.141
Without the derive
The derive is pure sugar: it emits the Geometry + Point
(+ PointMut) impls below. Writing them by hand is the escape hatch
for computed coordinates, packed storage, or FFI structs — same flow,
same output (runnable as cargo run --example parcel_buffer_manual):
use ;
use Cartesian;
use ;
use *;
use PointTag;
use ;
// Your own point type, registered by hand — the escape hatch for
// computed coordinates, packed storage, or FFI structs the derive
// cannot express.
// Only needed by algorithms that construct points (buffer, correct).
register_ring!;
register_polygon!;
The buffered area matches the closed form for a square grown by distance d with round corners: s² + 4·s·d + π·d² = 4 + 8 + π ≈ 15.14.
What the example shows:
register_ring!/register_polygon!implement the concept traits for your structs (Rust's orphan rule forbids a blanket impl, so the macros mint it per type — the same coherence workaround theBOOST_GEOMETRY_REGISTER_*macros perform in C++). Defaults are closed, clockwise rings; both are overridable per type.is_valid_polygonchecks the OGC simple-feature rules — point count, closure, finite coordinates, spikes, self-intersections, ring orientation, hole containment — and reports the first failure as aValidityFailurevariant (Err(SelfIntersection),Err(WrongOrientation), …) rather than a barefalse.buffer_convex_polygongrows the polygon outward, rounding each corner with a circular arc (JoinStrategy::Mitergives sharp corners instead). v1 buffers points and convex polygons with positive distances.correctfixes ring closure and orientation in place — the Boostbg::correctcounterpart.
Workspace layout
Nineteen crates form a dependency spine from foundational tag/coords
crates up through traits, models, strategies, and algorithms to the
boost_geometry facade — plus adapters (nalgebra, geo-types), IO
(WKT, WKB, GeoJSON, SVG), an R-tree, overlay operations, and
projections. boost_geometry re-exports everything; depend on it alone
unless you need a slimmer build.
See docs/01-architecture.md
for the full map.
no_std support
Generated by .github/scripts/no_std_support.py, which builds every crate
with --no-default-features (falling back to --features libm for crates
that need a libm-backed Float impl) and is checked in CI:
| Crate | no_std |
|---|---|
boost_geometry |
✅ |
geometry-adapt |
✅ |
geometry-adapt-geo-types |
✅ |
geometry-adapt-nalgebra |
✅ |
geometry-algorithm |
✅ |
geometry-coords |
✅ |
geometry-cs |
✅ |
geometry-derive |
✅ |
geometry-io-geojson |
❌ |
geometry-io-svg |
❌ |
geometry-io-wkb |
❌ |
geometry-io-wkt |
❌ |
geometry-model |
✅ |
geometry-overlay |
✅ |
geometry-proj |
✅ |
geometry-rtree |
✅ |
geometry-strategy |
✅ |
geometry-tag |
✅ |
geometry-trait |
✅ |
License
BSL-1.0 — see LICENSE.