preparation for functorising quad tree

This commit is contained in:
2025-07-07 02:36:29 +01:00
parent bd97aeceac
commit 6b5c0d9ba1
2 changed files with 29 additions and 21 deletions

BIN
dotscape

Binary file not shown.

View File

@@ -87,6 +87,11 @@ end
structure CollisionTree =
struct
(* ignoreData = any data we find in grid but which doesn't concern us
* so we omit from tree, to reduce number of items in tree,
* and therefore decrease the constant in O(n) *)
val ignoreData = 0
local
fun loopYAxis (x, y, eX, eY, yAxis, col) =
if y > eY orelse y >= Vector.length yAxis then
@@ -129,11 +134,17 @@ struct
let
val yAxis = Vector.sub (grid, x)
val data = Vector.sub (yAxis, y)
val ex = x + size
val ey = y + size
val item = {x = x, y = y, ex = ex, ey = ey, data = data}
in
BinTree.insert (item, bintree)
if data = ignoreData then
bintree
else
let
val ex = x + size
val ey = y + size
val item = {x = x, y = y, ex = ex, ey = ey, data = data}
in
BinTree.insert (item, bintree)
end
end
else
let
@@ -164,25 +175,22 @@ struct
, xClickPoints
, yClickPoints
) ({x, ex, y, ey, data}, acc) =
if data = 0 then
acc
else
let
val ex = if ex = x then x + 1 else ex
val ey = if ey = y then y + 1 else ey
let
val ex = if ex = x then x + 1 else ex
val ey = if ey = y then y + 1 else ey
val x = getClickPoint (xClickPoints, x)
val y = getClickPoint (yClickPoints, y)
val ex = getClickPoint (xClickPoints, ex)
val ey = getClickPoint (yClickPoints, ey)
val x = getClickPoint (xClickPoints, x)
val y = getClickPoint (yClickPoints, y)
val ex = getClickPoint (xClickPoints, ex)
val ey = getClickPoint (yClickPoints, ey)
val startX = Ndc.fromPixelX (x, windowWidth, windowHeight)
val endX = Ndc.fromPixelX (ex, windowWidth, windowHeight)
val startY = Ndc.fromPixelY (y, windowWidth, windowHeight)
val endY = Ndc.fromPixelY (ey, windowWidth, windowHeight)
in
Ndc.ltrbToVertexRgb (startX, startY, endX, endY, 0.0, 0.0, 0.0) :: acc
end
val startX = Ndc.fromPixelX (x, windowWidth, windowHeight)
val endX = Ndc.fromPixelX (ex, windowWidth, windowHeight)
val startY = Ndc.fromPixelY (y, windowWidth, windowHeight)
val endY = Ndc.fromPixelY (ey, windowWidth, windowHeight)
in
Ndc.ltrbToVertexRgb (startX, startY, endX, endY, 0.0, 0.0, 0.0) :: acc
end
in
fun toTriangles
( windowWidth