Closed grovesNL closed 4 days ago
It looks like both update
and remove
use location
, so I guess they probably have the same issue if this is correct.
Good catch; there was indeed confusion between the coordinates of the target cell and the coordinates of the target node. The specifics aren't quite what you described here: insert
and remove
(but not update
) both used the node coordinates to decide which cell within that node to insert into, which is obviously nonsense. Fixed in eedee1808b7cc6123246fa3df10762a0cf730dc9.
Fixes #11 Fixes #9
I'm not totally sure about this, so a close review would be greatly appreciated. This is my understanding after reviewing it for a while but I might have some details wrong.
The idea is that during
insert
, we look at the target's bounds and try to find a position for it. The bounds returned bybounds_from_world(self.granularity, &bounds)
are fine. When we convert these tree bounds into cell coordinates (location::<GRID_EXPONENT>()
) we do something like this:level
here accounts forGRID_EXPONENT
so internally it ends up beinglevel_for_extent(extent) + GRID_EXPONENT
, which is 8 (level 6 + offset of 2) in this case.In
from_point
we use the level we just calculated to figure out the extent:but this is the extent for level 8 without accounting for
GRID_EXPONENT
. My understanding is that we actually wantcell_extent(level - GRID_EXPONENT)
here (i.e., the extent of level 6), somin
would become the correct offset into the subdivided grid. At the same time though, we want to keep thelevel
as 8 in the returnedCellCoords
.So if we did want to account for
GRID_EXPONENT
when calculatingmin
here, there are a few options:location
/from_point
here and handle the levels/extent directlylocation
/from_point
and check if any of those places have the same problem.location
andfrom_point
aware ofGRID_EXPONENT
and handle it internally, including the adjusted level (8) into the coordinate and using the extent from the unadjusted level (extent of level 6) for themin
calculation.GRID_EXPONENT
cell_extent
GRID_EXPONENT
aware which might simplify some places where we currently docell_extent(level - GRID_EXPONENT)