summaryrefslogtreecommitdiff
path: root/city/geometry-test.lua
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-02-25 12:49:31 -0600
committersanine <sanine.not@pm.me>2022-02-25 12:49:31 -0600
commit9cd5a9f8ac5242cd220c9bae89432e817d548b83 (patch)
tree15cc8d83f738791b83a0dc6375ad8bfaeef83d56 /city/geometry-test.lua
parent342bc7a8caac79c28fc1c430926ea63d486303fa (diff)
add qt_node:find_containing()
Diffstat (limited to 'city/geometry-test.lua')
-rw-r--r--city/geometry-test.lua36
1 files changed, 36 insertions, 0 deletions
diff --git a/city/geometry-test.lua b/city/geometry-test.lua
index 4c61cac..98275a3 100644
--- a/city/geometry-test.lua
+++ b/city/geometry-test.lua
@@ -324,3 +324,39 @@ test(
end
end
)
+
+test(
+ 'find containing node for points',
+ function()
+ local node = geom.qt_node(geom.point(2, 2), 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))
+
+ local point = geom.point(3, 1)
+ local n = node:find_containing(point)
+ assert(n:is_leaf())
+ assert(n.square.center.x == 3)
+ assert(n.square.center.y == 1)
+
+ point = geom.point(1, 3)
+ n = node:find_containing(point)
+ assert(n:is_leaf())
+ assert(n.square.center.x == 1)
+ assert(n.square.center.y == 3)
+
+ point = geom.point(3, 3)
+ n = node:find_containing(point)
+ assert(n:is_leaf())
+ assert(n.square.center.x == 3)
+ assert(n.square.center.y == 3)
+
+ point = geom.point(0.24, 0.24)
+ n = node:find_containing(point)
+ assert(n:is_leaf())
+ assert(n.point.x == 0.25)
+ assert(n.point.y == 0.25)
+ end
+)