address one regression, where triangles were no longer being displayed (because calculation changed) after the previous refactoring. I know of only one more regression, which is that the clicked dots do not persist after moving the mouse.

This commit is contained in:
2024-09-19 17:46:40 +01:00
parent 9153217d5f
commit 6a7f11efe6
3 changed files with 45 additions and 7 deletions

BIN
dotscape

Binary file not shown.

View File

@@ -18,7 +18,7 @@ struct
val drawVec = val drawVec =
case ClickPoints.getClickPositionFromMouse model of case ClickPoints.getClickPositionFromMouse model of
SOME (xpos, ypos) => SOME (xpos, ypos) =>
ClickPoints.getDrawVec (xpos, ypos, 1.0, 0.0, 0.0, model) ClickPoints.getDrawDot (xpos, ypos, 1.0, 0.0, 0.0, model)
| NONE => Vector.fromList [] | NONE => Vector.fromList []
val drawMsg = DRAW_DOT drawVec val drawMsg = DRAW_DOT drawVec
in in
@@ -29,14 +29,16 @@ struct
case ClickPoints.getClickPositionFromMouse model of case ClickPoints.getClickPositionFromMouse model of
SOME (xpos, ypos) => SOME (xpos, ypos) =>
let let
val dotVec = ClickPoints.getDrawVec (xpos, ypos, 0.0, 0.0, 1.0, model) val dotVec = ClickPoints.getDrawDot (xpos, ypos, 0.0, 0.0, 1.0, model)
val {windowWidth, windowHeight, ...} = model val {windowWidth, windowHeight, ...} = model
val halfWidth = Real32.fromInt (windowWidth div 2) val halfWidth = Real32.fromInt (windowWidth div 2)
val halfHeight = Real32.fromInt (windowHeight div 2) val halfHeight = Real32.fromInt (windowHeight div 2)
val hpos = val hpos =
Ndc.centreAlignX (xpos, windowWidth, windowHeight, halfWidth) ClickPoints.xposToNdc (xpos, windowWidth, windowHeight, halfWidth)
val vpos = val vpos =
Ndc.centreAlignY (ypos, windowWidth, windowHeight, halfHeight) ClickPoints.yposToNdc (ypos, windowWidth, windowHeight, halfHeight)
val newUndoTuple = (hpos, vpos) val newUndoTuple = (hpos, vpos)
in in
(case #triangleStage model of (case #triangleStage model of
@@ -70,7 +72,6 @@ struct
let let
val model = AppWith.addTriangle val model = AppWith.addTriangle
(model, x1, y1, x2, y2, hpos, vpos, newUndoTuple) (model, x1, y1, x2, y2, hpos, vpos, newUndoTuple)
val drawVec = Triangles.toVector model val drawVec = Triangles.toVector model
val drawMsg = DRAW_TRIANGLES_AND_RESET_DOTS drawVec val drawMsg = DRAW_TRIANGLES_AND_RESET_DOTS drawVec
in in

View File

@@ -3,7 +3,7 @@ sig
val generate: int * int -> Real32.real vector val generate: int * int -> Real32.real vector
val getClickPositionFromMouse: AppType.app_type val getClickPositionFromMouse: AppType.app_type
-> (Real32.real * Real32.real) option -> (Real32.real * Real32.real) option
val getDrawVec: val getDrawDot:
Real32.real Real32.real
* Real32.real * Real32.real
* Real32.real * Real32.real
@@ -11,6 +11,10 @@ sig
* Real32.real * Real32.real
* AppType.app_type * AppType.app_type
-> Real32.real vector -> Real32.real vector
(* two below functions convert pixel coordinates to normalised device coordinates *)
val xposToNdc: Real32.real * int * int * Real32.real -> Real32.real
val yposToNdc: Real32.real * int * int * Real32.real -> Real32.real
end end
structure ClickPoints :> CLICK_POINTS = structure ClickPoints :> CLICK_POINTS =
@@ -53,7 +57,7 @@ struct
| NONE => NONE) | NONE => NONE)
| NONE => NONE | NONE => NONE
fun getDrawVec (xpos, ypos, r, g, b, app: AppType.app_type) = fun getDrawDot (xpos, ypos, r, g, b, app: AppType.app_type) =
let let
val {windowWidth, windowHeight, ...} = app val {windowWidth, windowHeight, ...} = app
@@ -71,4 +75,37 @@ struct
in in
Ndc.ltrbToVertex (left, top, right, bottom, r, g, b) Ndc.ltrbToVertex (left, top, right, bottom, r, g, b)
end end
fun xposToNdc (xpos, windowWidth, windowHeight, halfWidth) =
let
val xpos = xpos - halfWidth
in
if windowWidth > windowHeight then
let
val difference = windowWidth - windowHeight
val offset = Real32.fromInt (difference div 2)
in
xpos / (halfWidth - offset)
end
else
xpos / halfWidth
end
fun yposToNdc (ypos, windowWidth, windowHeight, halfHeight) =
let
val ypos = ~(ypos - halfHeight)
in
if windowHeight > windowWidth then
let
val difference = windowHeight - windowWidth
val offset = Real32.fromInt (difference div 2)
in
ypos / (halfHeight - offset)
end
else
ypos / halfHeight
end
end end