diff --git a/vector.lua b/vector.lua index 978e51c..4446718 100644 --- a/vector.lua +++ b/vector.lua @@ -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