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:
2024-08-08 01:37:46 +01:00
parent d9607d27d8
commit 1264e20dc8
5 changed files with 505 additions and 466 deletions

View File

@@ -1,44 +1,51 @@
structure AppInit = signature APP_INIT =
sig
val fromWidthAndHeight : int * int -> AppType.app_type
end
structure AppInit :> APP_INIT =
struct struct
open AppType open AppType
local fun helpFromWidthAndHeight
fun init (windowWidth, windowHeight, wStart, wFinish, hStart, hFinish) = (windowWidth, windowHeight, wStart, wFinish, hStart, hFinish) =
let
val xClickPoints = ClickPoints.generate (wStart, wFinish)
val yClickPoints = ClickPoints.generate (hStart, hFinish)
val graphLines =
GraphLines.generate
(windowWidth, windowHeight, xClickPoints, yClickPoints)
in
{ triangles = []
, triangleStage = NO_TRIANGLE
, windowWidth = windowWidth
, windowHeight = windowHeight
, xClickPoints = xClickPoints
, yClickPoints = yClickPoints
, graphLines = graphLines
}
end
fun fromWidthAndHeight (windowWidth, windowHeight) =
if windowWidth = windowHeight then
helpFromWidthAndHeight
(windowWidth, windowHeight, 0, windowWidth, 0, windowHeight)
else if windowWidth > windowHeight then
let let
val xClickPoints = ClickPoints.generate (wStart, wFinish) val difference = windowWidth - windowHeight
val yClickPoints = ClickPoints.generate (hStart, hFinish) val wStart = difference div 2
val graphLines = val wFinish = wStart + windowHeight
GraphLines.generate
(windowWidth, windowHeight, xClickPoints, yClickPoints)
in in
{ triangles = [] helpFromWidthAndHeight
, triangleStage = NO_TRIANGLE (windowWidth, windowHeight, wStart, wFinish, 0, windowHeight)
, windowWidth = windowWidth end
, windowHeight = windowHeight else
, xClickPoints = xClickPoints let
, yClickPoints = yClickPoints val difference = windowHeight - windowWidth
, graphLines = graphLines val hStart = difference div 2
} val hFinish = hStart + windowWidth
in
helpFromWidthAndHeight
(windowWidth, windowHeight, 0, windowWidth, hStart, hFinish)
end end
in
fun fromWidthAndHeight (windowWidth, windowHeight) =
if windowWidth = windowHeight then
init (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)
end
else
let
val difference = windowHeight - windowWidth
val hStart = difference div 2
val hFinish = hStart + windowWidth
in
init (windowWidth, windowHeight, 0, windowWidth, hStart, hFinish)
end
end
end end

View File

