port 'addCoordinates' function to app-update.sml
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user