Merge pull request #17 from ricardozanini/master

Truncate Function on Vector Module
This commit is contained in:
vrld 2013-04-27 03:15:27 -07:00
commit 5cecfac51a
2 changed files with 31 additions and 0 deletions

View File

@ -109,6 +109,19 @@ local function mirror(x,y, u,v)
return s*u - x, s*v - y
end
-- ref.: http://blog.signalsondisplay.com/?p=336
local function truncate(maxLen)
local s
s = maxLen / len()
if s < 1 then s = 1 end
x = x * s
y = y * s
return x,y
end
-- the module
return {

View File

@ -158,6 +158,24 @@ function vector:cross(v)
return self.x * v.y - self.y * v.x
end
-- ref.: http://blog.signalsondisplay.com/?p=336
function vector:truncate_inplace(maxLen)
local s
s = maxLen / self:len()
if s < 1 then s = 1 end
self.x = self.x * s
self.y = self.y * s
return self
end
function vector:truncate(maxLen)
return self:clone():truncate_inplace(maxLen)
end
-- the module
return setmetatable({new = new, isvector = isvector},