Updated vec3 doc comments. Brought vec2 in line with vec3. Doc commented vec2.

This commit is contained in:
Matthew Blanchard 2015-12-25 18:35:03 -05:00
parent 4302b2b5dc
commit c5d02e0683
7 changed files with 211 additions and 372 deletions

View File

@ -1,115 +1,259 @@
local sqrt= math.sqrt
local ffi = require "ffi"
ffi.cdef[[
typedef struct {
double x, y;
} cpml_vec2;
]]
local vec2 = {}
local cpml_vec2 = ffi.typeof("cpml_vec2")
vec2.new = cpml_vec2
function vec2.clone(a)
local out = vec2.new()
ffi.copy(out, a, ffi.sizeof(cpml_vec2))
return out
-- Private constructor.
local function new(x, y, z)
local v = {}
v.x, v.y = x, y
return setmetatable(v, vec2_mt)
end
-- Do the check to see if JIT is enabled. If so use the optimized FFI structs.
local status, ffi
if type(jit) == "table" and jit.status() then
status, ffi = pcall(require, "ffi")
if status then
ffi.cdef "typedef struct { double x, y;} cpml_vec2;"
new = ffi.typeof("cpml_vec2")
end
end
--- The public constructor.
-- @param x Can be of three types: </br>
-- number x component
-- table {x, y, z} or {x = x, y = y}
-- scalar to fill the vector eg. {x, x}
-- @tparam number y y component
function vec2.new(x, y, z)
-- number, number, number
if x and y then
assert(type(x) == "number", "new: Wrong argument type for x (<number> expected)")
assert(type(y) == "number", "new: Wrong argument type for y (<number> expected)")
return new(x, y)
-- {x=x, y=y} or {x, y}
elseif type(x) == "table" then
local x, y = x.x or x[1], x.y or x[2]
assert(type(x) == "number", "new: Wrong argument type for x (<number> expected)")
assert(type(y) == "number", "new: Wrong argument type for y (<number> expected)")
return new(x, y)
-- {x, x, x} eh. {0, 0, 0}, {3, 3, 3}
elseif type(x) == "number" then
return new(x, x)
else
return new(0, 0)
end
end
--- Clone a vector.
-- @tparam vec2 a vector to be cloned
-- @treturn vec2
function vec2.clone(a)
return new(a.x, a.y, a.z)
end
--- Add two vectors.
-- @tparam vec2 out vector to store the result
-- @tparam vec2 a Left hand operant
-- @tparam vec2 b Right hand operant
function vec2.add(out, a, b)
out.x = a.x + b.x
out.y = a.y + b.y
return out
end
--- Subtract one vector from another.
-- @tparam vec2 out vector to store the result
-- @tparam vec2 a Left hand operant
-- @tparam vec2 b Right hand operant
function vec2.sub(out, a, b)
out.x = a.x - b.x
out.y = a.y - b.y
return out
end
--- Multiply a vector by a scalar.
-- @tparam vec2 out vector to store the result
-- @tparam vec2 a Left hand operant
-- @tparam number b Right hand operant
function vec2.mul(out, a, b)
out.x = a.x * b
out.y = a.y * b
return out
end
--- Divide one vector by a scalar.
-- @tparam vec2 out vector to store the result
-- @tparam vec2 a Left hand operant
-- @tparam number b Right hand operant
function vec2.div(out, a, b)
out.x = a.x / b
out.y = a.y / b
return out
end
function vec2.cross(a, b)
return a.x * b.y - a.y * b.x
end
function vec2.dot(a, b)
return a.x * b.x + a.y * b.y
end
--- Get the normal of a vector.
-- @tparam vec2 out vector to store the result
-- @tparam vec2 a vector to normalize
function vec2.normalize(out, a)
local l = vec2.len(a)
out.x = a.x / l
out.y = a.y / l
return out
end
--- Trim a vector to a given length
-- @tparam vec2 out vector to store the result
-- @tparam vec2 a vector to be trimmed
-- @tparam number len the length to trim the vector to
function vec2.trim(out, a, len)
len = math.min(vec2.len(a), len)
vec2.normalize(out, a)
vec2.mul(out, len)
return out
end
--- Get the cross product of two vectors.
-- @tparam vec2 a Left hand operant
-- @tparam vec2 b Right hand operant
-- @tparam number
function vec2.cross(a, b)
return a.x * b.y - a.y * b.x
end
--- Get the dot product of two vectors.
-- @tparam vec2 a Left hand operant
-- @tparam vec2 b Right hand operant
-- @treturn number
function vec2.dot(a, b)
return a.x * b.x + a.y * b.y
end
--- Get the length of a vector.
-- @tparam vec2 a vector to get the length of
-- @treturn number
function vec2.len(a)
return sqrt(a.x * a.x + a.y * a.y)
end
--- Get the squared length of a vector.
-- @tparam vec2 a vector to get the squared length of
-- @treturn number
function vec2.len2(a)
return a.x * a.x + a.y * a.y
end
--- Get the distance between two vectors.
-- @tparam vec2 a first vector
-- @tparam vec2 b second vector
-- @treturn number
function vec2.dist(a, b)
local dx = a.x - b.x
local dy = a.y - b.y
return sqrt(dx * dx + dy * dy)
end
--- Get the squared distance between two vectors.
-- @tparam vec2 a first vector
-- @tparam vec2 b second vector
-- @treturn number
function vec2.dist2(a, b)
local dx = a.x - b.x
local dy = a.y - b.y
return dx * dx + dy * dy
end
function vec2.lerp(a, b, s)
return a + s * (b - a)
--- Lerp between two vectors.
-- @tparam vec3 out vector for result to be stored in
-- @tparam vec3 a first vector
-- @tparam vec3 b second vector
-- @tparam number s step value
-- @treturn vec3
function vec3.lerp(out, a, b, s)
vec2.sub(out, b, a)
vec2.mul(out, out, s)
vec2.add(out, out, a)
return out
end
--- Unpack a vector into form x,y
-- @tparam vec2 a first vector
-- @treturn number x component
-- @treturn number y component
function vec2.unpack(a)
return a.x, a.y
end
--- Return a string formatted "{x, y}"
-- @tparam vec2 a the vector to be turned into a string
-- @treturn string
function vec2.tostring(a)
return string.format("(%+0.3f,%+0.3f)", a.x, a.y)
end
--- Return a boolean showing if a table is or is not a vec2
-- @param v the object to be tested
-- @treturn boolean
function vec3.isvector(v)
return type(v) == "table" and
type(v.x) == "number" and
type(v.y) == "number"
end
local vec2_mt = {}
vec2_mt.__index = vec2
vec2_mt.__call = vec2.new
vec2_mt.__tostring = vec2.tostring
function vec2_mt.__call(self, x, y, z)
return vec2.new(x, y, z)
end
function vec2_mt.__unm(a)
return vec2.new(-a.x, -a.y)
return vec2.new(-a.x, -a.y, -a.z)
end
function vec2_mt.__eq(a,b)
return a.x == b.x and a.y == b.y
assert(vec2.isvector(a), "__eq: Wrong argument type for left hand operant. (<cpml.vec2> expected)")
assert(vec2.isvector(b), "__eq: Wrong argument type for right hand operant. (<cpml.vec2> expected)")
return a.x == b.x and a.y == b.y and a.z == b.z
end
function vec2_mt.__add(a, b)
assert(vec2.isvector(a), "__add: Wrong argument type for left hand operant. (<cpml.vec2> expected)")
assert(vec2.isvector(b), "__add: Wrong argument type for right hand operant. (<cpml.vec2> expected)")
local temp = vec2.new()
vec2.add(temp, a, b)
return temp
end
function vec2_mt.__mul(a, b)
local isvecb = vec2.isvector(b)
a, b = isvecb and b or a, isvecb and a or b
assert(vec2.isvector(a), "__mul: Wrong argument type for left hand operant. (<cpml.vec2> expected)")
assert(type(b) == "number", "__mul: Wrong argument type for right hand operant. (<number> expected)")
local temp = vec2.new()
vec2.mul(temp, a, b)
return temp
end
function vec2_mt.__div(a, b)
local isvecb = isvector(b)
a, b = isvecb and b or a, isvecb and a or b
assert(vec2.isvector(a), "__div: Wrong argument type for left hand operant. (<cpml.vec2> expected)")
assert(type(b) == "number", "__div: Wrong argument type for right hand operant. (<number> expected)")
local temp = vec2.new()
vec2.div(temp, a, b)
return temp

