aboutsummaryrefslogtreecommitdiff
path: root/builtin/common/vector.lua
diff options
context:
space:
mode:
authorLean Rada <godffrey0@gmail.com>2021-08-28 02:22:35 +0800
committerGitHub <noreply@github.com>2021-08-27 20:22:35 +0200
commitd36dca3aba34e989eec6686660c0490548baad67 (patch)
tree2a331065267baf52ee6301e4d6c006a82dda8ce4 /builtin/common/vector.lua
parenta7188bd6f55993d9ca6075b0b6a462c1e7e06412 (diff)
downloadhax-minetest-server-d36dca3aba34e989eec6686660c0490548baad67.tar.gz
hax-minetest-server-d36dca3aba34e989eec6686660c0490548baad67.zip
Optimize vector length calculations (#11549)
Diffstat (limited to '')
-rw-r--r--builtin/common/vector.lua4
1 files changed, 2 insertions, 2 deletions
diff --git a/builtin/common/vector.lua b/builtin/common/vector.lua
index cbaa872dc..752167a63 100644
--- a/builtin/common/vector.lua
+++ b/builtin/common/vector.lua
@@ -67,7 +67,7 @@ metatable.__eq = vector.equals
-- unary operations
function vector.length(v)
- return math.hypot(v.x, math.hypot(v.y, v.z))
+ return math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z)
end
-- Note: we can not use __len because it is already used for primitive table length
@@ -104,7 +104,7 @@ function vector.distance(a, b)
local x = a.x - b.x
local y = a.y - b.y
local z = a.z - b.z
- return math.hypot(x, math.hypot(y, z))
+ return math.sqrt(x * x + y * y + z * z)
end
function vector.direction(pos1, pos2)