bugfix: intersected geom should be initiated with a fresh copy of self

This commit is contained in:
chrox
2013-03-10 13:18:50 +08:00
parent 6561475cf7
commit dc22370cf1

View File

@@ -117,7 +117,8 @@ returns a rectangle for the part that we and a given rectangle share
TODO: what happens if there is no rectangle shared? currently behaviour is undefined.
]]--
function Geom:intersect(rect_b)
local intersected = Geom:new(self)
-- make a copy of self
local intersected = self:copy()
if self.x < rect_b.x then
intersected.x = rect_b.x
end
@@ -259,6 +260,11 @@ function Geom:offsetWithin(rect_b, dx, dy)
end
end
function Geom:shrinkInside(rect_b, dx, dy)
self:offsetBy(dx, dy)
return self:intersect(rect_b)
end
--[[
return the Euclidean distance between two geoms
]]--