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

72 lines
2.4 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 minusX = (curX - halfWidth - 1.0) / halfWidth
val plusX = (curX - halfWidth + 1.0) / 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 = Ndc.ltrbToVertex (minusX, maxY, plusX, 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 minusY = ~(curY - halfHeight - 1.0) / halfHeight
val plusY = ~(curY - halfHeight + 1.0) / halfHeight
val minX = Vector.sub (xClickPoints, 0)
val minX = (minX - halfWidth) / halfWidth
val maxX = Vector.sub (xClickPoints, Vector.length xClickPoints - 1)
val maxX = (maxX - halfWidth) / halfWidth
val acc = Ndc.ltrbToVertex (minX, plusY, maxX, minusY) :: 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