mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-29 18:53:44 +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))
|
return math.sqrt(norm(v))
|
||||||
end
|
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)
|
function normalize(v)
|
||||||
return divide_scalar(v, length(v))
|
return divide_scalar(v, length(v))
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user