@@ -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 struct
open AppType open AppType
@@ -49,61 +65,55 @@ struct
} }
end end
local fun helpWindowResize
fun make (app: app_type, windowWidth, windowHeight, wStart, wFinish, hStart, hFinish) :
( app: app_type app_type =
, windowWidth let
, windowHeight val
, wStart { xClickPoints = _
, wFinish , yClickPoints = _
, hStart , windowWidth = _
, hFinish , windowHeight = _
) : app_type = , graphLines = _
, triangles
, triangleStage
} = app
val xClickPoints = ClickPoints.generate (wStart, wFinish)
val yClickPoints = ClickPoints.generate (hStart, hFinish)
val graphLines =
GraphLines.generate
(windowWidth, windowHeight, xClickPoints, yClickPoints)
in
{ xClickPoints = xClickPoints
, yClickPoints = yClickPoints
, graphLines = graphLines
, triangles = triangles
, triangleStage = triangleStage
, windowWidth = windowWidth
, windowHeight = windowHeight
}
end
fun windowResize (app: app_type, windowWidth, windowHeight) =
if windowWidth = windowHeight then
helpWindowResize
(app, windowWidth, windowHeight, 0, windowWidth, 0, windowHeight)
else if windowWidth > windowHeight then
let let
val val difference = windowWidth - windowHeight
{ xClickPoints = _ val wStart = difference div 2
, yClickPoints = _ val wFinish = wStart + windowHeight
, windowWidth = _
, windowHeight = _
, graphLines = _
, triangles
, triangleStage
} = app
val xClickPoints = ClickPoints.generate (wStart, wFinish)
val yClickPoints = ClickPoints.generate (hStart, hFinish)
val graphLines =
GraphLines.generate
(windowWidth, windowHeight, xClickPoints, yClickPoints)
in in
{ xClickPoints = xClickPoints helpWindowResize
, yClickPoints = yClickPoints (app, windowWidth, windowHeight, wStart, wFinish, 0, windowHeight)
, graphLines = graphLines end
, triangles = triangles else
, triangleStage = triangleStage let
, windowWidth = windowWidth val difference = windowHeight - windowWidth
, windowHeight = windowHeight val hStart = difference div 2
} val hFinish = hStart + windowWidth
in
helpWindowResize
(app, windowWidth, windowHeight, 0, windowWidth, hStart, hFinish)
end end
in
fun windowResize (app: app_type, windowWidth, windowHeight) =
if windowWidth = windowHeight then
make (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
(app, windowWidth, windowHeight, wStart, wFinish, 0, windowHeight)
end
else
let
val difference = windowHeight - windowWidth
val hStart = difference div 2
val hFinish = hStart + windowWidth
in
make (app, windowWidth, windowHeight, 0, windowWidth, hStart, hFinish)
end
end
end end

View File

@@ -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 struct
fun generate (start, finish) = fun generate (start, finish) =
let let
@@ -9,127 +25,188 @@ struct
Vector.tabulate (41, fn idx => (Real32.fromInt idx * increment) + start) Vector.tabulate (41, fn idx => (Real32.fromInt idx * increment) + start)
end end
local (*
(* * Range to detect from clickable position.
* Range to detect from clickable position. * For example, if we have a clickable position at (x, y) = (500, 500),
* For example, if we have a clickable position at (x, y) = (500, 500), * with a range of 15, we can detect clicks targeting this position
* with a range of 15, we can detect clicks targeting this position * from top left at (485, 485) to bottom right at (515, 515).
* from top left at (485, 485) to bottom right at (515, 515). * *)
* *) val range = 15.0
val range = 15.0
fun getVerticalClickPos fun getVerticalClickPos
( yClickPoints ( yClickPoints
, idx , idx
, horizontalPos , horizontalPos
, mouseX , mouseX
, mouseY , mouseY
, r , r
, g , g
, b , b
, windowWidth , windowWidth
, windowHeight , windowHeight
) = ) =
if idx = Vector.length yClickPoints then if idx = Vector.length yClickPoints then
(#[], 0.0, 0.0) (#[], 0.0, 0.0)
else else
let let
val curVerticalPos = Vector.sub (yClickPoints, idx) val curVerticalPos = Vector.sub (yClickPoints, idx)
in in
if if
mouseY < curVerticalPos - range mouseY < curVerticalPos - range orelse mouseY > curVerticalPos + range
orelse mouseY > curVerticalPos + range then
then getVerticalClickPos
getVerticalClickPos ( yClickPoints
( yClickPoints , idx + 1
, idx + 1 , horizontalPos
, horizontalPos , mouseX
, mouseX , mouseY
, mouseY , r
, r , g
, g , b
, b , windowWidth
, windowWidth , windowHeight
, windowHeight )
) else
else let
let (* calculate normalised device coordinates *)
(* calculate normalised device coordinates *) 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 = horizontalPos - halfWidth
val hpos = horizontalPos - halfWidth val vpos = ~(curVerticalPos - halfHeight)
val vpos = ~(curVerticalPos - halfHeight)
(* coordinates to form small box around clicked area *) (* coordinates to form small box around clicked area *)
val left = (hpos - 5.0) / halfWidth val left = (hpos - 5.0) / halfWidth
val right = (hpos + 5.0) / halfWidth val right = (hpos + 5.0) / halfWidth
val bottom = (vpos - 5.0) / halfHeight val bottom = (vpos - 5.0) / halfHeight
val top = (vpos + 5.0) / halfHeight val top = (vpos + 5.0) / halfHeight
(* normalised device coordinates of drawVec should be relative (* normalised device coordinates of drawVec should be relative
* to actual windowWidth and windowHeight, * to actual windowWidth and windowHeight,
* even if not a square, to display cursor position... *) * even if not a square, to display cursor position... *)
val drawVec = Ndc.ltrbToVertex (left, top, right, bottom, r, g, b) val drawVec = Ndc.ltrbToVertex (left, top, right, bottom, r, g, b)
in in
(* (*
* ...however, normalised device coordinate of hpos and vpos * ...however, normalised device coordinate of hpos and vpos
* should be relative to the vertical centre * should be relative to the vertical centre
* (if height is greater than width) * (if height is greater than width)
* or horizontal centre * or horizontal centre
* (if width is greater than height). * (if width is greater than height).
* *
* So, for example, a 900x1000 resolution * So, for example, a 900x1000 resolution
* will have clickable points from 50...950, * will have clickable points from 50...950,
* in increments of 50. * in increments of 50.
* Because we always want to show canvas as a square * Because we always want to show canvas as a square
* with an aspect ratio of 1:1. * with an aspect ratio of 1:1.
* For displaying the click position on the screen, drawVec * For displaying the click position on the screen, drawVec
* which uses actual windowWidth and windowHeight, is fine. * which uses actual windowWidth and windowHeight, is fine.
* However, we want to attach the meaning "start" to 50 * However, we want to attach the meaning "start" to 50
* and "end" to 950, * and "end" to 950,
* so the hpos and vpos stored in the app's triangle list * so the hpos and vpos stored in the app's triangle list
* subtracts the offset 50 if needed, * subtracts the offset 50 if needed,
* allowing us to treat the coordinates as a 900x900 square. * allowing us to treat the coordinates as a 900x900 square.
* *
* We may not actually want to render a square to the screen * We may not actually want to render a square to the screen
* if the screen's aspect ratio is not 1:1, * if the screen's aspect ratio is not 1:1,
* but it's the responsibility of the rendering code * but it's the responsibility of the rendering code
* which turns triangles into OpenGL vectors * which turns triangles into OpenGL vectors
* to do that. * to do that.
* *) * *)
if windowWidth = windowHeight then if windowWidth = windowHeight then
let let
val hpos = hpos / halfWidth val hpos = hpos / halfWidth
val vpos = vpos / halfHeight val vpos = vpos / halfHeight
in in
(drawVec, hpos, vpos) (drawVec, hpos, vpos)
end end
else if windowWidth > windowHeight then else if windowWidth > windowHeight then
let let
val difference = windowWidth - windowHeight val difference = windowWidth - windowHeight
val offset = Real32.fromInt (difference div 2) val offset = Real32.fromInt (difference div 2)
val hpos = hpos / (halfWidth - offset) val hpos = hpos / (halfWidth - offset)
val vpos = vpos / halfHeight val vpos = vpos / halfHeight
in in
(drawVec, hpos, vpos) (drawVec, hpos, vpos)
end end
else else
(* windowHeight > windowWidth *) (* windowHeight > windowWidth *)
let let
val difference = windowHeight - windowWidth val difference = windowHeight - windowWidth
val offset = Real32.fromInt (difference div 2) val offset = Real32.fromInt (difference div 2)
val hpos = hpos / halfWidth val hpos = hpos / halfWidth
val vpos = vpos / (halfHeight - offset) val vpos = vpos / (halfHeight - offset)
in in
(drawVec, hpos, vpos) (drawVec, hpos, vpos)
end end
end end
end end
fun getHorizontalClickPos fun getHorizontalClickPos
( xClickPoints
, yClickPoints
, idx
, mouseX
, mouseY
, r
, g
, b
, windowWidth
, windowHeight
) =
if idx = Vector.length xClickPoints then
(#[], 0.0, 0.0)
else
let
val curPos = Vector.sub (xClickPoints, idx)
in
if mouseX < curPos - range orelse mouseX > curPos + range then
getHorizontalClickPos
( xClickPoints
, yClickPoints
, idx + 1
, mouseX
, mouseY
, r
, g
, b
, windowWidth
, windowHeight
)
else
getVerticalClickPos
( yClickPoints
, 0
, curPos
, mouseX
, mouseY
, r
, g
, b
, windowWidth
, windowHeight
)
end
(*
* This function returns a vector containing the position data of the
* clicked square.
* If a square wasn't found at the clicked position,
* an empty vector is returned.
*)
fun getClickPosition
( mouseX
, mouseY
, r
, g
, b
, xClickPoints
, yClickPoints
, windowWidth
, windowHeight
) =
getHorizontalClickPos
( xClickPoints ( xClickPoints
, yClickPoints , yClickPoints
, idx , 0
, mouseX , mouseX
, mouseY , mouseY
, r , r
@@ -137,69 +214,5 @@ struct
, b , b
, windowWidth , windowWidth
, windowHeight , windowHeight
) = )
if idx = Vector.length xClickPoints then
(#[], 0.0, 0.0)
else
let
val curPos = Vector.sub (xClickPoints, idx)
in
if mouseX < curPos - range orelse mouseX > curPos + range then
getHorizontalClickPos
( xClickPoints
, yClickPoints
, idx + 1
, mouseX
, mouseY
, r
, g
, b
, windowWidth
, windowHeight
)
else
getVerticalClickPos
( yClickPoints
, 0
, curPos
, mouseX
, mouseY
, r
, g
, b
, windowWidth
, windowHeight
)
end
in
(*
* This function returns a vector containing the position data of the
* clicked square.
* If a square wasn't found at the clicked position,
* an empty vector is returned.
*)
fun getClickPosition
( mouseX
, mouseY
, r
, g
, b
, xClickPoints
, yClickPoints
, windowWidth
, windowHeight
) =
getHorizontalClickPos
( xClickPoints
, yClickPoints
, 0
, mouseX
, mouseY
, r
, g
, b
, windowWidth
, windowHeight
)
end
end end

View File

@@ -1,176 +1,183 @@
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 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. * when the window is a square and has the aspect ratio 1:1.
* This is because the function assumes it can use * This is because the function assumes it can use
* the same position coordinates both horizontally and vertically. * the same position coordinates both horizontally and vertically.
* *) *)
fun helpGenGraphLinesSquare (pos: Real32.real, limit, acc) = fun helpGenGraphLinesSquare (pos: Real32.real, limit, acc) =
if pos >= limit then if pos >= limit then
Vector.concat acc Vector.concat acc
else else
let let
val pos2 = pos + 0.05 val pos2 = pos + 0.05
val vec = val vec =
#[ (* x = _.1 *) #[ (* x = _.1 *)
pos - 0.002, ~1.0 pos - 0.002, ~1.0
, pos + 0.002, ~1.0 , pos + 0.002, ~1.0
, pos + 0.002, 1.0 , pos + 0.002, 1.0
, pos + 0.002, 1.0 , pos + 0.002, 1.0
, pos - 0.002, 1.0 , 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
, 1.0, pos + 0.002
, 1.0, pos + 0.002 (* y = _.1 *)
, 1.0, pos - 0.002 , ~1.0, pos - 0.002
, ~1.0, pos - 0.002 , ~1.0, pos + 0.002
, 1.0, pos + 0.002
, 1.0, pos + 0.002
, 1.0, pos - 0.002
, ~1.0, pos - 0.002
(* x = _.05 *) (* x = _.05 *)
, pos2 - 0.001, ~1.0 , pos2 - 0.001, ~1.0
, pos2 + 0.001, ~1.0 , pos2 + 0.001, ~1.0
, pos2 + 0.001, 1.0 , pos2 + 0.001, 1.0
, pos2 + 0.001, 1.0 , pos2 + 0.001, 1.0
, pos2 - 0.001, 1.0 , pos2 - 0.001, 1.0
, pos2 - 0.001, ~1.0 , pos2 - 0.001, ~1.0
(* y = _.05 *) (* y = _.05 *)
, ~1.0, pos2 - 0.001 , ~1.0, pos2 - 0.001
, ~1.0, pos2 + 0.001 , ~1.0, pos2 + 0.001
, 1.0, pos2 + 0.001 , 1.0, pos2 + 0.001
, 1.0, pos2 + 0.001 , 1.0, pos2 + 0.001
, 1.0, pos2 - 0.001 , 1.0, pos2 - 0.001
, ~1.0, pos2 - 0.001 , ~1.0, pos2 - 0.001
]
val acc = vec :: acc
val nextPos = pos + 0.1
in
helpGenGraphLinesSquare (nextPos, limit, acc)
end
fun helpGenGraphLinesHorizontal
(pos, xClickPoints, acc, halfWidth, yMin, yMax) =
if pos = Vector.length xClickPoints then
acc
else
let
val curX = Vector.sub (xClickPoints, pos)
val ndc = (curX - halfWidth) / halfWidth
val vec =
if (pos + 1) mod 2 = 0 then
(* if even (thin lines) *)
#[
ndc - 0.001, yMin
, ndc + 0.001, yMin
, ndc + 0.001, yMax
, ndc + 0.001, yMax
, ndc - 0.001, yMax
, ndc - 0.001, yMin
] ]
val acc = vec :: acc else
val nextPos = pos + 0.1 (* if odd (thick lines) *)
in #[
helpGenGraphLinesSquare (nextPos, limit, acc) ndc - 0.002, yMin
end , ndc + 0.002, yMin
, ndc + 0.002, yMax
fun helpGenGraphLinesHorizontal (pos, xClickPoints, acc, halfWidth, yMin, yMax) = , ndc + 0.002, yMax
if pos = Vector.length xClickPoints then , ndc - 0.002, yMax
acc , ndc - 0.002, yMin
else ]
let val acc = vec :: acc
val curX = Vector.sub (xClickPoints, pos) in
val ndc = (curX - halfWidth) / halfWidth helpGenGraphLinesHorizontal
val vec = (pos + 1, xClickPoints, acc, halfWidth, yMin, yMax)
if (pos + 1) mod 2 = 0 then end
(* if even (thin lines) *)
#[
ndc - 0.001, yMin
, ndc + 0.001, yMin
, ndc + 0.001, yMax
, ndc + 0.001, yMax fun helpGenGraphLinesVertical (pos, yClickPoints, acc, halfHeight, xMin, xMax) =
, ndc - 0.001, yMax if pos = Vector.length yClickPoints then
, ndc - 0.001, yMin acc
] else
else let
(* if odd (thick lines) *) val curY = Vector.sub (yClickPoints, pos)
#[ val ndc = (curY - halfHeight) / halfHeight
ndc - 0.002, yMin val vec =
, ndc + 0.002, yMin if (pos + 1) mod 2 = 0 then
, ndc + 0.002, yMax (* if even (thin lines) *)
#[
xMin, ndc - 0.001
, xMin, ndc + 0.001
, xMax, ndc + 0.001
, ndc + 0.002, yMax , xMax, ndc + 0.001
, ndc - 0.002, yMax , xMax, ndc - 0.001
, ndc - 0.002, yMin , xMin, ndc - 0.001
] ]
val acc = vec:: acc else
in (* if odd (thick lines) *)
helpGenGraphLinesHorizontal #[
(pos + 1, xClickPoints, acc, halfWidth, yMin, yMax) xMin, ndc - 0.002
end , xMin, ndc + 0.002
, xMax, ndc + 0.002
fun helpGenGraphLinesVertical (pos, yClickPoints, acc, halfHeight, xMin, xMax) = , xMax, ndc + 0.002
if pos = Vector.length yClickPoints then , xMax, ndc - 0.002
acc , xMin, ndc - 0.002
else ]
let val acc = vec :: acc
val curY = Vector.sub (yClickPoints, pos) in
val ndc = (curY - halfHeight) / halfHeight helpGenGraphLinesVertical
val vec = (pos + 1, yClickPoints, acc, halfHeight, xMin, xMax)
if (pos + 1) mod 2 = 0 then end
(* if even (thin lines) *)
#[
xMin, ndc - 0.001
, xMin, ndc + 0.001
, xMax, ndc + 0.001
, xMax, ndc + 0.001 fun generate (windowWidth, windowHeight, xClickPoints, yClickPoints) =
, xMax, ndc - 0.001 if windowWidth = windowHeight then
, xMin, ndc - 0.001 helpGenGraphLinesSquare (~1.0, 1.0, [])
] else if windowWidth > windowHeight then
else let
(* if odd (thick lines) *) val difference = windowWidth - windowHeight
#[ val offset = difference div 2
xMin, ndc - 0.002
, xMin, ndc + 0.002
, xMax, ndc + 0.002
, xMax, ndc + 0.002 val halfWidth = Real32.fromInt (windowWidth div 2)
, xMax, ndc - 0.002 val halfHeight = Real32.fromInt (windowHeight div 2)
, xMin, ndc - 0.002
]
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, [])
else if windowWidth > windowHeight then
let
val difference = windowWidth - windowHeight
val offset = difference div 2
val halfWidth = Real32.fromInt (windowWidth div 2) val start = offset - (windowWidth div 2)
val halfHeight = Real32.fromInt (windowHeight div 2) val start = Real32.fromInt start / halfWidth
val start = offset - (windowWidth div 2) val finish = (windowWidth - offset) - (windowWidth div 2)
val start = Real32.fromInt start / halfWidth val finish = Real32.fromInt finish / halfWidth
val finish = (windowWidth - offset) - (windowWidth div 2) val lines = helpGenGraphLinesHorizontal
val finish = Real32.fromInt finish / halfWidth (0, xClickPoints, [], halfWidth, ~1.0, 1.0)
val lines = helpGenGraphLinesVertical
(0, yClickPoints, lines, halfHeight, start, finish)
in
Vector.concat lines
end
else
(* windowWidth < windowHeight *)
let
val difference = windowHeight - windowWidth
val offset = difference div 2
val lines = helpGenGraphLinesHorizontal val halfWidth = Real32.fromInt (windowWidth div 2)
(0, xClickPoints, [], halfWidth, ~1.0, 1.0) val halfHeight = Real32.fromInt (windowHeight div 2)
val lines = helpGenGraphLinesVertical
(0, yClickPoints, lines, halfHeight, start, finish)
in
Vector.concat lines
end
else
(* windowWidth < windowHeight *)
let
val difference = windowHeight - windowWidth
val offset = difference div 2
val halfWidth = Real32.fromInt (windowWidth div 2) val start = offset - (windowHeight div 2)
val halfHeight = Real32.fromInt (windowHeight div 2) val start = Real32.fromInt start / halfHeight
val start = offset - (windowHeight div 2) val finish = (windowHeight - offset) - (windowHeight div 2)
val start = Real32.fromInt start / halfHeight val finish = Real32.fromInt finish / halfHeight
val finish = (windowHeight - offset) - (windowHeight div 2) val lines = helpGenGraphLinesHorizontal
val finish = Real32.fromInt finish / halfHeight (0, xClickPoints, [], halfWidth, start, finish)
val lines = helpGenGraphLinesVertical
val lines = helpGenGraphLinesHorizontal (0, yClickPoints, lines, halfHeight, ~1.0, 1.0)
(0, xClickPoints, [], halfWidth, start, finish) in
val lines = helpGenGraphLinesVertical Vector.concat lines
(0, yClickPoints, lines, halfHeight, ~1.0, 1.0) end
in
Vector.concat lines
end
end
end end

