Remove vector assertions
These were initially added to get tracebacks for invalid vector errors, but it didn't work and tracebacks have since been properly fixed in the core.
This commit is contained in:
parent
f0db6c4423
commit
33ca115ae4
|
@ -1,10 +1,6 @@
|
||||||
|
|
||||||
vector = {}
|
vector = {}
|
||||||
|
|
||||||
local function assert_vector(v)
|
|
||||||
assert(type(v) == "table" and v.x and v.y and v.z, "Invalid vector")
|
|
||||||
end
|
|
||||||
|
|
||||||
function vector.new(a, b, c)
|
function vector.new(a, b, c)
|
||||||
if type(a) == "table" then
|
if type(a) == "table" then
|
||||||
assert(a.x and a.y and a.z, "Invalid vector passed to vector.new()")
|
assert(a.x and a.y and a.z, "Invalid vector passed to vector.new()")
|
||||||
|
@ -17,20 +13,16 @@ function vector.new(a, b, c)
|
||||||
end
|
end
|
||||||
|
|
||||||
function vector.equals(a, b)
|
function vector.equals(a, b)
|
||||||
assert_vector(a)
|
|
||||||
assert_vector(b)
|
|
||||||
return a.x == b.x and
|
return a.x == b.x and
|
||||||
a.y == b.y and
|
a.y == b.y and
|
||||||
a.z == b.z
|
a.z == b.z
|
||||||
end
|
end
|
||||||
|
|
||||||
function vector.length(v)
|
function vector.length(v)
|
||||||
assert_vector(v)
|
|
||||||
return math.hypot(v.x, math.hypot(v.y, v.z))
|
return math.hypot(v.x, math.hypot(v.y, v.z))
|
||||||
end
|
end
|
||||||
|
|
||||||
function vector.normalize(v)
|
function vector.normalize(v)
|
||||||
assert_vector(v)
|
|
||||||
local len = vector.length(v)
|
local len = vector.length(v)
|
||||||
if len == 0 then
|
if len == 0 then
|
||||||
return {x=0, y=0, z=0}
|
return {x=0, y=0, z=0}
|
||||||
|
@ -40,7 +32,6 @@ function vector.normalize(v)
|
||||||
end
|
end
|
||||||
|
|
||||||
function vector.round(v)
|
function vector.round(v)
|
||||||
assert_vector(v)
|
|
||||||
return {
|
return {
|
||||||
x = math.floor(v.x + 0.5),
|
x = math.floor(v.x + 0.5),
|
||||||
y = math.floor(v.y + 0.5),
|
y = math.floor(v.y + 0.5),
|
||||||
|
@ -49,8 +40,6 @@ function vector.round(v)
|
||||||
end
|
end
|
||||||
|
|
||||||
function vector.distance(a, b)
|
function vector.distance(a, b)
|
||||||
assert_vector(a)
|
|
||||||
assert_vector(b)
|
|
||||||
local x = a.x - b.x
|
local x = a.x - b.x
|
||||||
local y = a.y - b.y
|
local y = a.y - b.y
|
||||||
local z = a.z - b.z
|
local z = a.z - b.z
|
||||||
|
@ -58,8 +47,6 @@ function vector.distance(a, b)
|
||||||
end
|
end
|
||||||
|
|
||||||
function vector.direction(pos1, pos2)
|
function vector.direction(pos1, pos2)
|
||||||
assert_vector(pos1)
|
|
||||||
assert_vector(pos2)
|
|
||||||
local x_raw = pos2.x - pos1.x
|
local x_raw = pos2.x - pos1.x
|
||||||
local y_raw = pos2.y - pos1.y
|
local y_raw = pos2.y - pos1.y
|
||||||
local z_raw = pos2.z - pos1.z
|
local z_raw = pos2.z - pos1.z
|
||||||
|
@ -89,9 +76,7 @@ end
|
||||||
|
|
||||||
|
|
||||||
function vector.add(a, b)
|
function vector.add(a, b)
|
||||||
assert_vector(a)
|
|
||||||
if type(b) == "table" then
|
if type(b) == "table" then
|
||||||
assert_vector(b)
|
|
||||||
return {x = a.x + b.x,
|
return {x = a.x + b.x,
|
||||||
y = a.y + b.y,
|
y = a.y + b.y,
|
||||||
z = a.z + b.z}
|
z = a.z + b.z}
|
||||||
|
@ -103,9 +88,7 @@ function vector.add(a, b)
|
||||||
end
|
end
|
||||||
|
|
||||||
function vector.subtract(a, b)
|
function vector.subtract(a, b)
|
||||||
assert_vector(a)
|
|
||||||
if type(b) == "table" then
|
if type(b) == "table" then
|
||||||
assert_vector(b)
|
|
||||||
return {x = a.x - b.x,
|
return {x = a.x - b.x,
|
||||||
y = a.y - b.y,
|
y = a.y - b.y,
|
||||||
z = a.z - b.z}
|
z = a.z - b.z}
|
||||||
|
@ -117,9 +100,7 @@ function vector.subtract(a, b)
|
||||||
end
|
end
|
||||||
|
|
||||||
function vector.multiply(a, b)
|
function vector.multiply(a, b)
|
||||||
assert_vector(a)
|
|
||||||
if type(b) == "table" then
|
if type(b) == "table" then
|
||||||
assert_vector(b)
|
|
||||||
return {x = a.x * b.x,
|
return {x = a.x * b.x,
|
||||||
y = a.y * b.y,
|
y = a.y * b.y,
|
||||||
z = a.z * b.z}
|
z = a.z * b.z}
|
||||||
|
@ -131,9 +112,7 @@ function vector.multiply(a, b)
|
||||||
end
|
end
|
||||||
|
|
||||||
function vector.divide(a, b)
|
function vector.divide(a, b)
|
||||||
assert_vector(a)
|
|
||||||
if type(b) == "table" then
|
if type(b) == "table" then
|
||||||
assert_vector(b)
|
|
||||||
return {x = a.x / b.x,
|
return {x = a.x / b.x,
|
||||||
y = a.y / b.y,
|
y = a.y / b.y,
|
||||||
z = a.z / b.z}
|
z = a.z / b.z}
|
||||||
|
|
Loading…
Reference in New Issue