From ddb80f48e6a3f7d9b98aa45b6feeb461db3d0c6a Mon Sep 17 00:00:00 2001 From: mcc Date: Sun, 3 May 2020 13:36:26 -0400 Subject: [PATCH] Compatibility note for 1.0 release and PR#48 test --- README.md | 2 +- spec/mat4_spec.lua | 26 ++++++++++++++++++++++++++ spec/quat_spec.lua | 14 ++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 15a5503..92c1d53 100644 --- a/README.md +++ b/README.md @@ -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". diff --git a/spec/mat4_spec.lua b/spec/mat4_spec.lua index eecee4a..5473fcd 100644 --- a/spec/mat4_spec.lua +++ b/spec/mat4_spec.lua @@ -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]) diff --git a/spec/quat_spec.lua b/spec/quat_spec.lua index 9867dc8..a85297b 100644 --- a/spec/quat_spec.lua +++ b/spec/quat_spec.lua @@ -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() @@ -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