Computational Geometry
Robust geometric computation, built on exact arithmetic.
Computational geometry rests on decisions rather than measurements. A polygon is valid or it is not, two boxes meet or they do not, a point lies inside a region, on its boundary or outside it. Floating-point arithmetic approximates every value it computes, and an approximation decides such questions correctly only when the configuration is far from the boundary between one answer and the other. Real data lives at that boundary: parcels share edges, roads end exactly on other roads, and coordinates repeat. There an approximate decision can contradict another one made a moment later, and the structure built on both inherits the contradiction without any error to reveal it.
The packages here decide every such question exactly. Each decision begins in ordinary floating-point arithmetic, alongside a proven bound on its error, and the answer stands only when the bound shows it cannot be wrong. When it can, the decision is recomputed in exact arithmetic, which costs more but answers every finite input correctly. Ordinary data rarely needs the second step, and the data that sits on a boundary always receives it. A result the packages cannot establish is refused rather than approximated, so a caller never builds on an answer that is only probably right.
-
arithmetica: Exact geometric predicates and constructions for
f64input. Orientation, in-circle and in-sphere tests in 2D and 3D, and exact comparisons of distances and angles, each return the exact sign for every finite input. The predicates follow Shewchuk’s adaptive-precision design, completed by an exact integer stage that extends the guarantee over the whole floating-point range. The crate also provides exact line-intersection points and the expansion arithmetic underneath. It has no dependencies. Available on crates.io. -
situs: Spatial indexes over
f64boxes with no false negatives. A static R-tree bulk-loaded by Sort-Tile-Recursive packing and a dynamic R*-tree answer box queries, spatial joins and nearest-neighbor searches. Every comparison is exact or made on a certified bound whose error can only add candidates, so the index never omits an answer, and no distance is presented as exact. It has no dependencies by default. Available on crates.io. -
geometres: Exact, non-constructive computational geometry over
f64coordinates. Validated geometry types, the complete DE-9IM predicates, validation with every invalidity reported, and measurements with a certified sign and a documented bound. Its operations, from hulls and Delaunay triangulation to simplification and coverage union, return only input coordinates, and each result is vouched for exactly or refused. Built on arithmetica and situs. Available on crates.io.
The three packages form layers. arithmetica decides signs, situs filters candidates,
and
geometres decides geometric relationships exactly on both. Each comes with a user guide that
documents
every function, the numerical argument behind it, and worked examples that are compiled and run against the
published
release.