implement functions to get leftmost and rightmost x coordinates with mergeable items

This commit is contained in:
2025-07-07 23:52:24 +01:00
parent fb2bc76c10
commit 0464dd1ce3
2 changed files with 36 additions and 7 deletions

BIN
dotscape

Binary file not shown.

View File

@@ -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