diff --git a/dotscape b/dotscape index c9a1f97..bc874a5 100755 Binary files a/dotscape and b/dotscape differ diff --git a/fcore/quad-tree.sml b/fcore/quad-tree.sml index 14a32cd..fad93ec 100644 --- a/fcore/quad-tree.sml +++ b/fcore/quad-tree.sml @@ -29,15 +29,24 @@ struct | NODE {x = ox, y = oy, ex = oex, ey = oey, data = oldData, left, right} => let val dir = - if x < ox then LESS - else if x > ox then GREATER - else if y < oy then 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 EQUAL + if x < ox then + LESS + else if x > ox then + GREATER + else + (if y < oy then + 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 EQUAL))) in case dir of LESS => @@ -147,19 +156,36 @@ struct end end else - let - (* handles odd-number divisions. - * 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 + halfSize, y, halfSize, grid, bintree) - val bintree = build (x, y + halfSize, halfSize, grid, bintree) - in - build (x + halfSize, y + halfSize, halfSize, grid, bintree) - end + (if size mod 2 = 0 orelse size = 1 then + let + val halfSize = size div 2 + val bintree = build (x, y, halfSize, grid, bintree) + val bintree = build (x + halfSize, y, halfSize, grid, bintree) + val bintree = build (x, y + halfSize, halfSize, grid, bintree) + in + build (x + halfSize, y + halfSize, halfSize, grid, bintree) + 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 fun getClickPoint (clickPoints, pos) =