View File

@ -21,15 +21,14 @@ if type(jit) == "table" and jit.status() then
end
end
-- Statically allocate a temporary variable used in many of our functions.
-- Statically allocate a temporary variable used in some of our functions.
local tmp = new(0, 0, 0)
--- The public constructor.
-- @param x Can be of three types: </br>
-- <u1>
-- <li> number x component
-- <li> table {x, y, z} or {x = x, y = y, z = z}
-- <li> scalar to fill the vector eg. {x, x, x}
-- number x component
-- table {x, y, z} or {x = x, y = y, z = z}
-- scalar to fill the vector eg. {x, x, x}
-- @tparam number y y component
-- @tparam number z z component
function vec3.new(x, y, z)
@ -60,17 +59,17 @@ end
--- Clone a vector.
-- @tparam @{vec3} vec vector to be cloned
-- @treturn @{vec3}
-- @tparam vec3 a vector to be cloned
-- @treturn vec3
function vec3.clone(a)
return new(a.x, a.y, a.z)
end
--- Add two vectors.
-- @tparam @{vec3} out vector to store the result
-- @tparam @{vec3} a Left hand operant
-- @tparam @{vec3} b Right hand operant
-- @tparam vec3 out vector to store the result
-- @tparam vec3 a Left hand operant
-- @tparam vec3 b Right hand operant
function vec3.add(out, a, b)
out.x = a.x + b.x
out.y = a.y + b.y
@ -79,9 +78,9 @@ function vec3.add(out, a, b)
end
--- Subtract one vector from another.
-- @tparam @{vec3} out vector to store the result
-- @tparam @{vec3} a Left hand operant
-- @tparam @{vec3} b Right hand operant
-- @tparam vec3 out vector to store the result
-- @tparam vec3 a Left hand operant
-- @tparam vec3 b Right hand operant
function vec3.sub(out, a, b)
out.x = a.x - b.x
out.y = a.y - b.y
@ -89,10 +88,10 @@ function vec3.sub(out, a, b)
return out
end
--- Multiply two vectors.
-- @tparam @{vec3} out vector to store the result
-- @tparam @{vec3} a Left hand operant
-- @tparam @{vec3} b Right hand operant
--- Multiply a vector by a scalar.
-- @tparam vec3 out vector to store the result
-- @tparam vec3 a Left hand operant
-- @tparam number b Right hand operant
function vec3.mul(out, a, b)
out.x = a.x * b
out.y = a.y * b
@ -100,10 +99,10 @@ function vec3.mul(out, a, b)
return out
end
--- Divide one vector by another.
-- @tparam @{vec3} out vector to store the result
-- @tparam @{vec3} a Left hand operant
-- @tparam @{vec3} b Right hand operant
--- Divide a vector by a scakar.
-- @tparam vec3 out vector to store the result
-- @tparam vec3 a Left hand operant
-- @tparam number b Right hand operant
function vec3.div(out, a, b)
out.x = a.x / b
out.y = a.y / b
@ -112,9 +111,9 @@ function vec3.div(out, a, b)
end
--- Get the cross product of two vectors.
-- @tparam @{vec3} out vector to store the result
-- @tparam @{vec3} a Left hand operant
-- @tparam @{vec3} b Right hand operant
-- @tparam vec3 out vector to store the result
-- @tparam vec3 a Left hand operant
-- @tparam vec3 b Right hand operant
function vec3.cross(out, a, b)
out.x = a.y * b.z - a.z * b.y
out.y = a.z * b.x - a.x * b.z
@ -123,8 +122,8 @@ function vec3.cross(out, a, b)
end
--- Get the normal of a vector.
-- @tparam @{vec3} out vector to store the result
-- @tparam @{vec3} a vector to normalize
-- @tparam vec3 out vector to store the result
-- @tparam vec3 a vector to normalize
function vec3.normalize(out, a)
local l = vec3.len(a)
out.x = a.x / l
@ -134,8 +133,8 @@ function vec3.normalize(out, a)
end
--- Trim a vector to a given length
-- @tparam @{vec3} out vector to store the result
-- @tparam @{vec3} a vector to be trimmed
-- @tparam vec3 out vector to store the result
-- @tparam vec3 a vector to be trimmed
-- @tparam number len the length to trim the vector to
function vec3.trim(out, a, len)
len = math.min(vec3.len(a), len)
@ -164,11 +163,11 @@ end
--- Lerp between two vectors.
-- @tparam @{vec3} out vector for result to be stored in
-- @tparam @{vec3} a first vector
-- @tparam @{vec3} b second vector
-- @tparam vec3 out vector for result to be stored in
-- @tparam vec3 a first vector
-- @tparam vec3 b second vector
-- @tparam number s step value
-- @treturn @{vec3}
-- @treturn vec3
function vec3.lerp(out, a, b, s)
vec3.sub(out, b, a)
vec3.mul(out, out, s)
@ -177,30 +176,30 @@ function vec3.lerp(out, a, b, s)
end
--- Get the dot product of two vectors.
-- @tparam @{vec3} a Left hand operant
-- @tparam @{vec3} b Right hand operant
-- @tparam vec3 a Left hand operant
-- @tparam vec3 b Right hand operant
-- @treturn number
function vec3.dot(a, b)
return a.x * b.x + a.y * b.y + a.z * b.z
end
--- Get the length of a vector.
-- @tparam @{vec3} a vector to get the length of
-- @tparam vec3 a vector to get the length of
-- @treturn number
function vec3.len(a)
return sqrt(a.x * a.x + a.y * a.y + a.z * a.z)
end
--- Get the squared length of a vector.
-- @tparam @{vec3} a vector to get the squared length of
-- @tparam vec3 a vector to get the squared length of
-- @treturn number
function vec3.len2(a)
return a.x * a.x + a.y * a.y + a.z * a.z
end
--- Get the distance between two vectors.
-- @tparam @{vec3} a first vector
-- @tparam @{vec3} b second vector
-- @tparam vec3 a first vector
-- @tparam vec3 b second vector
-- @treturn number
function vec3.dist(a, b)
local dx = a.x - b.x
@ -210,8 +209,8 @@ function vec3.dist(a, b)
end
--- Get the squared distance between two vectors.
-- @tparam @{vec3} a first vector
-- @tparam @{vec3} b second vector
-- @tparam vec3 a first vector
-- @tparam vec3 b second vector
-- @treturn number
function vec3.dist2(a, b)
local dx = a.x - b.x
@ -221,7 +220,7 @@ function vec3.dist2(a, b)
end
--- Unpack a vector into form x,y,z
-- @tparam @{vec3} a first vector
-- @tparam vec3 a first vector
-- @treturn number x component
-- @treturn number y component
-- @treturn number z component
@ -230,13 +229,13 @@ function vec3.unpack(a)
end
--- Return a string formatted "{x, y, z}"
-- @tparam @{vec3} a the vector to be turned into a string
-- @tparam vec3 a the vector to be turned into a string
-- @treturn string
function vec3.tostring(a)
return string.format("(%+0.3f,%+0.3f,%+0.3f)", a.x, a.y, a.z)
end
--- Return a boolean showing if a table is or is not a vector
--- Return a boolean showing if a table is or is not a vec3
-- @param v the object to be tested
-- @treturn boolean
function vec3.isvector(v)

