create constant vector that looks like graph paper (grid for clicking points later)

This commit is contained in:
2024-07-29 22:45:10 +01:00
parent 228902297d
commit 438f6458a0
3 changed files with 756 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
structure AppType =
struct
type triangle =
{ x1: Real32.real
, y1: Real32.real
, x2: Real32.real
, y2: Real32.real
, x3: Real32.real
, y3: Real32.real
}
datatype triangle_stage =
NO_TRIANGLE
(*
* triangle_stage represents a work-in-progress triangle which is not fully completed,
* because user has to click one (x, y) pair, then a second pair,
* and then a third, to draw a complete triangle.
*
* There is no THIRD triangle_stage because that represents a complete triangle,
* which should be added to the `triangles` list.
*)
| FIRST of {x1: Real32.real, y1: Real32.real}
| SECOND of
{x1: Real32.real, y1: Real32.real, x2: Real32.real, y2: Real32.real}
type app_type = {triangles: triangle list, triangleStage: triangle_stage}
local
fun helpGetTrianglesVector (lst, acc) =
case lst of
{x1, y1, x2, y2, x3, y3} :: tl =>
let val vec = Vector.fromList [x1, y1, x2, y2, x3, y3]
in helpGetTrianglesVector (tl, vec :: acc)
end
| [] => acc
in
fun getTrianglesVector (app: app_type) =
let val lst = helpGetTrianglseVector (#triangles app, [])
in Vector.concat lst
end
end
end