diff --git a/dotscape b/dotscape index 713f42d..d53c824 100755 Binary files a/dotscape and b/dotscape differ diff --git a/dotscape.mlb b/dotscape.mlb index 72e621b..c95736a 100644 --- a/dotscape.mlb +++ b/dotscape.mlb @@ -1,6 +1,7 @@ $(SML_LIB)/basis/basis.mlb (* FUNCTIONAL CORE *) +fcore/grid.sml fcore/layer-tree.sml fcore/app-type.sml diff --git a/fcore/grid.sml b/fcore/grid.sml new file mode 100644 index 0000000..bee7ede --- /dev/null +++ b/fcore/grid.sml @@ -0,0 +1,23 @@ +structure Grid = +struct + type square = {r: int, g: int, b: int, a: int} + + type t = square vector vector + + val emptyPixel = {r = 0, g = 0, b = 0, a = 0} + + fun isBlank ({a, ...}: square) = a = 0 + + fun changeGridSize maxSide grid = + Vector.tabulate (maxSide, fn i => + if i < Vector.length grid then + let + val yAxis = Vector.sub (grid, i) + in + Vector.tabulate (maxSide, fn ii => + if ii < Vector.length yAxis then Vector.sub (yAxis, ii) + else emptyPixel) + end + else + Vector.tabulate (maxSide, fn _ => emptyPixel)) +end diff --git a/fcore/layer-tree.sml b/fcore/layer-tree.sml index 0506e45..f03103e 100644 --- a/fcore/layer-tree.sml +++ b/fcore/layer-tree.sml @@ -1,19 +1,11 @@ structure LayerTree = struct - type square = {r: int, g: int, b: int, a: int} - - type grid = square vector vector - datatype tree = - NODE of {key: int, value: grid, left: tree, right: tree} + NODE of {key: int, value: Grid.t, left: tree, right: tree} | LEAF - val emptyPixel = {r = 0, g = 0, b = 0, a = 0} - val emptyTree = LEAF - fun isBlank ({a, ...}: square) = a = 0 - fun insert (newKey, newValue, tree) = case tree of LEAF => NODE {key = newKey, value = newValue, left = LEAF, right = LEAF} @@ -66,7 +58,7 @@ struct (fn (xIdx, valueYAxis) => Vector.mapi (fn (yIdx, valuePixel) => - if isBlank valuePixel then + if Grid.isBlank valuePixel then let val accYAxis = Vector.sub (acc, xIdx) in Vector.sub (accYAxis, yIdx) end @@ -75,26 +67,13 @@ struct fun makeEmptyGrid maxSide = Vector.tabulate (maxSide, fn _ => - Vector.tabulate (maxSide, fn _ => emptyPixel)) + Vector.tabulate (maxSide, fn _ => Grid.emptyPixel)) fun flatten (maxSide, tree) = foldl (helpFlatten, tree, makeEmptyGrid maxSide) - fun helpChangeGridSize maxSide squares = - Vector.tabulate (maxSide, fn i => - if i < Vector.length squares then - let - val yAxis = Vector.sub (squares, i) - in - Vector.tabulate (maxSide, fn ii => - if ii < Vector.length yAxis then Vector.sub (yAxis, ii) - else emptyPixel) - end - else - Vector.tabulate (maxSide, fn _ => emptyPixel)) - fun changeGridSize (maxSide, tree) = - let val f = helpChangeGridSize maxSide + let val f = Grid.changeGridSize maxSide in map (f, tree) end end