finished coding merging functionality

This commit is contained in:
2025-07-08 16:59:21 +01:00
parent 1ae67bb616
commit 3fe3aa1d4d
2 changed files with 13 additions and 22 deletions

BIN
dotscape

Binary file not shown.

View File

@@ -320,13 +320,12 @@ struct
local
fun loop (x, y, ex, ey, grid) =
if x > 0 then
if quadHasSameColour (x, y, ex, ey, grid) then
loop (x - 1, y, x, ey, grid)
else
ex
else
if x < 0 then
0
else if quadHasSameColour (x, y, ex, ey, grid) then
loop (x - 1, y, x, ey, grid)
else
ex
in
fun getLeftmostX ({x, y, ex, ey, data}, grid) =
loop (x - 1, y, x, ey, grid)
@@ -348,7 +347,7 @@ struct
local
fun loop (x, y, ex, ey, grid) =
if y = 0 orelse ey = 0 then
if y < 0 then
0
else if quadHasSameColour (x, y, ex, ey, grid) then
loop (x, y - 1, ex, y, grid)
@@ -356,7 +355,7 @@ struct
ey
in
fun getTopmostY ({x, y, ex, ey, data}, grid) =
if y <= 0 orelse ey <= 0 then
if y < 0 orelse ey <= 0 then
0
else if quadHasSameColour (x, y, ex, ey, grid) then
loop (x, y - 1, ex, y, grid)
@@ -465,13 +464,14 @@ struct
end
fun merge (tree, grid) =
let val tree = mergeVertical (tree, grid)
in toBintree tree
let
val tree = mergeVertical (tree, grid)
val tree = mergeHorizontal (tree, grid)
in
toBintree tree
end
(* temporarily shadow previous "toTriangles" function.
* When this is done being implemented, rename to "toTrianglesCompressed" *)
fun toTriangles
fun toTrianglesMerged
( windowWidth
, windowHeight
, squares
@@ -483,17 +483,8 @@ struct
) =
let
val qtree = buildTree (0, 0, size, squares)
val bintree = toBintree qtree
val bintree = merge (qtree, squares)
val list = BinTree.toList bintree
val length = List.length list
val _ = print ("length = " ^ Int.toString length ^ "\n")
val _ = print "start fold\n"
val _ = List.foldl (fn (item, _) => printItem item) () list
val _ = print "finish fold\n"
val f = folder
( windowWidth
, windowHeight