signature GRAPH_LINES = sig val generate: AppType.app_type -> Real32.real vector end structure GraphLines :> GRAPH_LINES = struct fun toNdc (cur, half) = (cur - half) / half fun helpGenGraphLinesX (pos, xClickPoints, yClickPoints, acc, windowWidth, windowHeight) = if pos = Vector.length xClickPoints then Vector.concat acc else let val halfWidth = windowHeight div 2 val halfWidth = Real32.fromInt halfWidth val halfHeight = windowHeight div 2 val halfHeight = Real32.fromInt halfHeight val curX = Vector.sub (xClickPoints, pos) val curYNdc = toNdc (curX, halfWidth) val minY = Vector.sub (xClickPoints, 0) val minY = toNdc (minY, halfWidth) val maxY = Vector.sub (xClickPoints, Vector.length xClickPoints - 1) val maxY = toNdc (maxY, halfWidth) val acc = #[ curYNdc - 0.001, minY , curYNdc + 0.001, minY , curYNdc + 0.001, maxY , curYNdc + 0.001, maxY , curYNdc - 0.001, maxY , curYNdc - 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 = toNdc (curY, halfHeight) val minX = Vector.sub (xClickPoints, 0) val minX = toNdc (minX, halfWidth) val maxX = Vector.sub (xClickPoints, Vector.length xClickPoints - 1) val maxX = toNdc (maxX, 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