diff options
author | sanine <sanine.not@pm.me> | 2022-02-25 12:00:54 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-02-25 12:00:54 -0600 |
commit | 342bc7a8caac79c28fc1c430926ea63d486303fa (patch) | |
tree | c9920cc62e300d557e71065e16b563059c56ae81 /city/geometry.lua | |
parent | d4a02c3613746d00c5c3b633005c2f572a2bd721 (diff) |
add qt_node:query()
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 } |