diff --git a/dotscape b/dotscape index aa50f15..e59a088 100755 Binary files a/dotscape and b/dotscape differ diff --git a/fcore/quad-tree.sml b/fcore/quad-tree.sml index 48a98c7..55ac445 100644 --- a/fcore/quad-tree.sml +++ b/fcore/quad-tree.sml @@ -301,13 +301,9 @@ struct case tree of EMPTY => NONE | LEAF (item as {x = ix, y = iy, ex = iex, ey = iey, data = oldData}) => - if data = oldData then - (* data matches *) - if (x >= ix andalso x <= iex) andalso (y >= iy andalso y <= iey) then - (* search coordinates are in item *) - SOME item - else - NONE + if (x >= ix andalso x <= iex) andalso (y >= iy andalso y <= iey) then + (* search coordinates are in item *) + if data = oldData then (* data matches *) SOME item else NONE else NONE | NODE {tl, tr, bl, br} => @@ -357,4 +353,37 @@ struct (* bottom right *) getItemWithDataAt (x, y, qmx, qmy, halfSizeAfter, br, data) end + + fun getLeftmostX (rootSize, rootTree, prevItem) = + let + val {x = prevX, y = prevY, ex = prevEx, ey = prevEy, data = prevData} = + prevItem + in + case + getItemWithDataAt (prevX - 1, prevY, 0, 0, rootSize, rootTree, prevData) + of + SOME (newItem as {y = newY, ey = newEy, data = newData, ...}) => + if prevY = newY andalso newEy = prevEy andalso prevData = newData then + getLeftmostX (rootSize, rootTree, newItem) + else + prevX + | NONE => prevX + end + + fun getRightmostX (rootSize, rootTree, prevItem) = + let + val {x = prevX, y = prevY, ex = prevEx, ey = prevEy, data = prevData} = + prevItem + in + case + getItemWithDataAt + (prevEx + 1, prevY, 0, 0, rootSize, rootTree, prevData) + of + SOME (newItem as {y = newY, ey = newEy, data = newData, ...}) => + if prevY = newY andalso newEy = prevEy andalso prevData = newData then + getRightmostX (rootSize, rootTree, newItem) + else + prevEx + | NONE => prevEx + end end