preparation for functorising quad tree
This commit is contained in:
@@ -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,12 +134,18 @@ 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)
|
||||||
|
in
|
||||||
|
if data = ignoreData then
|
||||||
|
bintree
|
||||||
|
else
|
||||||
|
let
|
||||||
val ex = x + size
|
val ex = x + size
|
||||||
val ey = y + size
|
val ey = y + size
|
||||||
val item = {x = x, y = y, ex = ex, ey = ey, data = data}
|
val item = {x = x, y = y, ex = ex, ey = ey, data = data}
|
||||||
in
|
in
|
||||||
BinTree.insert (item, bintree)
|
BinTree.insert (item, bintree)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
(* handles odd-number divisions.
|
(* handles odd-number divisions.
|
||||||
@@ -164,9 +175,6 @@ struct
|
|||||||
, xClickPoints
|
, xClickPoints
|
||||||
, yClickPoints
|
, yClickPoints
|
||||||
) ({x, ex, y, ey, data}, acc) =
|
) ({x, ex, y, ey, data}, acc) =
|
||||||
if data = 0 then
|
|
||||||
acc
|
|
||||||
else
|
|
||||||
let
|
let
|
||||||
val ex = if ex = x then x + 1 else ex
|
val ex = if ex = x then x + 1 else ex
|
||||||
val ey = if ey = y then y + 1 else ey
|
val ey = if ey = y then y + 1 else ey
|
||||||
|
|||||||
Reference in New Issue
Block a user