From 2b29c702508f151a9103fb2254bf8fc7d7172fd7 Mon Sep 17 00:00:00 2001 From: chrox Date: Mon, 22 Jul 2013 21:59:22 +0800 Subject: [PATCH] fix Geom:combine when sizeof rect is zero --- frontend/ui/geometry.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/frontend/ui/geometry.lua b/frontend/ui/geometry.lua index 1331c4c01..29fce1ae2 100644 --- a/frontend/ui/geometry.lua +++ b/frontend/ui/geometry.lua @@ -74,6 +74,17 @@ function Geom:transformByScale(zx, zy) self:scaleBy(zx, zy) end +--[[ +return size of geom +]]-- +function Geom:sizeof() + if not self.w or not self.h then + return 0 + else + return self.w * self.h + end +end + --[[ enlarges or shrinks dimensions or rectangles @@ -91,7 +102,8 @@ return the outer rectangle that contains both us and a given rectangle works for rectangles, dimensions and points ]]-- function Geom:combine(rect_b) - local combined = Geom:new(self) + local combined = self:copy() + if not rect_b or rect_b:sizeof() == 0 then return combined end if combined.x > rect_b.x then combined.x = rect_b.x end