View File

@ -1,17 +1,4 @@
local mat4 = require "modules.mat4"
describe("mat4:", function()
it("testing basic operators", function()
end)
it("testing clone", function()
local v = mat4()
local c = v:clone()
c[1] = 2
assert.is_not.equal(v, c)
end)
describe("vec3 pending tests", function()
pending "lerp"
end)
end)

View File

@ -1,10 +1,4 @@
local quat = require "modules.quat"
describe("quat:", function()
it("testing basic operators", function()
end)
describe("vec3 pending tests", function()
pending "lerp"
end)
end)

View File

@ -2,59 +2,4 @@ local utils = require "modules.utils"
local constants = require "modules.constants"
describe("utils:", function()
it("testing clamp", function()
assert.is.equal(utils.clamp(10, 0, 5), 5)
assert.is.equal(utils.clamp(-5, 0, 5), 0)
end)
it("testing map", function()
assert.is.equal(utils.map(10, 0, 10, 0, 1), 1)
assert.is.equal(utils.map(-5, 0, 10, 0, 5), -2.5)
end)
it("testing wrap", function()
assert.is.equal(utils.wrap(-2, 6), 4)
assert.is.equal(utils.wrap(8, 6), 2)
end)
it("testing is_pot", function()
assert.is_true(utils.is_pot(1))
assert.is_true(utils.is_pot(8))
assert.is_true(utils.is_pot(16384))
assert.is_false(utils.is_pot(7))
assert.is_false(utils.is_pot(-22))
assert.is_false(utils.is_pot(54812))
end)
it("testing round", function()
assert.is.equal(utils.round(5.3), 5)
assert.is.equal(utils.round(5.8), 6)
-- comparing floats is annoying...
assert.is.is_true(math.abs(utils.round(5.5555, 0.1) - 5.6) < constants.FLT_EPSILON)
end)
it("testing deadzone", function()
assert.is.equal(utils.deadzone(0.5, 0.05), 0.5)
assert.is.equal(utils.deadzone(0.02, 0.05), 0.0)
assert.is.equal(utils.deadzone(-0.1, 0.02), -0.1)
end)
it("testing threshold", function()
assert.is_true(utils.threshold(0.5, 0.25))
assert.is_true(utils.threshold(0.25, 0.25))
assert.is_false(utils.threshold(-0.1, 0.5))
assert.is_true(utils.threshold(-0.25, 0.1))
end)
it("testing lerp", function()
local l = 0.5
local h = 20.0
assert.is.equal(utils.lerp(0, l, h), l)
assert.is.equal(utils.lerp(1, l, h), h)
assert.is.equal(utils.lerp(0.5, l, h), (l+h)/2)
end)
pending "smoothstep"
end)

