begin creating a string for collision data

This commit is contained in:
2025-07-13 14:35:50 +01:00
parent 7ec1e34bb8
commit 7cfbd3cdb3

View File

@@ -548,12 +548,36 @@ struct
(* based on triangle order formed by `Ndc.ltrbToVertexRgb` function *)
val item = String.concatWith ",\n"
[ x, ey, r, g, b
, ex, ey, r, g, b
, x, y, r, g, b
, x, y, r, g, b
, ex, ey, r, g, b
, ex, y, r, g, b
[ x
, ey
, r
, g
, b
, ex
, ey
, r
, g
, b
, x
, y
, r
, g
, b
, x
, y
, r
, g
, b
, ex
, ey
, r
, g
, b
, ex
, y
, r
, g
, b
]
in
item :: acc
@@ -598,4 +622,25 @@ struct
, "end\n"
]
end
(* functions for exporting a collision detection string *)
fun mapItem (item as {r, g, b, a}) =
if shouldIgnoreData item then item else {r = 1, g = 1, b = 1, a = 1}
fun mapGrid grid =
Vector.map (fn yAxis => Vector.map (fn item => mapItem item) yAxis) grid
fun toCollisionStringFolder ({x, ex, y, ey, data = _}, acc) =
let
val ex = if x = ex then ex + 1 else ex
val ey = if y = ey then ey + 1 else ey
fun toCollisionString (squares, canvasWidth, canvasHeight) =
let
val size = Int.max (canvasWidth, canvasHeight)
val qtree = buildTree (0, 0, size, squares)
val bintree = merge (qtree, squares)
val collisions = BinTree.foldr (toExportStringFolder, bintree, [])
val collisions = String.concatWith ",\n" coords
end