progress moving away from 'squares' field to layer tree

This commit is contained in:
2025-08-09 09:32:34 +01:00
parent 34c29bcbba
commit 58439d8df8
5 changed files with 92 additions and 16 deletions

BIN
dotscape

Binary file not shown.

View File

@@ -25,6 +25,7 @@ struct
val maxPoints = Int.max (canvasWidth, canvasHeight) val maxPoints = Int.max (canvasWidth, canvasHeight)
val squares = Vector.tabulate (maxPoints, fn _ => val squares = Vector.tabulate (maxPoints, fn _ =>
Vector.tabulate (maxPoints, fn _ => {r = 0, g = 0, b = 0, a = 0})) Vector.tabulate (maxPoints, fn _ => {r = 0, g = 0, b = 0, a = 0}))
val layerTree = LayerTree.init maxPoints
in in
{ mode = AppType.NORMAL_MODE { mode = AppType.NORMAL_MODE
, squares = squares , squares = squares
@@ -48,7 +49,7 @@ struct
, b = 0 , b = 0
, a = 1 , a = 1
, layer = 0 , layer = 0
, layerTree = LayerTree.empty , layerTree = layerTree
, modalNum = 0 , modalNum = 0
, undo = [] , undo = []
, redo = [] , redo = []

View File

@@ -1069,6 +1069,66 @@ struct
} }
end end
fun layerTree (app: app_type, layerTree, arrowX, arrowY) : app_type =
let
val
{ mode
, mouseX
, mouseY
, xClickPoints
, yClickPoints
, windowWidth
, windowHeight
, squares
, arrowX = _
, arrowY = _
, canvasWidth
, canvasHeight
, showGraph
, openFilePath
, fileBrowser
, fileBrowserIdx
, r
, g
, b
, a
, layer
, layerTree = _
, modalNum
, undo
, redo
} = app
in
{ mode = mode
, mouseX = mouseX
, mouseY = mouseY
, squares = squares
, arrowX = arrowX
, arrowY = arrowY
, canvasWidth = canvasWidth
, canvasHeight = canvasHeight
, 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 = modalNum
, undo = undo
, redo = redo
}
end
fun canvasWidth (app: app_type, newCanvasWidth) = fun canvasWidth (app: app_type, newCanvasWidth) =
let let
val val

View File

@@ -2,7 +2,10 @@ structure LayerTree =
struct struct
datatype t = NODE of {key: int, value: Grid.t, left: t, right: t} | LEAF datatype t = NODE of {key: int, value: Grid.t, left: t, right: t} | LEAF
val empty = LEAF fun init maxSide =
let val grid = Grid.makeEmpty maxSide
in NODE {key = 0, value = grid, left = LEAF, right = LEAF}
end
fun insert (newKey, newValue, tree) = fun insert (newKey, newValue, tree) =
case tree of case tree of
@@ -82,7 +85,4 @@ struct
in in
insert (key, grid, tree) insert (key, grid, tree)
end end
fun removePixel (key, newX, newY, maxSide, tree) =
addPixel (key, newX, newY, maxSide, Grid.emptyPixel, tree)
end end

View File

@@ -134,7 +134,7 @@ struct
fun realToInt x = Real32.toInt IEEEReal.TO_NEAREST x fun realToInt x = Real32.toInt IEEEReal.TO_NEAREST x
fun changeSquare (model: app_type, hIdx, vIdx, fModel) = fun changePixel (model: app_type, hIdx, vIdx, pixel) =
let let
val val
{ windowWidth { windowWidth
@@ -143,18 +143,28 @@ struct
, yClickPoints , yClickPoints
, canvasWidth , canvasWidth
, canvasHeight , canvasHeight
, layer
, layerTree
, r
, g
, b
, a
, ... , ...
} = model } = model
val maxSide = Int.max (canvasWidth, canvasHeight)
val xpos = Vector.sub (xClickPoints, hIdx) val xpos = Vector.sub (xClickPoints, hIdx)
val ypos = Vector.sub (yClickPoints, vIdx) val ypos = Vector.sub (yClickPoints, vIdx)
val model = fModel (model, hIdx, vIdx, hIdx, vIdx) val layerTree = LayerTree.addPixel
val squares = #squares model (layer, hIdx, vIdx, maxSide, pixel, layerTree)
val model = AppWith.layerTree (model, layerTree, hIdx, vIdx)
val squares = LayerTree.flatten (maxSide, layerTree)
val dotVec = getDotVecFromIndices (model, hIdx, vIdx) val dotVec = getDotVecFromIndices (model, hIdx, vIdx)
val maxSide = Int.max (canvasWidth, canvasHeight)
val squares = CollisionTree.toTriangles val squares = CollisionTree.toTriangles
( windowWidth ( windowWidth
, windowHeight , windowHeight
@@ -170,22 +180,27 @@ struct
(model, [DRAW drawMsg]) (model, [DRAW drawMsg])
end end
fun addCoordinates (model, hIdx, vIdx) = fun addPixel (model: app_type, hIdx, vIdx) =
changeSquare (model, hIdx, vIdx, AppWith.addSquare) let
val {r, g, b, a, ...} = model
val pixel = {r = r, g = g, b = b, a = a}
in
changePixel (model, hIdx, vIdx, pixel)
end
fun deletePixel (model, hIdx, vIdx) =
changePixel (model, hIdx, vIdx, Grid.emptyPixel)
fun mouseLeftClick model = fun mouseLeftClick model =
case ClickPoints.getClickPositionFromMouse model of case ClickPoints.getClickPositionFromMouse model of
SOME (hIdx, vIdx) => addCoordinates (model, hIdx, vIdx) SOME (hIdx, vIdx) => addPixel (model, hIdx, vIdx)
| NONE => (model, []) | NONE => (model, [])
fun enterOrSpaceCoordinates model = fun enterOrSpaceCoordinates model =
let val {arrowX, arrowY, ...} = model let val {arrowX, arrowY, ...} = model
in addCoordinates (model, arrowX, arrowY) in addPixel (model, arrowX, arrowY)
end end
fun deletePixel (model, hIdx, vIdx) =
changeSquare (model, hIdx, vIdx, AppWith.deleteSquare)
fun backspace model = fun backspace model =
let val {arrowX, arrowY, ...} = model let val {arrowX, arrowY, ...} = model
in deletePixel (model, arrowX, arrowY) in deletePixel (model, arrowX, arrowY)