View File

@ -1,112 +1,4 @@
local constants = require "modules.constants"
local vec2 = require "modules.vec2"
describe("vec2:", function()
it("testing basic operators", function()
-- add
assert.is.equal(vec2(1, 1) + vec2(2, 3), vec2(3, 4))
assert.is.equal(vec2(1, 1) + 5, vec2(6, 6))
-- sub
assert.is.equal(vec2(1, 1) - vec2(2, 3), vec2(-1, -2))
assert.is.equal(vec2(1, 1) - 5, vec2(-4, -4))
-- mul
assert.is.equal(vec2(2, 1) * vec2(2, 3), vec2(4, 3))
assert.has_no.errors(function() return vec2(1,1) * {x=2,y=2} end)
assert.has_no.errors(function() return 2 * vec2(1,1) end)
assert.has_no.errors(function() return vec2(1,1) * 2 end)
-- unm
assert.is.equal(vec2(1, 1) + -vec2(1, 1), vec2(0, 0))
-- div
assert.is.equal(vec2(1, 1) / 2, vec2(0.5, 0.5))
assert.is.equal(vec2(1, 1) / vec2(2, 2), vec2(0.5, 0.5))
assert.is.equal(1 / vec2(2, 2), vec2(0.5, 0.5))
end)
it("testing value ranges", function()
-- This makes sure we are initializing reasonably and that
-- we haven't broken everything with some FFI magic.
assert.is.equal(vec2(256, 0).x, 256)
assert.is.equal(vec2(0, 65537).y, 65537)
assert.is.equal(vec2(-953, 0).x, -953)
assert.is.equal(vec2(0, 1.2222).y, 1.2222)
end)
it("testing comparison operators", function()
-- eq
assert.is_true(vec2(5,5) == vec2(5,5))
-- lt
assert.is_true(vec2(3,3) < vec2(5,5))
assert.is_false(vec2(5,5) < vec2(5,5))
-- le
assert.is_true(vec2(5,5) <= vec2(5,5))
assert.is_false(vec2(3,3) >= vec2(5,5))
end)
it("testing new", function()
local v = vec2()
assert.is_true(v.x == 0)
assert.is_true(v.y == 0)
v = vec2{1, 2}
assert.is_true(v.x == 1)
assert.is_true(v.y == 2)
v = vec2(4, 5)
assert.is_true(v.x == 4)
assert.is_true(v.y == 5)
end)
it("testing tostring", function()
assert.has_no.errors(function() return tostring(vec2(1,1)) end)
end)
it("testing isvector", function()
assert.is_true(vec2.isvector(vec2()))
assert.is_true(vec2.isvector(vec2{1,1}))
assert.is_true(vec2.isvector{x=1, y=2})
end)
it("testing clone", function()
local v = vec2(1,1)
local c = v:clone()
c.x = 2
assert.is_not.equal(v, c)
end)
it("testing len and normalize", function()
assert.is.equal(vec2(1,0):len(), 1)
assert.is_true(vec2(5,-10):normalize():len() - 1 < constants.FLT_EPSILON)
end)
it("testing len2", function()
assert.is.equal(vec2(1,0):len2(), 1)
assert.is.equal(vec2(2,0):len2(), 4)
end)
it("testing lerp", function()
assert.is.equal(vec2(0, 0):lerp(vec2(1, 1), 0.5), vec2(0.5, 0.5))
end)
describe("vec2 pending tests", function()
pending "rotate"
pending "dot"
pending "cross"
pending "trim"
pending "angle_to"
pending "angle_between"
pending "mirror_on"
pending "orientation_to_direction"
pending "project_from"
pending "project_on"
pending "perpendicular"
pending "rotate"
pending "dist"
pending "dist2"
end)
end)

