diff --git a/dotscape b/dotscape index 496043d..f2c5a15 100755 Binary files a/dotscape and b/dotscape differ diff --git a/fcore/layer-tree.sml b/fcore/layer-tree.sml index 79fa68a..e5f97ac 100644 --- a/fcore/layer-tree.sml +++ b/fcore/layer-tree.sml @@ -46,6 +46,17 @@ struct foldl (f, right, acc) end + fun foldr (f, tree, acc) = + case tree of + LEAF => acc + | NODE {value, left, right, ...} => + let + val acc = foldr (f, right, acc) + val acc = f (value, acc) + in + foldr (f, left, acc) + end + fun map (f, tree) = case tree of LEAF => LEAF diff --git a/fcore/parser/parser.md b/fcore/parser/parser.md index 5d879d1..a322fd8 100644 --- a/fcore/parser/parser.md +++ b/fcore/parser/parser.md @@ -16,6 +16,6 @@ layer ::= **[** item **]** layer_tree ::= int int **{** (layer)* **}** ``` -The first two `int`s in the grid `int int **{** (item)+ **}**` always follow the order: `canvasWidth canvasHeight`. +The first two `int`s in the `layer_tree` always follow the order: `canvasWidth canvasHeight`. -The large number of `int`s in the `item` always follows the order: `x y ex ey r g b a`. +The large number of `int`s in the `item` always follow the order: `x y ex ey r g b a`. diff --git a/fcore/quad-tree.sml b/fcore/quad-tree.sml index b330b8b..aaf7aef 100644 --- a/fcore/quad-tree.sml +++ b/fcore/quad-tree.sml @@ -460,7 +460,7 @@ struct fun toSaveStringFolder ({x, ex, y, ey, data = {r, g, b, a}}, acc) = let val item = String.concat - [ "{" + [ "[" , Int.toString x , " " , Int.toString y @@ -476,20 +476,28 @@ struct , Int.toString b , " " , Int.toString a - , " } " + , " ] " ] in item :: acc end - fun toSaveString (squares, canvasWidth, canvasHeight) = + fun toSaveStringTreeFolder size (grid, acc) = + let + val qtree = buildTree (0, 0, size, grid) + val bintree = merge (qtree, grid) + val str = BinTree.foldr (toSaveStringFolder, bintree, []) + in + String.concat str :: acc + end + + fun toSaveString (layerTree, canvasWidth, canvasHeight) = let val size = Int.max (canvasWidth, canvasHeight) - val qtree = buildTree (0, 0, size, squares) - val bintree = merge (qtree, squares) + val f = toSaveStringTreeFolder size val initial = ["}"] - val acc = BinTree.foldr (toSaveStringFolder, bintree, initial) + val acc = LayerTree.foldr (f, layerTree, initial) val acc = String.concat [Int.toString canvasWidth, " ", Int.toString canvasHeight, " { "]