done generating collision string

This commit is contained in:
2025-07-13 15:02:13 +01:00
parent 7cfbd3cdb3
commit d98b815516
4 changed files with 31 additions and 89 deletions

View File

@@ -632,15 +632,43 @@ struct
fun toCollisionStringFolder ({x, ex, y, ey, data = _}, acc) =
let
val ex = if x = ex then ex + 1 else ex
val ex = ex + 1
val ey = if y = ey then ey + 1 else ey
val width = ex - x
val width = if width = 0 then width + 1 else width
val height = ey - y
val height = if height = 0 then height + 1 else height
val x = Int.toString x
val y = Int.toString y
val width = Int.toString width
val height = Int.toString height
val item = String.concat
[ "{x = "
, x
, ", y = "
, y
, ", width = "
, width
, ", height = "
, height
, " }"
]
in
item :: acc
end
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
val collisions = BinTree.foldr (toCollisionStringFolder, bintree, [])
val collisions = String.concatWith ",\n" collisions
in
String.concat ["val collisions = #[", collisions, "]\n"]
end
end