fix bugs with generating export strings from quad tree (have to add 1 to ex and ey indiscriminately, except if we are not in the canvas width/height dimensions)
This commit is contained in:
@@ -534,14 +534,15 @@ struct
|
|||||||
in "endYToNdc (yOffset, " ^ startY ^ ", " ^ endY ^ ", scale, halfHeight)"
|
in "endYToNdc (yOffset, " ^ startY ^ ", " ^ endY ^ ", scale, halfHeight)"
|
||||||
end
|
end
|
||||||
|
|
||||||
fun toExportStringFolder ({x, ex, y, ey, data = {r, g, b, a}}, acc) =
|
fun toExportStringFolder (maxWidth, maxHeight) ({x, ex, y, ey, data = {r, g, b, a}}, acc) =
|
||||||
let
|
let
|
||||||
val ey = if ey = y then y + 1 else ey
|
val ex = if ex < maxWidth then ex + 1 else ex
|
||||||
|
val ey = if ey < maxHeight then ey + 1 else ey
|
||||||
|
|
||||||
val x = makeXString x
|
val x = makeXString x
|
||||||
val y = makeYString y
|
val y = makeYString y
|
||||||
val ex = makeEndXString (x, ex)
|
val ex = makeEndXString (x, ex)
|
||||||
val ey = makeYString ey
|
val ey = makeEndYString (y, ey)
|
||||||
val r = colToRealString r
|
val r = colToRealString r
|
||||||
val g = colToRealString g
|
val g = colToRealString g
|
||||||
val b = colToRealString b
|
val b = colToRealString b
|
||||||
@@ -589,7 +590,8 @@ struct
|
|||||||
val qtree = buildTree (0, 0, size, squares)
|
val qtree = buildTree (0, 0, size, squares)
|
||||||
val bintree = merge (qtree, squares)
|
val bintree = merge (qtree, squares)
|
||||||
|
|
||||||
val coords = BinTree.foldr (toExportStringFolder, bintree, [])
|
val f = toExportStringFolder (canvasWidth, canvasHeight)
|
||||||
|
val coords = BinTree.foldr (f, bintree, [])
|
||||||
val coords = String.concatWith ",\n" coords
|
val coords = String.concatWith ",\n" coords
|
||||||
in
|
in
|
||||||
String.concat
|
String.concat
|
||||||
@@ -630,10 +632,10 @@ struct
|
|||||||
fun mapGrid grid =
|
fun mapGrid grid =
|
||||||
Vector.map (fn yAxis => Vector.map (fn item => mapItem item) yAxis) grid
|
Vector.map (fn yAxis => Vector.map (fn item => mapItem item) yAxis) grid
|
||||||
|
|
||||||
fun toCollisionStringFolder scale ({x, ex, y, ey, data = _}, acc) =
|
fun toCollisionStringFolder (scale, maxWidth, maxHeight) ({x, ex, y, ey, data = _}, acc) =
|
||||||
let
|
let
|
||||||
val ex = ex + 1
|
val ex = if ex < maxWidth then ex + 1 else ex
|
||||||
val ey = if y = ey then ey + 1 else ey
|
val ey = if ey < maxHeight then ey + 1 else ey
|
||||||
|
|
||||||
val width = ex - x
|
val width = ex - x
|
||||||
val width = if width = 0 then width + 1 else width
|
val width = if width = 0 then width + 1 else width
|
||||||
@@ -662,11 +664,12 @@ struct
|
|||||||
|
|
||||||
fun toCollisionString (squares, canvasWidth, canvasHeight, scale) =
|
fun toCollisionString (squares, canvasWidth, canvasHeight, scale) =
|
||||||
let
|
let
|
||||||
|
val scale = if scale = 0 then 1 else scale
|
||||||
val size = Int.max (canvasWidth, canvasHeight)
|
val size = Int.max (canvasWidth, canvasHeight)
|
||||||
val qtree = buildTree (0, 0, size, squares)
|
val qtree = buildTree (0, 0, size, squares)
|
||||||
val bintree = merge (qtree, squares)
|
val bintree = merge (qtree, squares)
|
||||||
|
|
||||||
val f = toCollisionStringFolder scale
|
val f = toCollisionStringFolder (scale, canvasWidth, canvasHeight)
|
||||||
val collisions = BinTree.foldr (f, bintree, [])
|
val collisions = BinTree.foldr (f, bintree, [])
|
||||||
val collisions = String.concatWith ",\n" collisions
|
val collisions = String.concatWith ",\n" collisions
|
||||||
in
|
in
|
||||||
|
|||||||
Reference in New Issue
Block a user