JFLib

diagram_core/src/render/index.rs#

Source: lib/diagram_core/src/render/index.rs

index -- a uniform grid over a drawing's items: which items touch a rectangle, without
looking at all of them (culling for the drawing side, hit tests for JD7)

  Grid::build(&items, bounds)     up to 128 x 128 cells over the bounds; an item lands in
                                  every cell its box touches, an item over more than 1024
                                  cells in a list that every query looks at
  grid.query(rect, &mut out)      the items touching rect, ascending (painter's order)
  grid.replace(&changes, &items)  (JD7) ranges of items made anew (render::rebuild): the
                                  grid keeps its cells, the items after a range that grew or
                                  shrank are renumbered

Building is linear in the items times their cells (bounded per item); a query costs the
cells of its rectangle plus what lies in them.  Nothing is quadratic in the number of items.
A cell's list need not be sorted (a query sorts what it found).  An item outside the bounds
the grid was built for lies in the cells at the edge, where a query outside looks too.
  • struct Grid

impl Grid

  • fn build(items: &[Item], bounds: [f64; 4]) -> Grid
  • fn replace(&mut self, changes: &[(usize, usize, usize)], items: &[Item]) ranges of items made anew: (first item, old count, new count) each, ascending and apart, in the old numbering; items the list as it is now
  • fn query(&self, rect: [f64; 4], out: &mut Vec<u32>)

Source: docs/API.md in the JFLib repository.