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 = structure CollisionTree =
struct 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 local
fun loopYAxis (x, y, eX, eY, yAxis, col) = fun loopYAxis (x, y, eX, eY, yAxis, col) =
if y > eY orelse y >= Vector.length yAxis then if y > eY orelse y >= Vector.length yAxis then
@@ -129,11 +134,17 @@ struct
let let
val yAxis = Vector.sub (grid, x) val yAxis = Vector.sub (grid, x)
val data = Vector.sub (yAxis, y) 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 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 end
else else
let let
@@ -164,25 +175,22 @@ struct
, xClickPoints , xClickPoints
, yClickPoints , yClickPoints
) ({x, ex, y, ey, data}, acc) = ) ({x, ex, y, ey, data}, acc) =
if data = 0 then let
acc val ex = if ex = x then x + 1 else ex
else 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 x = getClickPoint (xClickPoints, x)
val y = getClickPoint (yClickPoints, y) val y = getClickPoint (yClickPoints, y)
val ex = getClickPoint (xClickPoints, ex) val ex = getClickPoint (xClickPoints, ex)
val ey = getClickPoint (yClickPoints, ey) val ey = getClickPoint (yClickPoints, ey)
val startX = Ndc.fromPixelX (x, windowWidth, windowHeight) val startX = Ndc.fromPixelX (x, windowWidth, windowHeight)
val endX = Ndc.fromPixelX (ex, windowWidth, windowHeight) val endX = Ndc.fromPixelX (ex, windowWidth, windowHeight)
val startY = Ndc.fromPixelY (y, windowWidth, windowHeight) val startY = Ndc.fromPixelY (y, windowWidth, windowHeight)
val endY = Ndc.fromPixelY (ey, windowWidth, windowHeight) val endY = Ndc.fromPixelY (ey, windowWidth, windowHeight)
in in
Ndc.ltrbToVertexRgb (startX, startY, endX, endY, 0.0, 0.0, 0.0) :: acc Ndc.ltrbToVertexRgb (startX, startY, endX, endY, 0.0, 0.0, 0.0) :: acc
end end
in in
fun toTriangles fun toTriangles
( windowWidth ( windowWidth