progress coding function to create an export string
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
structure BinTree =
|
structure CollisionTree =
|
||||||
struct
|
struct
|
||||||
|
structure BinTree =
|
||||||
|
struct
|
||||||
datatype 'a bintree =
|
datatype 'a bintree =
|
||||||
NODE of
|
NODE of
|
||||||
{ x: int
|
{ x: int
|
||||||
@@ -95,10 +97,8 @@ struct
|
|||||||
|
|
||||||
fun toList tree =
|
fun toList tree =
|
||||||
foldr (fn (item, acc) => item :: acc, tree, [])
|
foldr (fn (item, acc) => item :: acc, tree, [])
|
||||||
end
|
end
|
||||||
|
|
||||||
structure CollisionTree =
|
|
||||||
struct
|
|
||||||
fun shouldIgnoreData {a, r = _, g = _, b = _} = a = 0
|
fun shouldIgnoreData {a, r = _, g = _, b = _} = a = 0
|
||||||
|
|
||||||
local
|
local
|
||||||
@@ -457,33 +457,6 @@ struct
|
|||||||
toBintree tree
|
toBintree tree
|
||||||
end
|
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) =
|
fun toStringFolder ({x, ex, y, ey, data = {r, g, b, a}}, acc) =
|
||||||
let
|
let
|
||||||
val item = String.concat
|
val item = String.concat
|
||||||
@@ -524,4 +497,77 @@ struct
|
|||||||
in
|
in
|
||||||
String.concat acc
|
String.concat acc
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user