summaryrefslogtreecommitdiff
path: root/city/geometry-test.lua
diff options
context:
space:
mode:
Diffstat (limited to 'city/geometry-test.lua')
-rw-r--r--city/geometry-test.lua96
1 files changed, 95 insertions, 1 deletions
diff --git a/city/geometry-test.lua b/city/geometry-test.lua
index 3227cd1..758ce95 100644
--- a/city/geometry-test.lua
+++ b/city/geometry-test.lua
@@ -1,5 +1,6 @@
local test = require('minunit').test
local geom = require 'geometry'
+local util = require 'util'
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -148,7 +149,100 @@ test(
assert(node.square.center.y == 2)
assert(node.square.span == 4)
- assert(not node:is_leaf())
+ assert(node:is_leaf())
+ assert(not node.point)
+ end
+)
+
+test(
+ 'insert points into qt_node',
+ function()
+ local center = geom.point(2, 2)
+ local node = geom.qt_node(center, 4)
+
+ assert(node:is_leaf())
assert(not node.point)
+
+ node:insert(geom.point(1, 1))
+ assert(node:is_leaf())
+ assert(node.point.x == 1)
+ assert(node.point.y == 1)
+
+ node:insert(geom.point(3, 3))
+ assert(not node:is_leaf())
+
+ assert(node.children[1]:is_leaf())
+ assert(node.children[1].point.x == 1)
+ assert(node.children[1].point.y == 1)
+
+ assert(node.children[2]:is_leaf())
+ assert(not node.children[2].point)
+
+ assert(node.children[3]:is_leaf())
+ assert(not node.children[3].point)
+
+ assert(node.children[4]:is_leaf())
+ assert(node.children[4].point.x == 3)
+ assert(node.children[4].point.y == 3)
+ end
+)
+
+test(
+ 'instert four points into qt_node',
+ function()
+ local center = geom.point(2, 2)
+ local node = geom.qt_node(center, 4)
+
+ node:insert(geom.point(1, 1))
+ node:insert(geom.point(0.5, 0.5))
+ node:insert(geom.point(0.25, 0.25))
+ node:insert(geom.point(0.125, 0.125))
+
+ assert(not node:is_leaf())
+
+ assert(node.children[2]:is_leaf())
+ assert(not node.children[2].point)
+ assert(node.children[3]:is_leaf())
+ assert(not node.children[3].point)
+ assert(node.children[4]:is_leaf())
+ assert(not node.children[4].point)
+
+ node = node.children[1].children[1]
+ assert(not node:is_leaf())
+
+ assert(not node.children[1]:is_leaf())
+ assert(node.children[2]:is_leaf())
+ assert(not node.children[2].point)
+ assert(node.children[3]:is_leaf())
+ assert(not node.children[3].point)
+ assert(node.children[4]:is_leaf())
+ assert(node.children[4].point.x == 1)
+ assert(node.children[4].point.y == 1)
+
+ node = node.children[1]
+ assert(not node:is_leaf())
+
+ assert(node.children[2]:is_leaf())
+ assert(not node.children[2].point)
+ assert(node.children[3]:is_leaf())
+ assert(not node.children[3].point)
+ assert(node.children[4]:is_leaf())
+ assert(node.children[4].point.x == 0.5)
+ assert(node.children[4].point.y == 0.5)
+
+ node = node.children[1]
+ assert(not node:is_leaf())
+
+ assert(node.children[2]:is_leaf())
+ assert(not node.children[2].point)
+ assert(node.children[3]:is_leaf())
+ assert(not node.children[3].point)
+ assert(node.children[4]:is_leaf())
+ assert(node.children[4].point.x == 0.25)
+ assert(node.children[4].point.y == 0.25)
+
+ assert(node.children[1]:is_leaf())
+ assert(node.children[1].point.x == 0.125)
+ assert(node.children[1].point.y == 0.125)
end
)