progress coding function to create an export string
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
structure CollisionTree =
|
||||
struct
|
||||
structure BinTree =
|
||||
struct
|
||||
datatype 'a bintree =
|
||||
@@ -97,8 +99,6 @@ struct
|
||||
foldr (fn (item, acc) => item :: acc, tree, [])
|
||||
end
|
||||
|
||||
structure CollisionTree =
|
||||
struct
|
||||
fun shouldIgnoreData {a, r = _, g = _, b = _} = a = 0
|
||||
|
||||
local
|
||||
@@ -457,33 +457,6 @@ struct
|
||||
toBintree tree
|
||||
end
|
||||
|
||||
fun toTrianglesMerged
|
||||
( windowWidth
|
||||
, windowHeight
|
||||
, squares
|
||||
, size
|
||||
, canvasWidth
|
||||
, canvasHeight
|
||||
, xClickPoints
|
||||
, yClickPoints
|
||||
) =
|
||||
let
|
||||
val qtree = buildTree (0, 0, size, squares)
|
||||
val bintree = merge (qtree, squares)
|
||||
|
||||
val f = folder
|
||||
( windowWidth
|
||||
, windowHeight
|
||||
, canvasWidth
|
||||
, canvasHeight
|
||||
, xClickPoints
|
||||
, yClickPoints
|
||||
)
|
||||
val vec = BinTree.foldr (f, bintree, [])
|
||||
in
|
||||
Vector.concat vec
|
||||
end
|
||||
|
||||
fun toStringFolder ({x, ex, y, ey, data = {r, g, b, a}}, acc) =
|
||||
let
|
||||
val item = String.concat
|
||||
@@ -524,4 +497,77 @@ struct
|
||||
in
|
||||
String.concat acc
|
||||
end
|
||||
|
||||
fun intToRealString num =
|
||||
let
|
||||
val result = Real32.fromInt num
|
||||
val result = Real32.toString result
|
||||
in
|
||||
if String.isSubstring "." result then result else result ^ ".0"
|
||||
end
|
||||
|
||||
fun colToRealString col =
|
||||
let
|
||||
val result = Real32.fromInt col / 255.0
|
||||
val result = Real32.toString result
|
||||
in
|
||||
if String.isSubstring "." result then result else result ^ ".0"
|
||||
end
|
||||
|
||||
fun toExportStringFolder ({x, ex, y, ey, data = {r, g, b, a}}, acc) =
|
||||
let
|
||||
val x = intToRealString x
|
||||
val y = intToRealString y
|
||||
val ex = intToRealString ex
|
||||
val ey = intToRealString ey
|
||||
val r = colToRealString r
|
||||
val g = colToRealString g
|
||||
val b = colToRealString b
|
||||
|
||||
val x = String.concat ["((", x, " - halfWidth) / halfWidth)"]
|
||||
val y = String.concat ["(~(", y, " - halfHeight) / halfHeight)"]
|
||||
|
||||
val ex = String.concat
|
||||
[ "((((("
|
||||
, ex
|
||||
, " - "
|
||||
, x
|
||||
, ") "
|
||||
, "* scale) + "
|
||||
, x
|
||||
, ") - halfWidth) / halfWidth)"
|
||||
]
|
||||
|
||||
val ey = String.concat
|
||||
[ "("
|
||||
, "("
|
||||
, "("
|
||||
, "("
|
||||
, "("
|
||||
, ey
|
||||
, " - "
|
||||
, y
|
||||
, ")"
|
||||
, "* scale) + "
|
||||
, y
|
||||
, ") - halfHeight) / halfHeight)"
|
||||
]
|
||||
in
|
||||
x :: y :: ex :: ex :: y :: ey :: r :: g :: b :: acc
|
||||
end
|
||||
|
||||
fun toExportString (squares, canvasWidth, canvasHeight) =
|
||||
let
|
||||
val size = Int.max (canvasWidth, canvasHeight)
|
||||
val qtree = buildTree (0, 0, size, squares)
|
||||
val bintree = merge (qtree, squares)
|
||||
|
||||
val coords = BinTree.foldr (toExportStringFolder, bintree, [])
|
||||
val coords = String.concatWith "," coords
|
||||
|
||||
val header = ""
|
||||
val footer = ""
|
||||
in
|
||||
String.concat [header, coords, footer]
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user