Skip to content

Commit

Permalink
Compatibility note for 1.0 release and PR#48 test
Browse files Browse the repository at this point in the history
  • Loading branch information
mcclure committed May 3, 2020
1 parent 1000f1d commit ddb80f4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ Clone the repository and require it, or if you prefer luarocks: `$ luarocks inst

# Versions

This library has a major compatibility break at version 1.0. Up to version 0.10, composition a*b means "apply b, then a" for quaternions and "apply a, then b" for matrices. Starting with version 1.0, the two are consistent and matrix a*b means "apply b, then a".
This library has a major compatibility break at version 1.0. Up to version 0.10, composition a*b means "apply b, then a" for quaternions and "apply a, then b" for matrices. Now as of version 1.0, the two are consistent and matrix a*b means "apply b, then a".
26 changes: 26 additions & 0 deletions spec/mat4_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,32 @@ describe("mat4:", function()
assert.is.equal(c[4], d[4])
end)

it("verifies mat4 composition order", function()
local a = mat4 {
1, 5, 9, 13,
2, 6, 10, 14,
3, 7, 11, 15,
4, 8, 12, 16
}
local b = mat4 {
2, 3, 5, 7,
11, 13, 17, 19,
23, 29, 31, 37,
41, 43, 47, 53
}
local c = mat4():mul(a, b)
local d = a * b

local v = { 10, 20, 30, 40 }

local cv = c * v
local abv = a*(b*v)

assert.is.equal(cv.x, abv.x) -- Verify (a*b)*v == a*(b*v)
assert.is.equal(cv.y, abv.y)
assert.is.equal(cv.z, abv.z)
end)

it("scales a matrix", function()
local a = mat4():scale(mat4(), vec3(5, 5, 5))
assert.is.equal(5, a[1])
Expand Down
14 changes: 14 additions & 0 deletions spec/quat_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local quat = require "modules.quat"
local vec3 = require "modules.vec3"
local utils = require "modules.utils"
local constants = require "modules.constants"

describe("quat:", function()
it("creates an identity quaternion", function()
Expand Down Expand Up @@ -125,6 +126,19 @@ describe("quat:", function()
assert.is.equal(b, c)
end)

it("verifies quat composition order", function()
local a = quat(2, 3, 4, 1):normalize() -- Only the normal quaternions represent rotations
local b = quat(3, 6, 9, 1):normalize()
local c = a * b

local v = vec3(3, 4, 5)

local cv = c * v
local abv = a * (b * v)

assert.is_true((abv - cv):len() < 1e-07) -- Verify (a*b)*v == a*(b*v) within an epsilon
end)

it("multiplies a quaternion by an exponent of 0", function()
local a = quat(2, 3, 4, 1):normalize()
local e = 0
Expand Down

0 comments on commit ddb80f4

Please sign in to comment.