From 4a87b0f16e7b90f0d77ad4439e9473aee1728d47 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sun, 6 Jul 2025 13:52:38 +0100 Subject: [PATCH] port 'addCoordinates' function to app-update.sml --- temp-squares/fcore/app-update.sml | 33 +++++++++++++++++++++++++++++++ temp-squares/fcore/quad-tree.sml | 12 ++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/temp-squares/fcore/app-update.sml b/temp-squares/fcore/app-update.sml index 9d1f241..51cf756 100644 --- a/temp-squares/fcore/app-update.sml +++ b/temp-squares/fcore/app-update.sml @@ -139,4 +139,37 @@ struct else getDrawDotMsgWhenArrowIsAtBoundary model end + + fun realToInt x = Real32.toInt IEEEReal.TO_NEAREST x + + fun addCoordinates (model: app_type, hIdx, vIdx) = + let + val + { windowWidth + , windowHeight + , xClickPoints + , yClickPoints + , canvasWidth + , canvasHeight + , ... + } = model + + val xpos = Vector.sub (xClickPoints, hIdx) + val ypos = Vector.sub (yClickPoints, vIdx) + + val model = AppWith.addSquare (model, realToInt xpos, realToInt ypos, hIdx, vIdx) + val squares = #squares model + + val dotVec = getDotVecFromIndices (model, hIdx, vIdx) + + val halfWidth = Real32.fromInt (windowWidth div 2) + val halfHeight = Real32.fromInt (windowHeight div 2) + + val maxSide = Int.max (canvasWidth, canvasHeight) + val squares = + CollisionTree.toTriangles (windowWidth, windowHeight, squares, maxSide) + val drawMsg = DRAW_SQUARES_AND_DOTS {squares = squares, dots = dotVec} + in + (model, drawMsg) + end end diff --git a/temp-squares/fcore/quad-tree.sml b/temp-squares/fcore/quad-tree.sml index 2e90ae9..b44b1db 100644 --- a/temp-squares/fcore/quad-tree.sml +++ b/temp-squares/fcore/quad-tree.sml @@ -245,6 +245,11 @@ struct case squares of {x, y, ex, ey, data = _} :: tl => let + val x = Real32.fromInt x + val y = Real32.fromInt y + val ex = Real32.fromInt ex + val ey = Real32.fromInt ey + val startX = Ndc.fromPixelX (x, windowWidth, windowHeight) val endX = Ndc.fromPixelX (ex, windowWidth, windowHeight) val startY = Ndc.fromPixelY (y, windowWidth, windowHeight) @@ -256,7 +261,12 @@ struct end | [] => Vector.concat acc in - fun toTriangles (windowWidth, windowHeight, squares) = + fun toTriangles (windowWidth, windowHeight, squares, size) = + let + val qtree = build (0, 0, size, squares) + val squares = toList qtree + in loop (windowWidth, windowHeight, squares, []) + end end end