diff --git a/dot-to-dot b/dot-to-dot index 1eb5173..3571135 100755 Binary files a/dot-to-dot and b/dot-to-dot differ diff --git a/functional-core/app-type.sml b/functional-core/app-type.sml index 0a6c5da..27a96e7 100644 --- a/functional-core/app-type.sml +++ b/functional-core/app-type.sml @@ -1,8 +1,8 @@ signature APP_TYPE = sig datatype triangle_stage = - FIRST of {x1: Real32.real, y1: Real32.real} - | NO_TRIANGLE + NO_TRIANGLE + | FIRST of {x1: Real32.real, y1: Real32.real} | SECOND of {x1: Real32.real, x2: Real32.real, y1: Real32.real, y2: Real32.real} diff --git a/functional-core/app-update.sml b/functional-core/app-update.sml index 5043b45..781d6b5 100644 --- a/functional-core/app-update.sml +++ b/functional-core/app-update.sml @@ -17,6 +17,16 @@ struct end end + fun ltrbToVertex (left, top, right, bottom, r, g, b) = + #[ left, bottom, r, g, b + , right, bottom, r, g, b + , left, top, r, g, b + + , left, top, r, g, b + , right, bottom, r, g, b + , right, top, r, g, b + ] + local fun genClickPoints (windowWidth, windowHeight) = let @@ -50,15 +60,7 @@ struct val bottom = (vpos - 5.0) / halfHeight val top = (vpos + 5.0) / halfHeight - val drawVec = - #[ left, bottom, r, g, b - , right, bottom, r, g, b - , left, top, r, g, b - - , left, top, r, g, b - , right, bottom, r, g, b - , right, top, r, g, b - ] + val drawVec = ltrbToVertex (left, top, right, bottom, r, g, b) val hpos = hpos / halfWidth val vpos = vpos / halfHeight @@ -91,6 +93,54 @@ 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} => + let + val halfWidth = Real32.fromInt (Constants.windowWidth div 2) + val halfHeight = Real32.fromInt (Constants.windowHeight div 2) + + val x1px = x1 * halfWidth + val left = (x1px - 5.0) / halfWidth + val right = (x1px + 5.0) / halfWidth + + val y1px = y1 * halfHeight + val top = (y1px + 5.0) / halfHeight + val bottom = (y1px - 5.0) / halfHeight + + val firstVec = ltrbToVertex (left, top, right, bottom, 0.0, 0.0, 1.0) + in + Vector.concat [firstVec, drawVec] + end + | SECOND {x1, y1, x2, y2} => + let + val halfWidth = Real32.fromInt (Constants.windowWidth div 2) + val halfHeight = Real32.fromInt (Constants.windowHeight div 2) + + val x1px = x1 * halfWidth + val left = (x1px - 5.0) / halfWidth + val right = (x1px + 5.0) / halfWidth + + val y1px = y1 * halfHeight + val top = (y1px + 5.0) / halfHeight + val bottom = (y1px - 5.0) / halfHeight + + val firstVec = ltrbToVertex (left, top, right, bottom, 0.0, 0.0, 1.0) + + val x2px = x2 * halfWidth + val left = (x2px - 5.0) / halfWidth + val right = (x2px + 5.0) / halfWidth + + val y2px = y2 * halfHeight + val top = (y2px + 5.0) / halfHeight + val bottom = (y2px - 5.0) / halfHeight + + val secVec = ltrbToVertex (left, top, right, bottom, 0.0, 0.0, 1.0) + in + Vector.concat [firstVec, secVec, drawVec] + end + fun update (model, mouseX, mouseY, inputMsg) = let open DrawMessage