implement functions to get leftmost and rightmost x coordinates with mergeable items
This commit is contained in:
@@ -301,13 +301,9 @@ struct
|
|||||||
case tree of
|
case tree of
|
||||||
EMPTY => NONE
|
EMPTY => NONE
|
||||||
| LEAF (item as {x = ix, y = iy, ex = iex, ey = iey, data = oldData}) =>
|
| 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
|
if (x >= ix andalso x <= iex) andalso (y >= iy andalso y <= iey) then
|
||||||
(* search coordinates are in item *)
|
(* search coordinates are in item *)
|
||||||
SOME item
|
if data = oldData then (* data matches *) SOME item else NONE
|
||||||
else
|
|
||||||
NONE
|
|
||||||
else
|
else
|
||||||
NONE
|
NONE
|
||||||
| NODE {tl, tr, bl, br} =>
|
| NODE {tl, tr, bl, br} =>
|
||||||
@@ -357,4 +353,37 @@ struct
|
|||||||
(* bottom right *)
|
(* bottom right *)
|
||||||
getItemWithDataAt (x, y, qmx, qmy, halfSizeAfter, br, data)
|
getItemWithDataAt (x, y, qmx, qmy, halfSizeAfter, br, data)
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user