diff --git a/dotscape b/dotscape index d42c2bf..c9a1f97 100755 Binary files a/dotscape and b/dotscape differ diff --git a/fcore/quad-tree.sml b/fcore/quad-tree.sml index 66f668e..14a32cd 100644 --- a/fcore/quad-tree.sml +++ b/fcore/quad-tree.sml @@ -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