remove instances of 'local ... in ... end', replacing it with opauque structures with signatures, because I like the lower indentation level and additional whitespace in the latter
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
structure AppInit =
|
||||
signature APP_INIT =
|
||||
sig
|
||||
val fromWidthAndHeight : int * int -> AppType.app_type
|
||||
end
|
||||
|
||||
structure AppInit :> APP_INIT =
|
||||
struct
|
||||
open AppType
|
||||
|
||||
local
|
||||
fun init (windowWidth, windowHeight, wStart, wFinish, hStart, hFinish) =
|
||||
fun helpFromWidthAndHeight
|
||||
(windowWidth, windowHeight, wStart, wFinish, hStart, hFinish) =
|
||||
let
|
||||
val xClickPoints = ClickPoints.generate (wStart, wFinish)
|
||||
val yClickPoints = ClickPoints.generate (hStart, hFinish)
|
||||
@@ -20,17 +25,19 @@ struct
|
||||
, graphLines = graphLines
|
||||
}
|
||||
end
|
||||
in
|
||||
|
||||
fun fromWidthAndHeight (windowWidth, windowHeight) =
|
||||
if windowWidth = windowHeight then
|
||||
init (windowWidth, windowHeight, 0, windowWidth, 0, windowHeight)
|
||||
helpFromWidthAndHeight
|
||||
(windowWidth, windowHeight, 0, windowWidth, 0, windowHeight)
|
||||
else if windowWidth > windowHeight then
|
||||
let
|
||||
val difference = windowWidth - windowHeight
|
||||
val wStart = difference div 2
|
||||
val wFinish = wStart + windowHeight
|
||||
in
|
||||
init (windowWidth, windowHeight, wStart, wFinish, 0, windowHeight)
|
||||
helpFromWidthAndHeight
|
||||
(windowWidth, windowHeight, wStart, wFinish, 0, windowHeight)
|
||||
end
|
||||
else
|
||||
let
|
||||
@@ -38,7 +45,7 @@ struct
|
||||
val hStart = difference div 2
|
||||
val hFinish = hStart + windowWidth
|
||||
in
|
||||
init (windowWidth, windowHeight, 0, windowWidth, hStart, hFinish)
|
||||
end
|
||||
helpFromWidthAndHeight
|
||||
(windowWidth, windowHeight, 0, windowWidth, hStart, hFinish)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,20 @@
|
||||
structure AppWith =
|
||||
signature APP_WITH =
|
||||
sig
|
||||
val windowResize: AppType.app_type * int * int -> AppType.app_type
|
||||
val triangleStage: AppType.app_type * AppType.triangle_stage
|
||||
-> AppType.app_type
|
||||
val newTriangle:
|
||||
AppType.app_type
|
||||
* Real32.real
|
||||
* Real32.real
|
||||
* Real32.real
|
||||
* Real32.real
|
||||
* Real32.real
|
||||
* Real32.real
|
||||
-> AppType.app_type
|
||||
end
|
||||
|
||||
structure AppWith :> APP_WITH =
|
||||
struct
|
||||
open AppType
|
||||
|
||||
@@ -49,16 +65,9 @@ struct
|
||||
}
|
||||
end
|
||||
|
||||
local
|
||||
fun make
|
||||
( app: app_type
|
||||
, windowWidth
|
||||
, windowHeight
|
||||
, wStart
|
||||
, wFinish
|
||||
, hStart
|
||||
, hFinish
|
||||
) : app_type =
|
||||
fun helpWindowResize
|
||||
(app: app_type, windowWidth, windowHeight, wStart, wFinish, hStart, hFinish) :
|
||||
app_type =
|
||||
let
|
||||
val
|
||||
{ xClickPoints = _
|
||||
@@ -84,17 +93,18 @@ struct
|
||||
, windowHeight = windowHeight
|
||||
}
|
||||
end
|
||||
in
|
||||
|
||||
fun windowResize (app: app_type, windowWidth, windowHeight) =
|
||||
if windowWidth = windowHeight then
|
||||
make (app, windowWidth, windowHeight, 0, windowWidth, 0, windowHeight)
|
||||
helpWindowResize
|
||||
(app, windowWidth, windowHeight, 0, windowWidth, 0, windowHeight)
|
||||
else if windowWidth > windowHeight then
|
||||
let
|
||||
val difference = windowWidth - windowHeight
|
||||
val wStart = difference div 2
|
||||
val wFinish = wStart + windowHeight
|
||||
in
|
||||
make
|
||||
helpWindowResize
|
||||
(app, windowWidth, windowHeight, wStart, wFinish, 0, windowHeight)
|
||||
end
|
||||
else
|
||||
@@ -103,7 +113,7 @@ struct
|
||||
val hStart = difference div 2
|
||||
val hFinish = hStart + windowWidth
|
||||
in
|
||||
make (app, windowWidth, windowHeight, 0, windowWidth, hStart, hFinish)
|
||||
end
|
||||
helpWindowResize
|
||||
(app, windowWidth, windowHeight, 0, windowWidth, hStart, hFinish)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,20 @@
|
||||
structure ClickPoints =
|
||||
signature CLICK_POINTS =
|
||||
sig
|
||||
val generate: int * int -> Real32.real vector
|
||||
val getClickPosition:
|
||||
Real32.real
|
||||
* Real32.real
|
||||
* Real32.real
|
||||
* Real32.real
|
||||
* Real32.real
|
||||
* Real32.real vector
|
||||
* Real32.real vector
|
||||
* int
|
||||
* int
|
||||
-> Real32.real vector * Real32.real * Real32.real
|
||||
end
|
||||
|
||||
structure ClickPoints :> CLICK_POINTS =
|
||||
struct
|
||||
fun generate (start, finish) =
|
||||
let
|
||||
@@ -9,7 +25,6 @@ struct
|
||||
Vector.tabulate (41, fn idx => (Real32.fromInt idx * increment) + start)
|
||||
end
|
||||
|
||||
local
|
||||
(*
|
||||
* Range to detect from clickable position.
|
||||
* For example, if we have a clickable position at (x, y) = (500, 500),
|
||||
@@ -37,8 +52,7 @@ struct
|
||||
val curVerticalPos = Vector.sub (yClickPoints, idx)
|
||||
in
|
||||
if
|
||||
mouseY < curVerticalPos - range
|
||||
orelse mouseY > curVerticalPos + range
|
||||
mouseY < curVerticalPos - range orelse mouseY > curVerticalPos + range
|
||||
then
|
||||
getVerticalClickPos
|
||||
( yClickPoints
|
||||
@@ -171,7 +185,7 @@ struct
|
||||
, windowHeight
|
||||
)
|
||||
end
|
||||
in
|
||||
|
||||
(*
|
||||
* This function returns a vector containing the position data of the
|
||||
* clicked square.
|
||||
@@ -201,5 +215,4 @@ struct
|
||||
, windowWidth
|
||||
, windowHeight
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
structure GraphLines =
|
||||
signature GRAPH_LINES =
|
||||
sig
|
||||
val generate: int * int * Real32.real vector * Real32.real vector
|
||||
-> Real32.real vector
|
||||
end
|
||||
|
||||
structure GraphLines :> GRAPH_LINES =
|
||||
struct
|
||||
local
|
||||
(* This function only produces the desired result
|
||||
(*
|
||||
* This function only produces the desired result
|
||||
* when the window is a square and has the aspect ratio 1:1.
|
||||
* This is because the function assumes it can use
|
||||
* the same position coordinates both horizontally and vertically.
|
||||
* *)
|
||||
*)
|
||||
fun helpGenGraphLinesSquare (pos: Real32.real, limit, acc) =
|
||||
if pos >= limit then
|
||||
Vector.concat acc
|
||||
@@ -21,6 +27,7 @@ struct
|
||||
, pos + 0.002, 1.0
|
||||
, pos - 0.002, 1.0
|
||||
, pos - 0.002, ~1.0
|
||||
|
||||
(* y = _.1 *)
|
||||
, ~1.0, pos - 0.002
|
||||
, ~1.0, pos + 0.002
|
||||
@@ -54,7 +61,8 @@ struct
|
||||
helpGenGraphLinesSquare (nextPos, limit, acc)
|
||||
end
|
||||
|
||||
fun helpGenGraphLinesHorizontal (pos, xClickPoints, acc, halfWidth, yMin, yMax) =
|
||||
fun helpGenGraphLinesHorizontal
|
||||
(pos, xClickPoints, acc, halfWidth, yMin, yMax) =
|
||||
if pos = Vector.length xClickPoints then
|
||||
acc
|
||||
else
|
||||
@@ -84,7 +92,7 @@ struct
|
||||
, ndc - 0.002, yMax
|
||||
, ndc - 0.002, yMin
|
||||
]
|
||||
val acc = vec:: acc
|
||||
val acc = vec :: acc
|
||||
in
|
||||
helpGenGraphLinesHorizontal
|
||||
(pos + 1, xClickPoints, acc, halfWidth, yMin, yMax)
|
||||
@@ -120,12 +128,12 @@ struct
|
||||
, xMax, ndc - 0.002
|
||||
, xMin, ndc - 0.002
|
||||
]
|
||||
val acc = vec:: acc
|
||||
val acc = vec :: acc
|
||||
in
|
||||
helpGenGraphLinesVertical
|
||||
(pos + 1, yClickPoints, acc, halfHeight, xMin, xMax)
|
||||
end
|
||||
in
|
||||
|
||||
fun generate (windowWidth, windowHeight, xClickPoints, yClickPoints) =
|
||||
if windowWidth = windowHeight then
|
||||
helpGenGraphLinesSquare (~1.0, 1.0, [])
|
||||
@@ -172,5 +180,4 @@ struct
|
||||
in
|
||||
Vector.concat lines
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
structure Triangles =
|
||||
signature TRIANGLES =
|
||||
sig
|
||||
val toVector: AppType.app_type -> Real32.real vector
|
||||
end
|
||||
|
||||
structure Triangles :> TRIANGLES =
|
||||
struct
|
||||
open AppType
|
||||
|
||||
local
|
||||
fun helpToVector
|
||||
(lst, acc, windowWidth, windowHeight, halfWidth, halfHeight) =
|
||||
fun helpToVector (lst, acc, windowWidth, windowHeight, halfWidth, halfHeight) =
|
||||
case lst of
|
||||
{x1, y1, x2, y2, x3, y3} :: tl =>
|
||||
let
|
||||
@@ -30,7 +33,7 @@ struct
|
||||
(tl, acc, windowWidth, windowHeight, halfWidth, halfHeight)
|
||||
end
|
||||
| [] => acc
|
||||
in
|
||||
|
||||
fun toVector (app: app_type) =
|
||||
let
|
||||
val windowWidth = #windowWidth app
|
||||
@@ -42,5 +45,4 @@ struct
|
||||
in
|
||||
Vector.concat lst
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user