mirror of
https://github.com/appgurueu/modlib.git
synced 2025-02-17 00:32:35 +01:00
Add vector.distance (required by k-d-tree)
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user