Files
sml-projects/fcore/graph-lines.sml

88 lines
2.8 KiB
Standard ML
Raw Normal View History

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-06 17:50:46 +01:00
fun helpGenGraphLinesX (pos, xClickPoints, yClickPoints, acc,
windowWidth, windowHeight) =
if pos = Vector.length xClickPoints then
2025-07-06 02:15:16 +01:00
Vector.concat acc
else
let
2025-07-10 22:48:34 +01:00
val halfWidth = Real32.fromInt (windowWidth div 2)
val halfHeight = Real32.fromInt (windowHeight div 2)
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 22:48:34 +01:00
val curXNdc = (curX - halfWidth) / halfWidth
2025-07-06 02:15:16 +01:00
2025-07-06 17:50:46 +01:00
val minY = Vector.sub (xClickPoints, 0)
2025-07-10 22:48:34 +01:00
val minY = (~(minY - halfHeight)) / halfHeight
2025-07-06 17:50:46 +01:00
val maxY = Vector.sub (xClickPoints, Vector.length xClickPoints - 1)
2025-07-10 22:48:34 +01:00
val maxY = (~(maxY - halfHeight)) /halfHeight
2025-07-06 02:15:16 +01:00
val acc =
2025-07-10 22:48:34 +01:00
#[ curXNdc - 0.001, minY
, curXNdc + 0.001, minY
, curXNdc + 0.001, maxY
2025-07-06 02:15:16 +01:00
2025-07-10 22:48:34 +01:00
, curXNdc + 0.001, maxY
, curXNdc - 0.001, maxY
, curXNdc - 0.001, minY
2025-07-06 17:50:46 +01:00
] :: 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-06 17:50:46 +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-06 17:50:46 +01:00
val halfWidth = windowHeight div 2
val halfWidth = Real32.fromInt halfWidth
val halfHeight = windowHeight div 2
val halfHeight = Real32.fromInt halfHeight
2025-07-06 02:15:16 +01:00
val curY = Vector.sub (yClickPoints, pos)
2025-07-10 22:48:34 +01:00
val curYNdc =(~(curY - halfHeight)) / 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 _ = print ("maxX = " ^ Real32.toString maxX ^ "\n")
val maxX = (maxX - halfWidth) / halfWidth
2025-07-06 17:50:46 +01:00
2025-07-06 02:15:16 +01:00
val acc =
2025-07-06 17:50:46 +01:00
#[ minX, curYNdc - 0.001
, minX, curYNdc + 0.001
, maxX, curYNdc + 0.001
2025-07-06 02:15:16 +01:00
2025-07-06 17:50:46 +01:00
, maxX, curYNdc + 0.001
, maxX, curYNdc - 0.001
, minX, curYNdc - 0.001
2025-07-06 02:15:16 +01:00
] :: acc
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) =
2025-07-06 17:50:46 +01:00
let
val acc = helpGenGraphLinesY (0, yClickPoints, xClickPoints, [], windowWidth, windowHeight)
in
helpGenGraphLinesX (0, xClickPoints, yClickPoints, acc, windowWidth, windowHeight)
end
2025-07-06 02:15:16 +01:00
fun generate (app: AppType.app_type) =
let
val {windowWidth, windowHeight, xClickPoints, yClickPoints, ...} = app
in
helpGenerate (windowWidth, windowHeight, xClickPoints, yClickPoints)
end
end