progress with merging vertically
This commit is contained in:
@@ -153,6 +153,8 @@ struct
|
|||||||
let
|
let
|
||||||
val ex = x + size
|
val ex = x + size
|
||||||
val ey = y + size
|
val ey = y + size
|
||||||
|
val ex = Int.min (ex, Vector.length grid - 1)
|
||||||
|
val ey = Int.min (ey, Vector.length grid - 1)
|
||||||
val item = {x = x, y = y, ex = ex, ey = ey, data = data}
|
val item = {x = x, y = y, ex = ex, ey = ey, data = data}
|
||||||
in
|
in
|
||||||
BinTree.insert (item, bintree)
|
BinTree.insert (item, bintree)
|
||||||
@@ -204,8 +206,8 @@ struct
|
|||||||
, yClickPoints
|
, yClickPoints
|
||||||
) ({x, ex, y, ey, data}, acc) =
|
) ({x, ex, y, ey, data}, acc) =
|
||||||
let
|
let
|
||||||
val ex = if ex = x then x + 1 else ex
|
val ex = if ex = x then x + 1 else ex + 1
|
||||||
val ey = if ey = y then y + 1 else ey
|
val ey = if ey = y then y + 1 else ey + 1
|
||||||
|
|
||||||
val x = getClickPoint (xClickPoints, x)
|
val x = getClickPoint (xClickPoints, x)
|
||||||
val y = getClickPoint (yClickPoints, y)
|
val y = getClickPoint (yClickPoints, y)
|
||||||
@@ -281,7 +283,9 @@ struct
|
|||||||
else
|
else
|
||||||
let
|
let
|
||||||
val ex = x + size
|
val ex = x + size
|
||||||
|
val ex = Int.min (ex, Vector.length grid - 1)
|
||||||
val ey = y + size
|
val ey = y + size
|
||||||
|
val ey = Int.min (ey, Vector.length grid - 1)
|
||||||
in
|
in
|
||||||
LEAF {x = x, y = y, ex = ex, ey = ey, data = data}
|
LEAF {x = x, y = y, ex = ex, ey = ey, data = data}
|
||||||
end
|
end
|
||||||
@@ -344,7 +348,9 @@ struct
|
|||||||
|
|
||||||
local
|
local
|
||||||
fun loop (x, y, ex, ey, grid) =
|
fun loop (x, y, ex, ey, grid) =
|
||||||
if y < 0 then
|
if y = 0 then
|
||||||
|
1
|
||||||
|
else if ey <= 0 then
|
||||||
0
|
0
|
||||||
else if quadHasSameColour (x, y, ex, ey, grid) then
|
else if quadHasSameColour (x, y, ex, ey, grid) then
|
||||||
loop (x, y - 1, ex, y, grid)
|
loop (x, y - 1, ex, y, grid)
|
||||||
@@ -352,7 +358,12 @@ struct
|
|||||||
ey
|
ey
|
||||||
in
|
in
|
||||||
fun getTopmostY ({x, y, ex, ey, data}, grid) =
|
fun getTopmostY ({x, y, ex, ey, data}, grid) =
|
||||||
loop (x, y - 1, ex, y, grid)
|
if y <= 0 orelse ey <= 0 then
|
||||||
|
0
|
||||||
|
else if quadHasSameColour (x, y, ex, ey, grid) then
|
||||||
|
loop (x, y - 1, ex, y, grid)
|
||||||
|
else
|
||||||
|
y
|
||||||
end
|
end
|
||||||
|
|
||||||
local
|
local
|
||||||
@@ -363,12 +374,30 @@ struct
|
|||||||
else
|
else
|
||||||
y
|
y
|
||||||
else
|
else
|
||||||
Vector.length grid - 1
|
Vector.length grid
|
||||||
in
|
in
|
||||||
fun getBottomY ({x, y, ex, ey, data}, grid) =
|
fun getBottomY ({x, y, ex, ey, data}, grid) =
|
||||||
loop (x, ey, ex, ey + 1, grid)
|
if quadHasSameColour (x, y, ex, ey, grid) then loop (x, y, ex, ey, grid)
|
||||||
|
else y
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun printItem {x, y, ex, ey, data} =
|
||||||
|
let
|
||||||
|
val msg = String.concat
|
||||||
|
[ "{x = "
|
||||||
|
, Int.toString x
|
||||||
|
, ", y = "
|
||||||
|
, Int.toString y
|
||||||
|
, ", ex = "
|
||||||
|
, Int.toString ex
|
||||||
|
, ", ey = "
|
||||||
|
, Int.toString ey
|
||||||
|
, "}\n"
|
||||||
|
]
|
||||||
|
in
|
||||||
|
print msg
|
||||||
|
end
|
||||||
|
|
||||||
local
|
local
|
||||||
fun loop (tree, grid) =
|
fun loop (tree, grid) =
|
||||||
case tree of
|
case tree of
|
||||||
@@ -394,7 +423,7 @@ struct
|
|||||||
didTlChange orelse didTrChange orelse didBlChange
|
didTlChange orelse didTrChange orelse didBlChange
|
||||||
orelse didBrChange
|
orelse didBrChange
|
||||||
in
|
in
|
||||||
(node, didChange)
|
(node, false)
|
||||||
end
|
end
|
||||||
in
|
in
|
||||||
fun mergeVertical (tree, grid) =
|
fun mergeVertical (tree, grid) =
|
||||||
@@ -438,10 +467,41 @@ struct
|
|||||||
end
|
end
|
||||||
|
|
||||||
fun merge (tree, grid) =
|
fun merge (tree, grid) =
|
||||||
|
let val tree = mergeVertical (tree, grid)
|
||||||
|
in toBintree tree
|
||||||
|
end
|
||||||
|
|
||||||
|
(* temporarily shadow previous "toTriangles" function.
|
||||||
|
* When this is done being implemented, rename to "toTrianglesCompressed" *)
|
||||||
|
fun toTriangles
|
||||||
|
( windowWidth
|
||||||
|
, windowHeight
|
||||||
|
, squares
|
||||||
|
, size
|
||||||
|
, canvasWidth
|
||||||
|
, canvasHeight
|
||||||
|
, xClickPoints
|
||||||
|
, yClickPoints
|
||||||
|
) =
|
||||||
let
|
let
|
||||||
val tree = mergeVertical (tree, grid)
|
val qtree = buildTree (0, 0, size, squares)
|
||||||
val tree = mergeHorizontal (tree, grid)
|
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 f = folder
|
||||||
|
( windowWidth
|
||||||
|
, windowHeight
|
||||||
|
, canvasWidth
|
||||||
|
, canvasHeight
|
||||||
|
, xClickPoints
|
||||||
|
, yClickPoints
|
||||||
|
)
|
||||||
|
val vec = BinTree.foldr (f, bintree, [])
|
||||||
in
|
in
|
||||||
BinTree.toList tree
|
Vector.concat vec
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user