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-10 23:54:51 +01:00
|
|
|
val minusX = (curX - halfWidth - 1.0) / halfWidth
|
|
|
|
|
val plusX = (curX - halfWidth + 1.0) / halfWidth
|
2025-07-06 02:15:16 +01:00
|
|
|
|
2025-07-11 01:56:59 +01:00
|
|
|
val minY = Vector.sub (yClickPoints, 0)
|
2025-07-10 22:48:34 +01:00
|
|
|
val minY = (~(minY - halfHeight)) / halfHeight
|
2025-07-11 01:56:59 +01:00
|
|
|
val maxY = Vector.sub (yClickPoints, Vector.length yClickPoints - 1)
|
2025-07-11 00:57:55 +01:00
|
|
|
val maxY = (~(maxY - halfHeight)) / halfHeight
|
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 01:45:47 +01:00
|
|
|
val minusY = (~(curY - halfHeight - 1.0)) / halfHeight
|
|
|
|
|
val plusY = (~(curY - halfHeight + 1.0)) / halfHeight
|
2025-07-06 17:50:46 +01:00
|
|
|
|
|
|
|
|
val minX = Vector.sub (xClickPoints, 0)
|
2025-07-10 22:48:34 +01:00
|
|
|
val minX = (minX - halfWidth) / halfWidth
|
2025-07-06 17:50:46 +01:00
|
|
|
val maxX = Vector.sub (xClickPoints, Vector.length xClickPoints - 1)
|
2025-07-10 22:48:34 +01:00
|
|
|
val maxX = (maxX - halfWidth) / halfWidth
|
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
|