Expand description
Spatial hit-test index with z-order support and dirty-rect caching.
Provides O(1) average-case hit-test queries for thousands of widgets by using uniform grid bucketing with z-order tracking.
§Design
Uses a hybrid approach:
- Uniform grid: Screen divided into cells (default 8x8 pixels each)
- Bucket lists: Each grid cell stores widget IDs that overlap it
- Z-order tracking: Widgets have explicit z-order; topmost wins on overlap
- Dirty-rect cache: Last hover result cached; invalidated on dirty regions
§Invariants
- Hit-test always returns topmost widget (highest z) at query point
- Ties broken by registration order (later = on top)
- Dirty regions force recomputation of affected buckets only
- No allocations on steady-state hit-test queries
§Failure Modes
- Buckets are unbounded
Vecs: pathological overlap degrades queries to a per-bucket linear scan but never loses entries (there is no separate fallback path). HitId::default()(id 0) is reserved as the removed-entry sentinel;SpatialHitIndex::registerrejects it.- Re-registering an existing id replaces the previous entry.
Structs§
- Cache
Stats - Diagnostic statistics for cache performance.
- HitEntry
- A registered widget’s hit information.
- Spatial
HitConfig - Configuration for the spatial hit index.
- Spatial
HitIndex - Spatial index for efficient hit-testing with z-order support.