mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-25 08:43:44 +01:00
Add vector.normalize_zero
This commit is contained in:
parent
71b6d9769d
commit
66315d0219
13
vector.lua
13
vector.lua
@ -162,6 +162,19 @@ function normalize(v)
|
|||||||
return divide_scalar(v, length(v))
|
return divide_scalar(v, length(v))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function normalize_zero(v)
|
||||||
|
local len = length(v)
|
||||||
|
if len == 0 then
|
||||||
|
-- Return a zeroed vector with the same keys
|
||||||
|
local zeroed = {}
|
||||||
|
for k in pairs(v) do
|
||||||
|
zeroed[k] = 0
|
||||||
|
end
|
||||||
|
return new(zeroed)
|
||||||
|
end
|
||||||
|
return divide_scalar(v, len)
|
||||||
|
end
|
||||||
|
|
||||||
function floor(v)
|
function floor(v)
|
||||||
return apply(v, math.floor)
|
return apply(v, math.floor)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user