aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorShadowNinja <noreply@gmail.com>2013-09-16 16:13:39 -0400
committerPerttu Ahola <celeron55@gmail.com>2013-10-17 09:41:01 +0300
commit12504a18ec5b76df037482ea2cf435d8c320efbc (patch)
tree2fb4a4eb9ff8c6fba02fa7c61ff088bb71e38321 /builtin
parentb3591019ad7e9bdce2a0a20cbbf64a769c1717c2 (diff)
downloadminetest-12504a18ec5b76df037482ea2cf435d8c320efbc.tar.gz
minetest-12504a18ec5b76df037482ea2cf435d8c320efbc.tar.bz2
minetest-12504a18ec5b76df037482ea2cf435d8c320efbc.zip
Remove vector metatable setting
This not only makes the vector functions faster, but also makes them more consistent with other functions.
Diffstat (limited to 'builtin')
-rw-r--r--builtin/vector.lua72
1 files changed, 27 insertions, 45 deletions
diff --git a/builtin/vector.lua b/builtin/vector.lua
index 839f139ca..7faa2c17d 100644
--- a/builtin/vector.lua
+++ b/builtin/vector.lua
@@ -2,22 +2,12 @@
vector = {}
function vector.new(a, b, c)
- v = {x=0, y=0, z=0}
if type(a) == "table" then
- v = {x=a.x, y=a.y, z=a.z}
+ return {x=a.x, y=a.y, z=a.z}
elseif a and b and c then
- v = {x=a, y=b, z=c}
+ return {x=a, y=b, z=c}
end
- setmetatable(v, {
- __add = vector.add,
- __sub = vector.subtract,
- __mul = vector.multiply,
- __div = vector.divide,
- __umn = function(v) return vector.multiply(v, -1) end,
- __len = vector.length,
- __eq = vector.equals,
- })
- return v
+ return {x=0, y=0, z=0}
end
function vector.equals(a, b)
@@ -85,57 +75,49 @@ end
function vector.add(a, b)
if type(b) == "table" then
- return vector.new(
- a.x + b.x,
- a.y + b.y,
- a.z + b.z)
+ return {x = a.x + b.x,
+ y = a.y + b.y,
+ z = a.z + b.z}
else
- return vector.new(
- a.x + b,
- a.y + b,
- a.z + b)
+ return {x = a.x + b,
+ y = a.y + b,
+ z = a.z + b}
end
end
function vector.subtract(a, b)
if type(b) == "table" then
- return vector.new(
- a.x - b.x,
- a.y - b.y,
- a.z - b.z)
+ return {x = a.x - b.x,
+ y = a.y - b.y,
+ z = a.z - b.z}
else
- return vector.new(
- a.x - b,
- a.y - b,
- a.z - b)
+ return {x = a.x - b,
+ y = a.y - b,
+ z = a.z - b}
end
end
function vector.multiply(a, b)
if type(b) == "table" then
- return vector.new(
- a.x * b.x,
- a.y * b.y,
- a.z * b.z)
+ return {x = a.x * b.x,
+ y = a.y * b.y,
+ z = a.z * b.z}
else
- return vector.new(
- a.x * b,
- a.y * b,
- a.z * b)
+ return {x = a.x * b,
+ y = a.y * b,
+ z = a.z * b}
end
end
function vector.divide(a, b)
if type(b) == "table" then
- return vector.new(
- a.x / b.x,
- a.y / b.y,
- a.z / b.z)
+ return {x = a.x / b.x,
+ y = a.y / b.y,
+ z = a.z / b.z}
else
- return vector.new(
- a.x / b,
- a.y / b,
- a.z / b)
+ return {x = a.x / b,
+ y = a.y / b,
+ z = a.z / b}
end
end