2025-07-06 02:15:16 +01:00
|
|
|
signature GRAPH_LINES =
|
|
|
|
|
sig
|
|
|
|
|
val generate: AppType.app_type -> Real32.real vector
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
structure GraphLines :> GRAPH_LINES =
|
|
|
|
|
struct
|
2025-07-11 00:57:55 +01:00
|
|
|
fun helpGenGraphLinesX
|
|
|
|
|
(pos, xClickPoints, yClickPoints, acc, windowWidth, windowHeight) =
|
2025-07-06 17:50:46 +01:00
|
|
|
if pos = Vector.length xClickPoints then
|
2025-07-06 02:15:16 +01:00
|
|
|
Vector.concat acc
|
|
|
|
|
else
|
|
|
|
|
let
|
2025-07-11 01:45:47 +01:00
|
|
|
val halfWidth = Real32.fromInt windowWidth / 2.0
|
|
|
|
|
val halfHeight = Real32.fromInt windowHeight / 2.0
|
2025-07-06 02:15:16 +01:00
|
|
|
|
2025-07-06 17:50:46 +01:00
|
|
|
val curX = Vector.sub (xClickPoints, pos)
|
2025-07-11 03:54:38 +01:00
|
|
|
val minusX = Ndc.fromPixelX (curX - 1.0, windowWidth, windowHeight)
|
|
|
|
|
val plusX = Ndc.fromPixelX (curX + 1.0, windowWidth, windowHeight)
|
2025-07-06 02:15:16 +01:00
|
|
|
|
2025-07-11 01:56:59 +01:00
|
|
|
val minY = Vector.sub (yClickPoints, 0)
|
|
|
|
|
val maxY = Vector.sub (yClickPoints, Vector.length yClickPoints - 1)
|
2025-07-11 03:54:38 +01:00
|
|
|
val minY = Ndc.fromPixelY (minY, windowWidth, windowHeight)
|
|
|
|
|
val maxY = Ndc.fromPixelY (maxY, windowWidth, windowHeight)
|
2025-07-06 02:15:16 +01:00
|
|
|
|
2025-07-10 23:54:51 +01:00
|
|
|
val acc = Ndc.ltrbToVertex (minusX, maxY, plusX, minY) :: acc
|
2025-07-06 02:15:16 +01:00
|
|
|
in
|
2025-07-06 17:50:46 +01:00
|
|
|
helpGenGraphLinesX
|
|
|
|
|
(pos + 1, xClickPoints, yClickPoints, acc, windowWidth, windowHeight)
|
2025-07-06 02:15:16 +01:00
|
|
|
end
|
|
|
|
|
|
2025-07-11 00:57:55 +01:00
|
|
|
fun helpGenGraphLinesY
|
|
|
|
|
(pos, yClickPoints, xClickPoints, acc, windowWidth, windowHeight) =
|
2025-07-06 02:15:16 +01:00
|
|
|
if pos = Vector.length yClickPoints then
|
|
|
|
|
acc
|
|
|
|
|
else
|
|
|
|
|
let
|
2025-07-11 01:45:47 +01:00
|
|
|
val halfWidth = Real32.fromInt windowWidth / 2.0
|
|
|
|
|
val halfHeight = Real32.fromInt windowHeight / 2.0
|
2025-07-06 17:50:46 +01:00
|
|
|
|
2025-07-06 02:15:16 +01:00
|
|
|
val curY = Vector.sub (yClickPoints, pos)
|
2025-07-11 03:54:38 +01:00
|
|
|
val minusY = Ndc.fromPixelY (curY - 1.0, windowWidth, windowHeight)
|
|
|
|
|
val plusY = Ndc.fromPixelY (curY + 1.0, windowWidth, windowHeight)
|
2025-07-06 17:50:46 +01:00
|
|
|
|
|
|
|
|
val minX = Vector.sub (xClickPoints, 0)
|
|
|
|
|
val maxX = Vector.sub (xClickPoints, Vector.length xClickPoints - 1)
|
2025-07-11 03:54:38 +01:00
|
|
|
val minX = Ndc.fromPixelX (minX, windowWidth, windowHeight)
|
|
|
|
|
val maxX = Ndc.fromPixelX (maxX, windowWidth, windowHeight)
|
2025-07-06 17:50:46 +01:00
|
|
|
|
2025-07-10 23:54:51 +01:00
|
|
|
val acc = Ndc.ltrbToVertex (minX, plusY, maxX, minusY) :: acc
|
2025-07-06 02:15:16 +01:00
|
|
|
in
|
2025-07-06 17:50:46 +01:00
|
|
|
helpGenGraphLinesY
|
|
|
|
|
(pos + 1, yClickPoints, xClickPoints, acc, windowWidth, windowHeight)
|
2025-07-06 02:15:16 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun helpGenerate (windowWidth, windowHeight, xClickPoints, yClickPoints) =
|
|
|
|
|
let
|
2025-07-11 00:57:55 +01:00
|
|
|
val acc = helpGenGraphLinesY
|
|
|
|
|
(0, yClickPoints, xClickPoints, [], windowWidth, windowHeight)
|
2025-07-06 02:15:16 +01:00
|
|
|
in
|
2025-07-11 00:57:55 +01:00
|
|
|
helpGenGraphLinesX
|
|
|
|
|
(0, xClickPoints, yClickPoints, acc, windowWidth, windowHeight)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun generate (app: AppType.app_type) =
|
|
|
|
|
let val {windowWidth, windowHeight, xClickPoints, yClickPoints, ...} = app
|
|
|
|
|
in helpGenerate (windowWidth, windowHeight, xClickPoints, yClickPoints)
|
2025-07-06 02:15:16 +01:00
|
|
|
end
|
|
|
|
|
end
|