git-subtree-dir: dotscape git-subtree-mainline:6b91d64fc3git-subtree-split:f306501a68
70 lines
2.5 KiB
Standard ML
70 lines
2.5 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 / 2.0
|
|
val halfHeight = Real32.fromInt windowHeight / 2.0
|
|
|
|
val curX = Vector.sub (xClickPoints, pos)
|
|
val minusX = Ndc.fromPixelX (curX - 1.0, windowWidth, windowHeight)
|
|
val plusX = Ndc.fromPixelX (curX + 1.0, windowWidth, windowHeight)
|
|
|
|
val minY = Vector.sub (yClickPoints, 0)
|
|
val maxY = Vector.sub (yClickPoints, Vector.length yClickPoints - 1)
|
|
val minY = Ndc.fromPixelY (minY, windowWidth, windowHeight)
|
|
val maxY = Ndc.fromPixelY (maxY, windowWidth, windowHeight)
|
|
|
|
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 = Real32.fromInt windowWidth / 2.0
|
|
val halfHeight = Real32.fromInt windowHeight / 2.0
|
|
|
|
val curY = Vector.sub (yClickPoints, pos)
|
|
val minusY = Ndc.fromPixelY (curY - 1.0, windowWidth, windowHeight)
|
|
val plusY = Ndc.fromPixelY (curY + 1.0, windowWidth, windowHeight)
|
|
|
|
val minX = Vector.sub (xClickPoints, 0)
|
|
val maxX = Vector.sub (xClickPoints, Vector.length xClickPoints - 1)
|
|
val minX = Ndc.fromPixelX (minX, windowWidth, windowHeight)
|
|
val maxX = Ndc.fromPixelX (maxX, windowWidth, windowHeight)
|
|
|
|
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
|