fix #1529 by rounding off the scaled dimension

pull/1662/head
chrox 9 years ago
parent f73f8916c0
commit 1f094657dc

@ -1,3 +1,4 @@
local Math = require("optmath")
local DEBUG = require("dbg") local DEBUG = require("dbg")
--[[ --[[
@ -62,8 +63,8 @@ scale rectangle (grow to bottom and to the right) or dimension
if a single factor is given, it is applied to both width and height if a single factor is given, it is applied to both width and height
]]-- ]]--
function Geom:scaleBy(zx, zy) function Geom:scaleBy(zx, zy)
self.w = self.w * zx self.w = Math.round(self.w * zx)
self.h = self.h * (zy or zx) self.h = Math.round(self.h * (zy or zx))
return self return self
end end
@ -71,8 +72,8 @@ end
this method also takes care of x and y this method also takes care of x and y
]]-- ]]--
function Geom:transformByScale(zx, zy) function Geom:transformByScale(zx, zy)
self.x = self.x * zx self.x = Math.round(self.x * zx)
self.y = self.y * (zx or zy) self.y = Math.round(self.y * (zx or zy))
self:scaleBy(zx, zy) self:scaleBy(zx, zy)
end end
@ -327,8 +328,8 @@ return the midpoint of two geoms
]]-- ]]--
function Geom:midpoint(geom) function Geom:midpoint(geom)
return Geom:new{ return Geom:new{
x = (self.x + geom.x) / 2, x = Math.round((self.x + geom.x) / 2),
y = (self.y + geom.y) / 2, y = Math.round((self.y + geom.y) / 2),
w = 0, h = 0, w = 0, h = 0,
} }
end end
@ -338,8 +339,8 @@ return center point in this geom
]]-- ]]--
function Geom:center() function Geom:center()
return Geom:new{ return Geom:new{
x = self.x + self.w / 2, x = self.x + Math.round(self.w / 2),
y = self.y + self.h / 2, y = self.y + Math.round(self.h / 2),
w = 0, h = 0, w = 0, h = 0,
} }
end end

Loading…
Cancel
Save