View File

@@ -1,46 +1,48 @@
structure Triangles = signature TRIANGLES =
sig
val toVector: AppType.app_type -> Real32.real vector
end
structure Triangles :> TRIANGLES =
struct struct
open AppType open AppType
local fun helpToVector (lst, acc, windowWidth, windowHeight, halfWidth, halfHeight) =
fun helpToVector case lst of
(lst, acc, windowWidth, windowHeight, halfWidth, halfHeight) = {x1, y1, x2, y2, x3, y3} :: tl =>
case lst of let
{x1, y1, x2, y2, x3, y3} :: tl => val x1 = Ndc.centreAlignX (x1, windowWidth, windowHeight, halfWidth)
let val x2 = Ndc.centreAlignX (x2, windowWidth, windowHeight, halfWidth)
val x1 = Ndc.centreAlignX (x1, windowWidth, windowHeight, halfWidth) val x3 = Ndc.centreAlignX (x3, windowWidth, windowHeight, halfWidth)
val x2 = Ndc.centreAlignX (x2, windowWidth, windowHeight, halfWidth)
val x3 = Ndc.centreAlignX (x3, windowWidth, windowHeight, halfWidth)
val y1 = Ndc.centreAlignY (y1, windowWidth, windowHeight, halfHeight) val y1 = Ndc.centreAlignY (y1, windowWidth, windowHeight, halfHeight)
val y2 = Ndc.centreAlignY (y2, windowWidth, windowHeight, halfHeight) val y2 = Ndc.centreAlignY (y2, windowWidth, windowHeight, halfHeight)
val y3 = Ndc.centreAlignY (y3, windowWidth, windowHeight, halfHeight) val y3 = Ndc.centreAlignY (y3, windowWidth, windowHeight, halfHeight)
val vec = val vec =
#[ x1 / halfWidth #[ x1 / halfWidth
, y1 / halfHeight , y1 / halfHeight
, x2 / halfWidth , x2 / halfWidth
, y2 / halfHeight , y2 / halfHeight
, x3 / halfWidth , x3 / halfWidth
, y3 / halfHeight , y3 / halfHeight
] ]
val acc = vec :: acc val acc = vec :: acc
in in
helpToVector helpToVector
(tl, acc, windowWidth, windowHeight, halfWidth, halfHeight) (tl, acc, windowWidth, windowHeight, halfWidth, halfHeight)
end end
| [] => acc | [] => acc
in
fun toVector (app: app_type) = fun toVector (app: app_type) =
let let
val windowWidth = #windowWidth app val windowWidth = #windowWidth app
val windowHeight = #windowHeight app val windowHeight = #windowHeight app
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 lst = helpToVector val lst = helpToVector
(#triangles app, [], windowWidth, windowHeight, halfWidth, halfHeight) (#triangles app, [], windowWidth, windowHeight, halfWidth, halfHeight)
in in
Vector.concat lst Vector.concat lst
end end
end
end end