make odd-number-division case more explicit when building quad tree
This commit is contained in:
@@ -29,15 +29,24 @@ struct
|
|||||||
| NODE {x = ox, y = oy, ex = oex, ey = oey, data = oldData, left, right} =>
|
| NODE {x = ox, y = oy, ex = oex, ey = oey, data = oldData, left, right} =>
|
||||||
let
|
let
|
||||||
val dir =
|
val dir =
|
||||||
if x < ox then LESS
|
if x < ox then
|
||||||
else if x > ox then GREATER
|
LESS
|
||||||
else if y < oy then LESS
|
else if x > ox then
|
||||||
else if y > oy then GREATER
|
GREATER
|
||||||
else if ex < oex then LESS
|
else
|
||||||
else if ex > oex then GREATER
|
(if y < oy then
|
||||||
else if ey < oey then LESS
|
LESS
|
||||||
|
else if y > oy then
|
||||||
|
GREATER
|
||||||
|
else
|
||||||
|
(if ex < oex then
|
||||||
|
LESS
|
||||||
|
else if ex > oex then
|
||||||
|
GREATER
|
||||||
|
else
|
||||||
|
(if ey < oey then LESS
|
||||||
else if ey > oey then GREATER
|
else if ey > oey then GREATER
|
||||||
else EQUAL
|
else EQUAL)))
|
||||||
in
|
in
|
||||||
case dir of
|
case dir of
|
||||||
LESS =>
|
LESS =>
|
||||||
@@ -147,19 +156,36 @@ struct
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
(if size mod 2 = 0 orelse size = 1 then
|
||||||
let
|
let
|
||||||
(* handles odd-number divisions.
|
val halfSize = size div 2
|
||||||
* For example, `7 div 2` is 3 because of integer division. *)
|
|
||||||
val halfSize =
|
|
||||||
if size = 1 orelse size mod 2 = 0 then size div 2
|
|
||||||
else (size + 1) div 2
|
|
||||||
|
|
||||||
val bintree = build (x, y, halfSize, grid, bintree)
|
val bintree = build (x, y, halfSize, grid, bintree)
|
||||||
val bintree = build (x + halfSize, y, halfSize, grid, bintree)
|
val bintree = build (x + halfSize, y, halfSize, grid, bintree)
|
||||||
val bintree = build (x, y + halfSize, halfSize, grid, bintree)
|
val bintree = build (x, y + halfSize, halfSize, grid, bintree)
|
||||||
in
|
in
|
||||||
build (x + halfSize, y + halfSize, halfSize, grid, bintree)
|
build (x + halfSize, y + halfSize, halfSize, grid, bintree)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
(* handles odd-number divisions.
|
||||||
|
* For example, `7 div 2` is 3 because of integer division.
|
||||||
|
* We would not cover every pixel unless we handle odd numbers specially. *)
|
||||||
|
let
|
||||||
|
val halfSizeBefore = size div 2
|
||||||
|
val halfSizeAfter = (size + 1) div 2
|
||||||
|
val bintree = build (x, y, halfSizeAfter, grid, bintree)
|
||||||
|
val bintree = build
|
||||||
|
(x + halfSizeBefore, y, halfSizeAfter, grid, bintree)
|
||||||
|
val bintree = build
|
||||||
|
(x, y + halfSizeBefore, halfSizeAfter, grid, bintree)
|
||||||
|
in
|
||||||
|
build
|
||||||
|
( x + halfSizeBefore
|
||||||
|
, y + halfSizeBefore
|
||||||
|
, halfSizeAfter
|
||||||
|
, grid
|
||||||
|
, bintree
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
|
||||||
local
|
local
|
||||||
fun getClickPoint (clickPoints, pos) =
|
fun getClickPoint (clickPoints, pos) =
|
||||||
|
|||||||
Reference in New Issue
Block a user