Foundational spatial and scene data structures for user interfaces, graphics editors, and CAD viewers.
Understory is a small family of crates designed to be combined in different stacks over time. The focus is on clean separation of concerns, pluggable performance trade‑offs, and long‑term architectural stability.
-
understory_index- A generic 2D AABB index with pluggable backends: FlatVec (linear scan), uniform Grid, R‑tree, and BVH.
- Works across
f32/f64/i64coordinate spaces with widened accumulator metrics for robust splits. - Point and rectangle queries.
- Batched updates via
commit()with coarse damage (added, removed, moved).
-
understory_box_tree- A Kurbo‑native, spatially indexed box tree for scene geometry: local bounds, transforms, optional clips, and z‑order.
- Computes world‑space AABBs and synchronizes them into
understory_indexfor fast hit‑testing and visibility. - Not a layout engine.
- Upstream code (your layout system) decides sizes and positions and then updates this tree.
Both crates are #![no_std] and use alloc.
Examples and tests use std.
We aim for a three‑tree model that scales and composes well.
- Widget tree — state and interaction
- Box tree — geometry and spatial indexing
- Render tree — display list (future crate)
This split makes debugging easier, enables incremental updates, and lets each layer evolve and be swapped independently. For example, a canvas or DWG or DXF viewer can reuse the box and index layers without any UI toolkit.
- Pluggable backends and scalars.
- Choose trade‑offs per product or view.
- Predictable updates.
- Batch with
commit()and use coarse damage for bounding paint. - Conservative geometry.
- Use world AABBs for transforms and rounded clips and apply precise filtering where cheap.
- No surprises.
no_std+alloc, minimal dependencies, and partial conciseDebugby default.
- Arena‑backed R‑tree and BVH reduce allocations and pointer chasing.
- STR and SAH‑like builds are available.
- Benchmarks live under
benches/and compare backends across distributions and sizes. - Choose Grid for regular distributions and good locality.
- Choose R‑tree or BVH for general scenes.
- Choose FlatVec for tiny sets.
- Render tree crate and composition and layering utilities.
- More backends and tuning such as grid origins, heuristics, bulk builders, and churn optimizations.
- Extended benches such as update mixes, overlap stress, and external comparisons.
- Integration examples with upstream toolkits.
- Read the crate READMEs.
understory_index/README.mdhas the API and a “Choosing a backend” guide.understory_box_tree/README.mdhas usage, hit‑testing, and visible‑set examples.
- Run examples.
cargo run -p understory_index --example basic_indexcargo run -p understory_box_tree --example basic_box_treecargo run -p understory_box_tree --example visible_list
- Minimum supported Rust: 1.88.
- Dual‑licensed under Apache‑2.0 and MIT.