1 /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
3 Redistribution and use in source and binary forms, with or without modification,
4 are permitted provided that the following conditions are met:
6 * Redistributions of source code must retain the above copyright notice, this
7 list of conditions and the following disclaimer.
8 * Redistributions in binary form must reproduce the above copyright notice,
9 this list of conditions and the following disclaimer in the documentation
10 and/or other materials provided with the distribution.
12 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
16 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
23 describe("mat3", function() {
24 var out, matA, matB, identity, result;
26 beforeEach(function() {
44 describe("fromMat4", function() {
45 beforeEach(function() {
46 result = mat3.fromMat4(out, [ 1, 2, 3, 4,
51 it("should return out", function() { expect(result).toBe(out); });
53 it("should calculate proper mat3", function() {
54 expect(out).toBeEqualish([ 1, 2, 3,
60 describe("create", function() {
61 beforeEach(function() { result = mat3.create(); });
62 it("should return a 9 element array initialized to a 3x3 identity matrix", function() { expect(result).toBeEqualish(identity); });
65 describe("clone", function() {
66 beforeEach(function() { result = mat3.clone(matA); });
67 it("should return a 9 element array initialized to the values in matA", function() { expect(result).toBeEqualish(matA); });
70 describe("copy", function() {
71 beforeEach(function() { result = mat3.copy(out, matA); });
72 it("should place values into out", function() { expect(out).toBeEqualish(matA); });
73 it("should return out", function() { expect(result).toBe(out); });
76 describe("identity", function() {
77 beforeEach(function() { result = mat3.identity(out); });
78 it("should place values into out", function() { expect(result).toBeEqualish(identity); });
79 it("should return out", function() { expect(result).toBe(out); });
82 describe("transpose", function() {
83 describe("with a separate output matrix", function() {
84 beforeEach(function() { result = mat3.transpose(out, matA); });
86 it("should place values into out", function() {
87 expect(out).toBeEqualish([
93 it("should return out", function() { expect(result).toBe(out); });
94 it("should not modify matA", function() {
95 expect(matA).toBeEqualish([
103 describe("when matA is the output matrix", function() {
104 beforeEach(function() { result = mat3.transpose(matA, matA); });
106 it("should place values into matA", function() {
107 expect(matA).toBeEqualish([
113 it("should return matA", function() { expect(result).toBe(matA); });
117 describe("invert", function() {
118 describe("with a separate output matrix", function() {
119 beforeEach(function() { result = mat3.invert(out, matA); });
121 it("should place values into out", function() {
122 expect(out).toBeEqualish([
128 it("should return out", function() { expect(result).toBe(out); });
129 it("should not modify matA", function() {
130 expect(matA).toBeEqualish([
138 describe("when matA is the output matrix", function() {
139 beforeEach(function() { result = mat3.invert(matA, matA); });
141 it("should place values into matA", function() {
142 expect(matA).toBeEqualish([
148 it("should return matA", function() { expect(result).toBe(matA); });
152 describe("adjoint", function() {
153 describe("with a separate output matrix", function() {
154 beforeEach(function() { result = mat3.adjoint(out, matA); });
156 it("should place values into out", function() {
157 expect(out).toBeEqualish([
163 it("should return out", function() { expect(result).toBe(out); });
164 it("should not modify matA", function() {
165 expect(matA).toBeEqualish([
173 describe("when matA is the output matrix", function() {
174 beforeEach(function() { result = mat3.adjoint(matA, matA); });
176 it("should place values into matA", function() {
177 expect(matA).toBeEqualish([
183 it("should return matA", function() { expect(result).toBe(matA); });
187 describe("determinant", function() {
188 beforeEach(function() { result = mat3.determinant(matA); });
190 it("should return the determinant", function() { expect(result).toEqual(1); });
193 describe("multiply", function() {
194 it("should have an alias called 'mul'", function() { expect(mat3.mul).toEqual(mat3.multiply); });
196 describe("with a separate output matrix", function() {
197 beforeEach(function() { result = mat3.multiply(out, matA, matB); });
199 it("should place values into out", function() {
200 expect(out).toBeEqualish([
206 it("should return out", function() { expect(result).toBe(out); });
207 it("should not modify matA", function() {
208 expect(matA).toBeEqualish([
214 it("should not modify matB", function() {
215 expect(matB).toBeEqualish([
223 describe("when matA is the output matrix", function() {
224 beforeEach(function() { result = mat3.multiply(matA, matA, matB); });
226 it("should place values into matA", function() {
227 expect(matA).toBeEqualish([
233 it("should return matA", function() { expect(result).toBe(matA); });
234 it("should not modify matB", function() {
235 expect(matB).toBeEqualish([
243 describe("when matB is the output matrix", function() {
244 beforeEach(function() { result = mat3.multiply(matB, matA, matB); });
246 it("should place values into matB", function() {
247 expect(matB).toBeEqualish([
253 it("should return matB", function() { expect(result).toBe(matB); });
254 it("should not modify matA", function() {
255 expect(matA).toBeEqualish([
264 describe("str", function() {
265 beforeEach(function() { result = mat3.str(matA); });
267 it("should return a string representation of the matrix", function() { expect(result).toEqual("mat3(1, 0, 0, 0, 1, 0, 1, 2, 1)"); });