remove 'squares' field from app type, and refactor most functions in common-update.sml to use layer tree instead of squares vector

This commit is contained in:
2025-08-09 10:19:26 +01:00
parent ab888f8410
commit d3ace298d3
6 changed files with 21 additions and 133 deletions

BIN
dotscape

Binary file not shown.

View File

@@ -23,12 +23,9 @@ struct
(windowWidth, windowHeight, canvasWidth, canvasHeight)
val maxPoints = Int.max (canvasWidth, canvasHeight)
val squares = Vector.tabulate (maxPoints, fn _ =>
Vector.tabulate (maxPoints, fn _ => {r = 0, g = 0, b = 0, a = 0}))
val layerTree = LayerTree.init maxPoints
in
{ mode = AppType.NORMAL_MODE
, squares = squares
, canvasWidth = canvasWidth
, canvasHeight = canvasHeight
, windowWidth = windowWidth

View File

@@ -8,7 +8,6 @@ struct
type app_type =
{ mode: app_mode
, squares: square vector vector
, canvasWidth: int
, canvasHeight: int
, windowWidth: int

View File

@@ -2,28 +2,10 @@ structure AppWith =
struct
open AppType
fun changeSquaresSize (squares, newCanvasWidth, newCanvasHeight) =
let
val maxPoints = Int.max (newCanvasWidth, newCanvasHeight)
in
Vector.tabulate (maxPoints, fn i =>
if i < Vector.length squares then
let
val yAxis = Vector.sub (squares, i)
in
Vector.tabulate (maxPoints, fn ii =>
if ii < Vector.length yAxis then Vector.sub (yAxis, ii)
else {r = 0, g = 0, b = 0, a = 0})
end
else
Vector.tabulate (maxPoints, fn _ => {r = 0, g = 0, b = 0, a = 0}))
end
fun arrowX (app, arrowX) =
let
val
{ mode
, squares
, arrowX = _
, arrowY
, canvasWidth
@@ -49,7 +31,6 @@ struct
} = app
in
{ mode = mode
, squares = squares
, arrowX = arrowX
, arrowY = arrowY
, canvasWidth = canvasWidth
@@ -79,7 +60,6 @@ struct
let
val
{ mode
, squares
, arrowX
, arrowY = _
, canvasWidth
@@ -105,7 +85,6 @@ struct
} = app
in
{ mode = mode
, squares = squares
, arrowX = arrowX
, arrowY = arrowY
, canvasWidth = canvasWidth
@@ -139,7 +118,6 @@ struct
, yClickPoints = _
, windowWidth = _
, windowHeight = _
, squares
, arrowX
, arrowY
, canvasWidth
@@ -165,7 +143,6 @@ struct
(windowWidth, windowHeight, canvasWidth, canvasHeight)
in
{ mode = mode
, squares = squares
, arrowX = arrowX
, arrowY = arrowY
, canvasWidth = canvasWidth
@@ -201,7 +178,6 @@ struct
, yClickPoints
, windowWidth
, windowHeight
, squares
, arrowX
, arrowY
, canvasWidth
@@ -223,7 +199,6 @@ struct
{ mode = mode
, mouseX = mouseX
, mouseY = mouseY
, squares = squares
, arrowX = arrowX
, arrowY = arrowY
, canvasWidth = canvasWidth
@@ -257,7 +232,6 @@ struct
, yClickPoints
, windowWidth
, windowHeight
, squares
, arrowX
, arrowY
, canvasWidth
@@ -279,7 +253,6 @@ struct
{ mode = mode
, mouseX = mouseX
, mouseY = mouseY
, squares = squares
, arrowX = arrowX
, arrowY = arrowY
, canvasWidth = canvasWidth
@@ -313,7 +286,6 @@ struct
, yClickPoints
, windowWidth
, windowHeight
, squares
, arrowX
, arrowY
, canvasWidth
@@ -335,7 +307,6 @@ struct
{ mode = newMode
, mouseX = mouseX
, mouseY = mouseY
, squares = squares
, arrowX = arrowX
, arrowY = arrowY
, canvasWidth = canvasWidth
@@ -369,7 +340,6 @@ struct
, yClickPoints
, windowWidth
, windowHeight
, squares
, arrowX
, arrowY
, canvasWidth
@@ -391,7 +361,6 @@ struct
{ mode = mode
, mouseX = mouseX
, mouseY = mouseY
, squares = squares
, arrowX = arrowX
, arrowY = arrowY
, canvasWidth = canvasWidth
@@ -425,7 +394,6 @@ struct
, yClickPoints
, windowWidth
, windowHeight
, squares
, arrowX
, arrowY
, canvasWidth
@@ -447,7 +415,6 @@ struct
{ mode = mode
, mouseX = mouseX
, mouseY = mouseY
, squares = squares
, arrowX = arrowX
, arrowY = arrowY
, canvasWidth = canvasWidth
@@ -481,7 +448,6 @@ struct
, yClickPoints
, windowWidth
, windowHeight
, squares
, arrowX
, arrowY
, canvasWidth
@@ -505,7 +471,6 @@ struct
{ mode = mode
, mouseX = mouseX
, mouseY = mouseY
, squares = squares
, arrowX = arrowX
, arrowY = arrowY
, canvasWidth = canvasWidth
@@ -539,7 +504,6 @@ struct
, yClickPoints
, windowWidth
, windowHeight
, squares
, arrowX
, arrowY
, canvasWidth
@@ -563,7 +527,6 @@ struct
{ mode = mode
, mouseX = mouseX
, mouseY = mouseY
, squares = squares
, arrowX = arrowX
, arrowY = arrowY
, canvasWidth = canvasWidth
@@ -597,7 +560,6 @@ struct
, yClickPoints
, windowWidth
, windowHeight
, squares
, arrowX
, arrowY
, canvasWidth
@@ -621,7 +583,6 @@ struct
{ mode = mode
, mouseX = mouseX
, mouseY = mouseY
, squares = squares
, arrowX = arrowX
, arrowY = arrowY
, canvasWidth = canvasWidth
@@ -655,7 +616,6 @@ struct
, yClickPoints
, windowWidth
, windowHeight
, squares
, arrowX
, arrowY
, canvasWidth
@@ -679,7 +639,6 @@ struct
{ mode = mode
, mouseX = mouseX
, mouseY = mouseY
, squares = squares
, arrowX = arrowX
, arrowY = arrowY
, canvasWidth = canvasWidth
@@ -713,7 +672,6 @@ struct
, yClickPoints
, windowWidth
, windowHeight
, squares
, arrowX
, arrowY
, canvasWidth
@@ -737,7 +695,6 @@ struct
{ mode = mode
, mouseX = mouseX
, mouseY = mouseY
, squares = squares
, arrowX = arrowX
, arrowY = arrowY
, canvasWidth = canvasWidth
@@ -771,7 +728,6 @@ struct
, yClickPoints
, windowWidth
, windowHeight
, squares
, arrowX
, arrowY
, canvasWidth
@@ -795,7 +751,6 @@ struct
{ mode = mode
, mouseX = mouseX
, mouseY = mouseY
, squares = squares
, arrowX = arrowX
, arrowY = arrowY
, canvasWidth = canvasWidth
@@ -829,7 +784,6 @@ struct
, yClickPoints
, windowWidth
, windowHeight
, squares
, arrowX = _
, arrowY = _
, canvasWidth
@@ -851,7 +805,6 @@ struct
{ mode = mode
, mouseX = mouseX
, mouseY = mouseY
, squares = squares
, arrowX = arrowX
, arrowY = arrowY
, canvasWidth = canvasWidth
@@ -880,7 +833,6 @@ struct
val
{ mode
, canvasWidth = _
, squares
, arrowX
, arrowY
, canvasHeight
@@ -914,7 +866,6 @@ struct
, arrowX = arrowX
, mouseX = mouseX
, mouseY = mouseY
, squares = squares
, arrowY = arrowY
, canvasHeight = canvasHeight
, windowWidth = windowWidth
@@ -942,7 +893,6 @@ struct
{ mode
, canvasHeight = _
, canvasWidth
, squares
, arrowX
, arrowY
, windowWidth
@@ -976,7 +926,6 @@ struct
, arrowX = arrowX
, mouseX = mouseX
, mouseY = mouseY
, squares = squares
, arrowY = arrowY
, windowWidth = windowWidth
, windowHeight = windowHeight
@@ -997,75 +946,12 @@ struct
}
end
fun useSquares (app: app_type, squares, canvasWidth, canvasHeight) =
let
val
{ mode
, canvasHeight = _
, canvasWidth = _
, squares = _
, arrowX
, arrowY
, windowWidth
, windowHeight
, xClickPoints
, yClickPoints
, showGraph
, mouseX
, mouseY
, openFilePath
, fileBrowser
, fileBrowserIdx
, r
, g
, b
, a
, layer
, layerTree
, modalNum
} = app
val arrowX = Int.min (arrowX, canvasWidth)
val arrowY = Int.min (arrowY, canvasHeight)
val (xClickPoints, yClickPoints) =
ClickPoints.generate
(windowWidth, windowHeight, canvasWidth, canvasHeight)
in
{ mode = mode
, canvasHeight = canvasHeight
, canvasWidth = canvasWidth
, arrowX = arrowX
, mouseX = mouseX
, mouseY = mouseY
, squares = squares
, arrowY = arrowY
, windowWidth = windowWidth
, windowHeight = windowHeight
, xClickPoints = xClickPoints
, yClickPoints = yClickPoints
, showGraph = showGraph
, openFilePath = openFilePath
, fileBrowser = fileBrowser
, fileBrowserIdx = fileBrowserIdx
, r = r
, g = g
, b = b
, a = a
, layer = layer
, layerTree = layerTree
, modalNum = 0
}
end
fun cursorColour (app, r, g, b, a) =
let
val
{ mode
, canvasHeight
, canvasWidth
, squares
, arrowX
, arrowY
, windowWidth
@@ -1094,7 +980,6 @@ struct
, arrowX = arrowX
, mouseX = mouseX
, mouseY = mouseY
, squares = squares
, arrowY = arrowY
, windowWidth = windowWidth
, windowHeight = windowHeight

View File

@@ -10,17 +10,19 @@ struct
fun resizeWindow (model, width, height, dots) =
let
val
{ squares
, canvasWidth
{ canvasWidth
, canvasHeight
, showGraph
, arrowX
, arrowY
, xClickPoints
, yClickPoints
, layerTree
, ...
} = model
val maxSide = Int.max (canvasWidth, canvasHeight)
val squares = LayerTree.flatten (maxSide, layerTree)
val squares = CollisionTree.toTriangles
( width
@@ -46,11 +48,12 @@ struct
fun getSaveSquaresMsg (model: app_type) =
let
(* todo: reimplement, saving each layer to a different line
val {canvasWidth, canvasHeight, squares, ...} = model
val str = CollisionTree.toSaveString (squares, canvasWidth, canvasHeight)
val msg = SAVE_SQUARES str
in
(model, [FILE msg])
*)
in raise Fail "todo common-update.sml: reimplement saving"
end
fun getLoadSquaresMsg model =
@@ -58,7 +61,11 @@ struct
fun getExportSquaresMsg (model: app_type) =
let
val {squares, canvasWidth, canvasHeight, ...} = model
val {layerTree, canvasWidth, canvasHeight, ...} = model
val maxSide = Int.max (canvasWidth, canvasHeight)
val squares = LayerTree.flatten (maxSide, layerTree)
val exportString =
CollisionTree.toExportString (squares, canvasWidth, canvasHeight)
val msg = EXPORT_SQUARES exportString
@@ -68,7 +75,11 @@ struct
fun getCollisionMsg (model: app_type) =
let
val {squares, canvasWidth, canvasHeight, modalNum, ...} = model
val {layerTree, canvasWidth, canvasHeight, modalNum, ...} = model
val maxSide = Int.max (canvasWidth, canvasHeight)
val squares = LayerTree.flatten (maxSide, layerTree)
val exportString =
CollisionTree.toCollisionString
(squares, canvasWidth, canvasHeight, modalNum)

View File

@@ -333,11 +333,7 @@ struct
end
fun useSquares (model, squares, canvasWidth, canvasHeight) =
let
val model = AppWith.useSquares (model, squares, canvasWidth, canvasHeight)
in
updateCanvas (model, canvasWidth, canvasHeight)
end
raise Fail "todo: reimplement"
fun enterBrowseMode model =
let