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

88 lines
2.8 KiB
Standard ML

signature GRAPH_LINES =
sig
val generate: AppType.app_type -> Real32.real vector
end
structure GraphLines :> GRAPH_LINES =
struct
fun helpGenGraphLinesX (pos, xClickPoints, yClickPoints, acc,
windowWidth, windowHeight) =
if pos = Vector.length xClickPoints then
Vector.concat acc
else
let
val halfWidth = Real32.fromInt (windowWidth div 2)
val halfHeight = Real32.fromInt (windowHeight div 2)
val curX = Vector.sub (xClickPoints, pos)
val curXNdc = (curX - halfWidth) / halfWidth
val minY = Vector.sub (xClickPoints, 0)
val minY = (~(minY - halfHeight)) / halfHeight
val maxY = Vector.sub (xClickPoints, Vector.length xClickPoints - 1)
val maxY = (~(maxY - halfHeight)) /halfHeight
val acc =
#[ curXNdc - 0.001, minY
, curXNdc + 0.001, minY
, curXNdc + 0.001, maxY
, curXNdc + 0.001, maxY
, curXNdc - 0.001, maxY
, curXNdc - 0.001, minY
] :: acc
in
helpGenGraphLinesX
(pos + 1, xClickPoints, yClickPoints, acc, windowWidth, windowHeight)
end
fun helpGenGraphLinesY (pos, yClickPoints, xClickPoints, acc,
windowWidth, windowHeight) =
if pos = Vector.length yClickPoints then
acc
else
let
val halfWidth = windowHeight div 2
val halfWidth = Real32.fromInt halfWidth
val halfHeight = windowHeight div 2
val halfHeight = Real32.fromInt halfHeight
val curY = Vector.sub (yClickPoints, pos)
val curYNdc =(~(curY - halfHeight)) / halfHeight
val minX = Vector.sub (xClickPoints, 0)
val minX = (minX - halfWidth) / halfWidth
val maxX = Vector.sub (xClickPoints, Vector.length xClickPoints - 1)
val _ = print ("maxX = " ^ Real32.toString maxX ^ "\n")
val maxX = (maxX - halfWidth) / halfWidth
val acc =
#[ minX, curYNdc - 0.001
, minX, curYNdc + 0.001
, maxX, curYNdc + 0.001
, maxX, curYNdc + 0.001
, maxX, curYNdc - 0.001
, minX, curYNdc - 0.001
] :: acc
in
helpGenGraphLinesY
(pos + 1, yClickPoints, xClickPoints, acc, windowWidth, windowHeight)
end
fun helpGenerate (windowWidth, windowHeight, xClickPoints, yClickPoints) =
let
val acc = helpGenGraphLinesY (0, yClickPoints, xClickPoints, [], windowWidth, windowHeight)
in
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)
end
end