mirror of
https://github.com/appgurueu/modlib.git
synced 2024-12-23 05:42:28 +01:00
Add vector.distance (required by k-d-tree)
This commit is contained in:
parent
4bdd79cadc
commit
4aec592fb2
@ -134,6 +134,15 @@ function length(v)
|
||||
return math.sqrt(norm(v))
|
||||
end
|
||||
|
||||
-- Minor code duplication for the sake of performance
|
||||
function distance(v, other_v)
|
||||
local sum = 0
|
||||
for key, value in pairs(v) do
|
||||
sum = sum + (value - other_v[key]) ^ 2
|
||||
end
|
||||
return math.sqrt(sum)
|
||||
end
|
||||
|
||||
function normalize(v)
|
||||
return divide_scalar(v, length(v))
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user