summaryrefslogtreecommitdiff
path: root/city/geometry.lua
diff options
context:
space:
mode:
Diffstat (limited to 'city/geometry.lua')
-rw-r--r--city/geometry.lua18
1 files changed, 15 insertions, 3 deletions
diff --git a/city/geometry.lua b/city/geometry.lua
index 5893731..a24e508 100644
--- a/city/geometry.lua
+++ b/city/geometry.lua
@@ -62,15 +62,27 @@ geom.square = class{
return false
end,
+ -- check if the square intersects the given square
+ intersects = function(self, square)
+ local overlap = function(a, b)
+ return math.max(a.min, b.min) < math.min(a.max, b.max)
+ end
+ local x_overlap = overlap(self.x, square.x)
+ local y_overlap = overlap(self.y, square.y)
+
+ if x_overlap and y_overlap then return true end
+ return false
+ end,
+
-- return an array of four squares covering the same
-- area as their parent
divide = function(self)
local this = getmetatable(self).__index
-
+
local x = self.center.x
local y = self.center.y
local d = self.span / 4
-
+
return {
this(geom.point(x-d, y-d), d*2),
this(geom.point(x+d, y-d), d*2),
@@ -105,7 +117,7 @@ geom.qt_node = class{
-- point isn't even in this region
return false
end
-
+
if self:is_leaf() and not self.point then
-- no preexisting point, just store it
self.point = point