use an immutable vector (always of length 4) for representing quad tree's internal nodes

This commit is contained in:
2025-01-31 06:24:51 +00:00
parent 76c5f9d662
commit 547b5bac97
3 changed files with 54 additions and 47 deletions

View File

@@ -38,14 +38,17 @@ struct
fun foldRegion (rx, ry, rw, rh, env, state, tree) =
case tree of
NODE {topLeft, topRight, bottomLeft, bottomRight, x, y, w, h} =>
NODE {nodes, x, y, w, h} =>
if isCollidingPlus (rx, ry, rw, rh, x, y, w, h) then
let
val state = foldRegion (rx, ry, rw, rh, env, state, topLeft)
val state = foldRegion (rx, ry, rw, rh, env, state, topRight)
val state = foldRegion (rx, ry, rw, rh, env, state, bottomLeft)
val state =
foldRegion (rx, ry, rw, rh, env, state, Vector.sub (nodes, tlIdx))
val state =
foldRegion (rx, ry, rw, rh, env, state, Vector.sub (nodes, trIdx))
val state =
foldRegion (rx, ry, rw, rh, env, state, Vector.sub (nodes, blIdx))
in
foldRegion (rx, ry, rw, rh, env, state, bottomRight)
foldRegion (rx, ry, rw, rh, env, state, Vector.sub (nodes, brIdx))
end
else
state