add function to quad tree to turn items into strings (for later saving to file)
This commit is contained in:
@@ -28,7 +28,7 @@ fcore/browse-mode.sml
|
|||||||
fcore/app-update.sml
|
fcore/app-update.sml
|
||||||
|
|
||||||
(* pure file parsing functions *)
|
(* pure file parsing functions *)
|
||||||
fcore/parse-file.sml
|
fcore/parser/parser.mlb
|
||||||
|
|
||||||
(* IMPERATIVE SHELL *)
|
(* IMPERATIVE SHELL *)
|
||||||
$(SML_LIB)/basis/mlton.mlb
|
$(SML_LIB)/basis/mlton.mlb
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
structure ParseFile =
|
|
||||||
struct
|
|
||||||
(* unimplemented *)
|
|
||||||
fun parseLine line = NONE
|
|
||||||
end
|
|
||||||
@@ -3,24 +3,23 @@ struct
|
|||||||
fun make (canvasWidth, canvasHeight) =
|
fun make (canvasWidth, canvasHeight) =
|
||||||
let
|
let
|
||||||
val maxPoints = Int.max (canvasWidth, canvasHeight)
|
val maxPoints = Int.max (canvasWidth, canvasHeight)
|
||||||
val emptyYAxis = Vector.tabulate (maxPoints, fn _ =>
|
val emptyYAxis = Vector.tabulate (maxPoints, fn _ => {r = 0, g = 0, b = 0, a = 0})
|
||||||
{r = 0, g = 0, b = 0, a = 0})
|
|
||||||
in
|
in
|
||||||
Vector.tabulate (maxPoints, fn _ => emptyYAxis)
|
Vector.tabulate (maxPoints, fn _ => emptyYAxis)
|
||||||
end
|
end
|
||||||
|
|
||||||
local
|
local
|
||||||
fun loopY (yAxis, x, ex, y, ey, colour) =
|
fun loopY (yAxis, x, ex, y, ey, colour) =
|
||||||
if y > ey then
|
if y > ey then yAxis
|
||||||
yAxis
|
|
||||||
else
|
else
|
||||||
let val yAxis = Vector.update (yAxis, y, colour)
|
let
|
||||||
in loopY (yAxis, x, ex, y + 1, ey, colour)
|
val yAxis = Vector.update (yAxis, y, colour)
|
||||||
|
in
|
||||||
|
loopY (yAxis, x, ex, y + 1, ey, colour)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun loopX (grid, x, ex, y, ey, colour) =
|
fun loopX (grid, x, ex, y, ey, colour) =
|
||||||
if x > ex then
|
if x > ex then grid
|
||||||
grid
|
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val yAxis = Vector.sub (grid, x)
|
val yAxis = Vector.sub (grid, x)
|
||||||
7
fcore/parser/tokens.sml
Normal file
7
fcore/parser/tokens.sml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
structure Tokens =
|
||||||
|
struct
|
||||||
|
datatype t =
|
||||||
|
L_BRACE
|
||||||
|
| R_BRACE
|
||||||
|
| INT of int
|
||||||
|
end
|
||||||
@@ -1 +0,0 @@
|
|||||||
structure Tokens = struct datatype t = L_BRACE | R_BRACE | INT of int end
|
|
||||||
@@ -500,4 +500,39 @@ struct
|
|||||||
in
|
in
|
||||||
Vector.concat vec
|
Vector.concat vec
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun toStringFolder ({x, ex, y, ey, data = {r, g, b, a}}, acc) =
|
||||||
|
let
|
||||||
|
val item = String.concat
|
||||||
|
[ "{"
|
||||||
|
, Int.toString x
|
||||||
|
, " "
|
||||||
|
, Int.toString y
|
||||||
|
, " "
|
||||||
|
, Int.toString ex
|
||||||
|
, " "
|
||||||
|
, Int.toString ey
|
||||||
|
, " "
|
||||||
|
, Int.toString r
|
||||||
|
, " "
|
||||||
|
, Int.toString g
|
||||||
|
, " "
|
||||||
|
, Int.toString b
|
||||||
|
, " "
|
||||||
|
, Int.toString a
|
||||||
|
, " }"
|
||||||
|
]
|
||||||
|
in
|
||||||
|
item :: acc
|
||||||
|
end
|
||||||
|
|
||||||
|
fun toString (squares, size) =
|
||||||
|
let
|
||||||
|
val qtree = buildTree (0, 0, size, squares)
|
||||||
|
val bintree = merge (qtree, squares)
|
||||||
|
|
||||||
|
val vec = BinTree.foldr (toStringFolder, bintree, [])
|
||||||
|
in
|
||||||
|
Vector.concat vec
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user