mirror of
https://github.com/vrld/hump.git
synced 2024-11-23 12:24:19 +00:00
Merge pull request #17 from ricardozanini/master
Truncate Function on Vector Module
This commit is contained in:
commit
5cecfac51a
@ -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 {
|
||||
|
18
vector.lua
18
vector.lua
@ -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},
|
||||
|
Loading…
Reference in New Issue
Block a user