diff options
Diffstat (limited to 'city/geometry.lua')
-rw-r--r-- | city/geometry.lua | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/city/geometry.lua b/city/geometry.lua index a24e508..e380173 100644 --- a/city/geometry.lua +++ b/city/geometry.lua @@ -89,7 +89,7 @@ geom.square = class{ this(geom.point(x-d, y+d), d*2), this(geom.point(x+d, y+d), d*2), } - end + end, } @@ -150,6 +150,25 @@ geom.qt_node = class{ -- should never get here return false + end, + + -- append any points within the supplied region under + -- the current node to the supplied array + query = function(self, region, points) + -- don't do anything if there's no intersection + if not self.square:intersects(region) then return end + + if self:is_leaf() then + if self.point and region:contains(self.point) then + table.insert(points, self.point) + end + return + end + + -- not a leaf node, recursively query children + for _, child in ipairs(self.children) do + child:query(region, points) + end end } |