{ } JustinGeoSci

Geometres User Guide

Geometres is a Rust crate of exact, non-constructive computational geometry over f64 coordinates.

Overview

Geometres provides validated geometry types, the complete DE-9IM topological predicates, validation with every invalidity reported, and measurements whose sign is certified and whose magnitude carries a documented bound. Every sign decision is an exact predicate from arithmetica, so a predicate never returns a plausible wrong answer on near-degenerate input.

The guide has seven parts:

The crate takes coordinates as f64 values and returns geometric results. It has no knowledge of file formats, coordinate reference systems or geographic features, and it contains no unsafe code.

The contract

Every public function does one of three things:

  • it validates;
  • it decides a predicate exactly;
  • it returns a quantity whose sign is certified and whose magnitude has a documented bound, such as area, length and distance.

No public function returns a coordinate that is not an input coordinate. Selecting among input values is allowed, as when an envelope takes the least and greatest of its coordinates, and computing new ones is not. An intersection point, an offset or a centroid is therefore not computed here. A hull, a simplification, a merge of lines or a coverage union is within it, because each is built from the input’s own vertices.

A result is either vouched for exactly or refused. Where an operation chooses vertices in f64, as simplification does, the exact checks of the crate confirm that the result is valid before it is returned. A result that fails is an error, or, through an explicit *_unvouched entry point, a value marked as not vouched for together with the reason. It is never returned as though it were valid.

An operation does not refuse its input because the input is invalid. Validation is the tool for detecting invalid geometry, and a caller who operates on invalid geometry receives a result that is not vouched for.

Conventions

A few conventions hold throughout the crate.

  • A value that exists has passed its checks. Every constructor validates: coordinates are finite, a ring has at least three distinct vertices, a polygon’s exterior runs counterclockwise and its holes clockwise, each hole lies inside the exterior, and the parts of a MultiPolygon meet at most at finitely many points. The two checks construction leaves to later are described under Constructed geometries.
  • Rings are stored open. A LinearRing holds its distinct vertices without a closing vertex.
  • Orientation is counterclockwise with the y-axis pointing up, decided by a certified area sign rather than a floating-point estimate.
  • Boundaries are exact. A point on an edge is on the boundary, and two polygons that share only an edge touch rather than overlap. No tolerance enters any predicate.
  • Errors. Constructors and predicates return GeometryError, which states the reason for a refusal.
  • Examples are short Rust programs whose results are shown with assert! and assert_eq!. Every example in this guide is compiled and run against the published crate.

Citation

If you use geometres in academic work, please cite the software. The DOI below always resolves to the latest version. Each method the crate implements is cited on the page that documents it.

Erlick, J. (2026). geometres (Version 0.1.0) [Computer software]. https://doi.org/10.5281/zenodo.24064850

Installation

Requirements

  • Rust 1.88 or later, edition 2024
  • Two dependencies: arithmetica for exact predicates and situs for spatial indexing. No situs type appears in the public API.

From crates.io

cargo add geometres

or add it to Cargo.toml directly:

[dependencies]
geometres = "0.1"

Cargo features

Feature Default Effect
3d off Adds Coord3d and the 3D counterpart of each geometry type (see 3D types). Their topology operates on the XY projection, and their winding is certified by the same routine as in 2D.
unstable-counters off Exposes deterministic operation counters for performance tests. They are outside semantic versioning and may change or disappear in any release.
cargo add geometres --features 3d

From source

git clone https://github.com/JustinGeoSci/geometres.git
cd geometres

cargo build
cargo test

API reference documentation for every release is published on docs.rs.

Quick start

Build two squares that share an edge, read their exact relation and measures, and see a clockwise exterior refused at construction and reported by validation:

use geometres::ops::{area, distance, validate};
use geometres::predicates::{intersects, relate, touches};
use geometres::{Coord2d, CoordSeq, LinearRing, Polygon};

let square = |x0: f64, y0: f64, s: f64| {
    let c = |x, y| Coord2d::new(x, y);
    let ring = LinearRing::new(CoordSeq::new(vec![
        c(x0, y0), c(x0 + s, y0), c(x0 + s, y0 + s), c(x0, y0 + s),
    ]))
    .unwrap();
    Polygon::new(ring, vec![]).unwrap()
};
let a = square(0.0, 0.0, 1.0);
let b = square(1.0, 0.0, 1.0); // shares the edge x = 1

// The squares meet along an edge, and their interiors do not.
assert!(touches(&a, &b).unwrap());
assert_eq!(relate(&a, &b).unwrap().matrix().to_string(), "FF2F11212");
assert!(intersects(&a, &square(0.5, 0.5, 1.0)).unwrap());

// Area with a certified sign, and a distance that is exactly zero
// because the squares intersect.
assert_eq!(area(&a), 1.0);
assert_eq!(distance(&a, &b).unwrap(), 0.0);

// A clockwise exterior is refused at construction, and validate reports why.
let cw = vec![
    Coord2d::new(0.0, 0.0), Coord2d::new(0.0, 1.0),
    Coord2d::new(1.0, 1.0), Coord2d::new(1.0, 0.0),
];
let ring = LinearRing::new(CoordSeq::new(cw.clone())).unwrap();
assert!(Polygon::new(ring, vec![]).is_err());
assert!(!validate(&[CoordSeq::new(cw)]).is_empty());

Predicates explains the matrix, and Geometry types lists every constructor and what it refuses.