Quaternions: Add tests for component-wise to_angle_axis and from_angle_axis

This commit is contained in:
mcc 2018-01-26 21:05:03 -05:00
parent d4fb346f0c
commit a41af4702b

View File

@ -279,6 +279,13 @@ describe("quat:", function()
assert.is.equal(vec3.unit_z, axis)
end)
it("converts between a quaternion and angle/axis (specify by component)", function()
local a = quat.from_angle_axis(math.pi, vec3.unit_z.x, vec3.unit_z.y, vec3.unit_z.z)
local angle, axis = a:to_angle_axis()
assert.is.equal(math.pi, angle)
assert.is.equal(vec3.unit_z, axis)
end)
it("converts between a quaternion and angle/axis (w=2)", function()
local angle, axis = quat(1, 1, 1, 2):to_angle_axis()
assert.is_true(utils.tolerance(1.427-angle, 0.001))
@ -287,6 +294,14 @@ describe("quat:", function()
assert.is_true(utils.tolerance(0.577-axis.z, 0.001))
end)
it("converts between a quaternion and angle/axis (w=2) (by component)", function()
local angle, x,y,z = quat(1, 1, 1, 2):to_angle_axis_unpack()
assert.is_true(utils.tolerance(1.427-angle, 0.001))
assert.is_true(utils.tolerance(0.577-x, 0.001))
assert.is_true(utils.tolerance(0.577-y, 0.001))
assert.is_true(utils.tolerance(0.577-z, 0.001))
end)
it("converts between a quaternion and angle/axis (w=1)", function()
local angle, axis = quat(1, 2, 3, 1):to_angle_axis()
assert.is.equal(0, angle)