geonative_utils/lib.rs
1//! # geonative-utils
2//!
3//! Geometric algorithms that operate on the geonative-core IR but don't
4//! belong in `core` itself (core stays focused on data model + codec
5//! primitives). When MVT/WMS/raster output needs Level-of-Detail
6//! simplification, this is where the math lives.
7//!
8//! ## What's in it
9//!
10//! - [`simplify::douglas_peucker`] — the canonical line-simplification
11//! algorithm. Operates on a `&[Coord]` slice.
12//! - [`simplify::simplify_geometry`] — dispatch helper: applies DP to every
13//! linear part of a `Geometry`, preserves ring closure on polygons,
14//! passes Point/MultiPoint/Empty through unchanged.
15//! - [`simplify::tolerance_for_zoom`] — small preset table mapping web-map
16//! zoom levels to sensible degree-based tolerances. Calibrated for
17//! lat/lng input (≈ pixel-equivalent at the equator).
18//!
19//! ## Clever bits
20//!
21//! - **Ring closure preserved.** Polygon rings come in closed
22//! (`first == last`); naive DP could drop the duplicate. We snapshot the
23//! closing vertex and re-append it after simplification if it was lost.
24//! - **No coord allocation when below the keep threshold.** Tiny rings
25//! (`len ≤ 3` for lines, `len ≤ 4` for closed rings) pass through unchanged
26//! to avoid both extra work and the risk of degeneration.
27//! - **Tolerance is in input units.** Pass lng/lat tolerance for WGS84 data
28//! (use [`simplify::tolerance_for_zoom`]); pass meters for projected data.
29//! No automatic CRS-aware tolerance — that would require knowing the CRS,
30//! which we deliberately leave to the caller.
31
32//! ## Module organization
33//!
34//! Algorithms are grouped by domain (`simplify`, future `measure`, `index`,
35//! `orient`, …). The crate root **deliberately does not re-export** them — we
36//! want callers to write `geonative_utils::simplify::douglas_peucker(...)` so
37//! the domain stays visible at the call site. This pattern mirrors how `std`
38//! organises its utility surfaces (`std::fmt`, `std::iter`, `std::collections`)
39//! and how the `geo` crate organises algorithms.
40
41#![forbid(unsafe_code)]
42#![warn(missing_debug_implementations)]
43
44pub mod index;
45pub mod measure;
46pub mod simplify;