Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion spec/gl-matrix/mat2-spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as mat2 from "../../src/mat2.js"

describe("mat2", function() {
let out, matA, matB, identity, result;
let out, matA, matB, identity, nonInvertible, result;

beforeEach(function() {
matA = [1, 2,
Expand All @@ -13,6 +13,9 @@ describe("mat2", function() {
out = [0, 0,
0, 0];

nonInvertible = [1, 0,
1, 0];

identity = [1, 0,
0, 1];
});
Expand Down Expand Up @@ -71,6 +74,12 @@ describe("mat2", function() {
it("should place values into matA", function() { expect(matA).toBeEqualish([-2, 1, 1.5, -0.5]); });
it("should return matA", function() { expect(result).toBe(matA); });
});

describe("when matrix is not invertible", function() {
beforeEach(function() { result = mat2.invert(out, nonInvertible); });

it("should return null", function() { expect(result).toBe(null); });
});
});

describe("adjoint", function() {
Expand Down
12 changes: 11 additions & 1 deletion spec/gl-matrix/mat2d-spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as mat2d from "../../src/mat2d.js"

describe("mat2d", function() {
let out, matA, matB, oldA, oldB, identity, result;
let out, matA, matB, oldA, oldB, identity, nonInvertible, result;

beforeEach(function() {
matA = [1, 2,
Expand All @@ -27,6 +27,10 @@ describe("mat2d", function() {
identity = [1, 0,
0, 1,
0, 0];

nonInvertible = [1, 0,
1, 0,
1, 0];
});

describe("create", function() {
Expand Down Expand Up @@ -66,6 +70,12 @@ describe("mat2d", function() {
it("should place values into matA", function() { expect(matA).toBeEqualish([ -2, 1, 1.5, -0.5, 1, -2 ]); });
it("should return matA", function() { expect(result).toBe(matA); });
});

describe("when matrix is not invertible", function() {
beforeEach(function() { result = mat2d.invert(out, nonInvertible); });

it("should return null", function() { expect(result).toBe(null); });
});
});

describe("determinant", function() {
Expand Down
12 changes: 11 additions & 1 deletion spec/gl-matrix/mat3-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as mat4 from "../../src/mat4.js"
import * as vec3 from "../../src/vec3.js"

describe("mat3", function() {
let out, matA, matB, identity, result;
let out, matA, matB, identity, nonInvertible, result;

beforeEach(function() {
matA = [1, 0, 0,
Expand All @@ -21,6 +21,10 @@ describe("mat3", function() {
identity = [1, 0, 0,
0, 1, 0,
0, 0, 1];

nonInvertible = [1, 2, 3,
1, 2, 3,
1, 2, 3];
});

describe("normalFromMat4", function() {
Expand Down Expand Up @@ -199,6 +203,12 @@ describe("mat3", function() {
});
it("should return matA", function() { expect(result).toBe(matA); });
});

describe("when matrix is not invertible", function() {
beforeEach(function() { result = mat3.invert(out, nonInvertible); });

it("should return null", function() { expect(result).toBe(null); });
});
});

describe("adjoint", function() {
Expand Down
13 changes: 12 additions & 1 deletion spec/gl-matrix/mat4-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as vec3 from "../../src/vec3.js"

function buildMat4Tests() {
return function() {
let out, matA, matB, identity, result;
let out, matA, matB, identity, nonInvertible, result;

beforeEach(function() {
// Attempting to portray a semi-realistic transform matrix
Expand All @@ -28,6 +28,11 @@ function buildMat4Tests() {
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1]);

nonInvertible = new Float32Array([1, 2, 3, 4,
1, 2, 3, 4,
1, 2, 3, 4,
1, 2, 3, 4]);
});

describe("create", function() {
Expand Down Expand Up @@ -126,6 +131,12 @@ function buildMat4Tests() {
});
it("should return matA", function() { expect(result).toBe(matA); });
});

describe("when matrix is not invertible", function() {
beforeEach(function() { result = mat4.invert(out, nonInvertible); });

it("should return null", function() { expect(result).toBe(null); });
});
});

describe("adjoint", function() {
Expand Down
2 changes: 1 addition & 1 deletion src/mat2.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export function transpose(out, a) {
*
* @param {mat2} out the receiving matrix
* @param {ReadonlyMat2} a the source matrix
* @returns {mat2} out
* @returns {mat2 | null} out, or null if source matrix is not invertible
*/
export function invert(out, a) {
let a0 = a[0],
Expand Down
2 changes: 1 addition & 1 deletion src/mat2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export function set(out, a, b, c, d, tx, ty) {
*
* @param {mat2d} out the receiving matrix
* @param {ReadonlyMat2d} a the source matrix
* @returns {mat2d} out
* @returns {mat2d | null} out, or null if source matrix is not invertible
*/
export function invert(out, a) {
let aa = a[0],
Expand Down
2 changes: 1 addition & 1 deletion src/mat3.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export function transpose(out, a) {
*
* @param {mat3} out the receiving matrix
* @param {ReadonlyMat3} a the source matrix
* @returns {mat3} out
* @returns {mat3 | null} out, or null if source matrix is not invertible
*/
export function invert(out, a) {
let a00 = a[0],
Expand Down
2 changes: 1 addition & 1 deletion src/mat4.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export function transpose(out, a) {
*
* @param {mat4} out the receiving matrix
* @param {ReadonlyMat4} a the source matrix
* @returns {mat4} out
* @returns {mat4 | null} out, or null if source matrix is not invertible
*/
export function invert(out, a) {
let a00 = a[0],
Expand Down