View File

@ -1,126 +1,4 @@
local vec3 = require "modules.vec3"
describe("vec3:", function()
it("testing basic operators", function()
-- add
assert.is.equal(vec3(1, 1, 1) + vec3(2, 3, 4), vec3(3, 4, 5))
assert.is.equal(vec3(1, 1, 1) + 5, vec3(6, 6, 6))
-- sub
assert.is.equal(vec3(1, 1, 1) - vec3(2, 3, 4), vec3(-1, -2, -3))
assert.is.equal(vec3(1, 1, 1) - 5, vec3(-4, -4, -4))
-- mul
assert.is.equal(vec3(2, 1, 2) * vec3(2, 3, 4), vec3(4, 3, 8))
assert.has_no.errors(function() return vec3(1,1,1) * {x=2,y=2,z=2} end)
assert.has_no.errors(function() return 2 * vec3(1,1,1) end)
assert.has_no.errors(function() return vec3(1,1,1) * 2 end)
-- unm
assert.is.equal(vec3(1, 1, 1) + -vec3(1, 1, 1), vec3(0, 0, 0))
-- div
assert.is.equal(vec3(1, 1, 1) / 2, vec3(0.5, 0.5, 0.5))
assert.is.equal(vec3(1, 1, 1) / vec3(2, 2, 2), vec3(0.5, 0.5, 0.5))
assert.is.equal(1 / vec3(2, 2, 2), vec3(0.5, 0.5, 0.5))
end)
it("testing value ranges", function()
-- This makes sure we are initializing reasonably and that
-- we haven't broken everything with some FFI magic.
assert.is.equal(vec3(256, 0, 0).x, 256)
assert.is.equal(vec3(0, 65537, 0).y, 65537)
assert.is.equal(vec3(953, 0, 491.5).z, 491.5)
assert.is.equal(vec3(0, 1.2222, 0).y, 1.2222)
end)
it("testing comparison operators", function()
-- eq
assert.is_true(vec3(5,5,5) == vec3(5,5,5))
-- lt
assert.is_true(vec3(3,3,3) < vec3(5,5,5))
assert.is_false(vec3(5,5,5) < vec3(5,5,5))
-- le
assert.is_true(vec3(5,5,5) <= vec3(5,5,5))
assert.is_false(vec3(3,3,3) >= vec3(5,5,5))
end)
it("testing new", function()
local v = vec3()
assert.is_true(v.x == 0)
assert.is_true(v.y == 0)
assert.is_true(v.z == 0)
v = vec3{1, 2, 3}
assert.is_true(v.x == 1)
assert.is_true(v.y == 2)
assert.is_true(v.z == 3)
v = vec3(4, 5, 6)
assert.is_true(v.x == 4)
assert.is_true(v.y == 5)
assert.is_true(v.z == 6)
end)
it("testing tostring", function()
assert.has_no.errors(function() return tostring(vec3(1,1,1)) end)
end)
it("testing isvector", function()
assert.is_true(vec3.isvector(vec3()))
assert.is_true(vec3.isvector(vec3{1,1}))
assert.is_true(vec3.isvector{x=1, y=2, z=3})
end)
it("testing clone", function()
local v = vec3(1,1,1)
local c = v:clone()
c.x = 2
assert.is_not.equal(v, c)
end)
it("testing dot", function()
assert.is.equal(vec3(5,10,-5):dot(vec3(3,1,1)), 20)
assert.is.equal(vec3(2,-1,2):dot(vec3(1,2,1)), 2)
assert.is.equal(vec3(5,5,5):dot(vec3(5,5,5)), 75)
end)
it("testing cross", function()
assert.is.equal(vec3.unit_x:cross(vec3.unit_y), vec3.unit_z)
end)
it("testing len and normalize", function()
assert.is.equal(vec3(1,0,0):len(), 1)
assert.is.equal(vec3(5,-10,9):normalize():len(), 1)
end)
it("testing len2", function()
assert.is.equal(vec3(1,0,0):len2(), 1)
assert.is.equal(vec3(2,0,2):len2(), 8)
end)
it("testing lerp", function()
assert.is.equal(vec3(0, 0, 0):lerp(vec3(1, 1, 1), 0.5), vec3(0.5, 0.5, 0.5))
end)
it("testing rotate", function()
local t = 1.0e-15
assert.is_true(vec3(1,0,0):rotate(math.pi, vec3.unit_z) - vec3(-1, 0, 0) < vec3(t, t, t))
end)
describe("vec3 pending tests", function()
pending "trim"
pending "angle_to"
pending "angle_between"
pending "mirror_on"
pending "orientation_to_direction"
pending "project_from"
pending "project_on"
pending "perpendicular"
pending "rotate"
pending "dist"
pending "dist2"
end)
end)