Skip to main content

Crate utz_encode

Crate utz_encode 

Source
Expand description

The μTZ encoder crate covers everything between loaded features and a .utz container: shared-arc topology and simplification (topo), quantization, the grid prefilter (grid), and the delta+varint container serializer with its generic-compression codecs (encode).

The crate was split out of utz_build so it compiles for wasm32-unknown-unknown: the webdist viewer runs this exact pipeline live for size stats (the wasm surface lives in utz_viz). Everything here is pure Rust with no filesystem or network access; the one C-backed codec (zstd) sits behind the zstd cargo feature.

Modules§

clean
Post-quantization cleanup of the shared arcs. Snapping arc vertices to a coarse grid (especially i16, ~611 m cells) collapses nearby vertices and folds thin features onto themselves, leaving consecutive duplicates, zero-area spurs where the path reverses over itself (“spikes”), and rings whose area vanishes entirely. Left in, the spurs self-overlap and flip the runtime’s even-odd PIP parity inside the fold.
encode
The self-describing container serializer.
grid
The grid and interned-CSR builder.
topo
The TopoJSON-style shared-arc topology builder. Shared borders are cut into arcs at junctions, each arc is stored ONCE as i24 delta+varint, and every ring is a list of signed arc references. Optional topology-aware Ramer–Douglas–Peucker (RDP) line simplification runs on each arc a single time (endpoints fixed), so neighbouring polygons stay stitched. Other open-polyline simplifiers could slot into the same per-arc pass.
validate
Ring-geometry validation, which finds where assembled rings self-cross, overlap themselves collinearly, self-touch, or collapse entirely. It is shared by the utz_dev_cli quant-clean report and the viewer’s live problems panel (wasm.rs), so both agree on what “problematic geometry” means.

Structs§

Feat
One timezone feature as loaded from the source GeoJSON: it carries the polygons plus the tzid and UTC offset metadata.

Enums§

Error

Constants§

KM_PER_DEG
Kilometers per degree, METERS_PER_DEG scaled; area math uses KM_PER_DEG² (with a latitude cosine) for km² per square degree.
METERS_PER_DEG
Meters per degree of latitude (and of longitude at the equator): the workspace’s one flat conversion between tolerances in meters (epsilon_m) and coordinate degrees.
QMAX_I24

Functions§

dq_lat
Dequantizes a latitude from a grid with half-range qmax, the inverse of q_lat().
dq_lon
Dequantizes a longitude from a grid with half-range qmax, the inverse of q_lon(). The input is f64 so fractional grid positions (e.g. ring intersection points) dequantize too; stored coordinates pass through f64::from.
push_i24
Appends value’s low three little-endian bytes, the stored form of an i24-quantized coordinate.
q24_lat
q24_lon
q_lat
Quantizes a latitude onto a grid with half-range qmax.
q_lon
Quantizes a longitude onto a grid with half-range qmax (see qmax_for()).
qmax_for
The half-range of an i{bits} quantization grid (2^(bits-1) - 1).
read_i24

Type Aliases§

Arc
One open shared-boundary polyline (see topo). This is NOT std::sync::Arc.
Poly
One polygon’s rings, the exterior ring first and the interior (hole) rings after.
Result
Ring
One closed ring. The closing vertex is not duplicated.