minor optimisation (do not have to branch on NO_TRIANGLE | FIRST | SECOND twice in update function; update function was branching on this itself, and call to 'getTriangleStageVector' was branching again which was redundant)
This commit is contained in:
BIN
dot-to-dot
BIN
dot-to-dot
Binary file not shown.
@@ -93,10 +93,7 @@ struct
|
||||
(0, Real32.fromInt mouseX, Real32.fromInt mouseY, r, g, b)
|
||||
end
|
||||
|
||||
fun getTriangleStageVector (model: app_type, drawVec) =
|
||||
case #triangleStage model of
|
||||
NO_TRIANGLE => drawVec
|
||||
| FIRST {x1, y1} =>
|
||||
fun getFirstTriangleStageVector (x1, y1, drawVec) =
|
||||
let
|
||||
val halfWidth = Real32.fromInt (Constants.windowWidth div 2)
|
||||
val halfHeight = Real32.fromInt (Constants.windowHeight div 2)
|
||||
@@ -113,7 +110,8 @@ struct
|
||||
in
|
||||
Vector.concat [firstVec, drawVec]
|
||||
end
|
||||
| SECOND {x1, y1, x2, y2} =>
|
||||
|
||||
fun getSecondTriangleStageVector (x1, y1, x2, y2, drawVec) =
|
||||
let
|
||||
val halfWidth = Real32.fromInt (Constants.windowWidth div 2)
|
||||
val halfHeight = Real32.fromInt (Constants.windowHeight div 2)
|
||||
@@ -141,6 +139,14 @@ struct
|
||||
Vector.concat [firstVec, secVec, drawVec]
|
||||
end
|
||||
|
||||
fun getTriangleStageVector (model: app_type, drawVec) =
|
||||
case #triangleStage model of
|
||||
NO_TRIANGLE => drawVec
|
||||
| FIRST {x1, y1} =>
|
||||
getFirstTriangleStageVector (x1, y1, drawVec)
|
||||
| SECOND {x1, y1, x2, y2} =>
|
||||
getSecondTriangleStageVector (x1, y1, x2, y2, drawVec)
|
||||
|
||||
fun update (model, mouseX, mouseY, inputMsg) =
|
||||
let
|
||||
open DrawMessage
|
||||
@@ -183,7 +189,7 @@ struct
|
||||
end
|
||||
| FIRST {x1, y1} =>
|
||||
let
|
||||
val drawVec = getTriangleStageVector (model, buttonVec)
|
||||
val drawVec = getFirstTriangleStageVector (x1, y1, buttonVec)
|
||||
val drawMsg = DRAW_BUTTON drawVec
|
||||
|
||||
val newTriangleStage = SECOND
|
||||
@@ -195,7 +201,8 @@ struct
|
||||
end
|
||||
| SECOND {x1, y1, x2, y2} =>
|
||||
let
|
||||
val drawVec = getTriangleStageVector (model, buttonVec)
|
||||
val drawVec =
|
||||
getSecondTriangleStageVector (x1, y1, x2, y2, buttonVec)
|
||||
val drawMsg = DRAW_BUTTON drawVec
|
||||
|
||||
val newTriangleStage = NO_TRIANGLE
|
||||
|
||||
Reference in New Issue
Block a user