summaryrefslogtreecommitdiff
path: root/city/geometry.lua
diff options
context:
space:
mode:
Diffstat (limited to 'city/geometry.lua')
-rw-r--r--city/geometry.lua14
1 files changed, 14 insertions, 0 deletions
diff --git a/city/geometry.lua b/city/geometry.lua
index e380173..410b4a3 100644
--- a/city/geometry.lua
+++ b/city/geometry.lua
@@ -169,6 +169,20 @@ geom.qt_node = class{
for _, child in ipairs(self.children) do
child:query(region, points)
end
+ end,
+
+ -- return the leaf node containing the given point
+ -- returns nil if no such node exists (i.e. the point
+ -- is out of bounds)
+ find_containing = function(self, point)
+ if not self.square:contains(point) then return end
+
+ if self:is_leaf() then return self end
+
+ for _, child in ipairs(self.children) do
+ local result = child:find_containing(point)
+ if result then return result end
+ end
end
}