Quadtrees


The quadtrees vocabulary implements the quadtree data structure in Factor.
<quadtree> ( bounds -- quadtree )


Quadtrees follow the Associative mapping protocol for insertion, deletion, and querying of exact points, using two-dimensional vectors as keys. Additional words are provided for spatial queries and pruning the tree structure:
in-rect ( tree rect -- values )

prune-quadtree ( tree -- tree )


The following words are provided to help write quadtree algorithms:
descend ( pt node -- pt subnode )

each-quadrant ( node quot -- )

map-quadrant ( node quot: ( child-node -- x ) -- array )


Quadtrees can be used to "swizzle" a sequence to improve the locality of spatial data in memory:
swizzle ( sequence quot -- sequence' )