-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Started to use Require.js for the unit testing projects
- Completely changing the structure of the project using prototype, this way allows for code assist! - Adding new objects for Matrix22 and Matrix44 - Better naming conventions for the objects - Fixed the return / function chaining problem, now should work better
- Loading branch information
1 parent
1478894
commit 7b93943
Showing
13 changed files
with
391 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
/** | ||
* @author CrashTheuniversE | ||
*/ | ||
|
||
/** | ||
* Matrix22 class | ||
*/ | ||
MW.Matrix22 = function() { | ||
|
||
this.rows = 2; | ||
this.cols = 2; | ||
this.m = new Array(4); | ||
} | ||
|
||
MW.Matrix22.prototype.identity = function() { | ||
this.m[0] = 1.0; this.m[1] = 0.0; | ||
this.m[2] = 0.0; this.m[3] = 1.0; | ||
return this; | ||
} | ||
|
||
MW.Matrix22.prototype.zero = function() { | ||
for (var i = 0; i < this.m.length; ++i) { | ||
this.m[i] = 0.0; | ||
} | ||
return this; | ||
} | ||
|
||
MW.Matrix22.prototype.determinant = function() { | ||
var det = this.m[0] * this.m[3] - this.m[1] * this.m[2]; | ||
return det; | ||
} | ||
|
||
MW.Matrix22.prototype.trace = function() { | ||
var t = this.m[0] + this.m[3]; | ||
return t; | ||
} | ||
|
||
MW.Matrix22.prototype.scale = function(sx, sy) { | ||
this.m[0] *= sx; | ||
this.m[3] *= sy; | ||
return this; | ||
} | ||
|
||
MW.Matrix22.prototype.copy = function(mtx) { | ||
for (var i = 0; i < this.m.length; ++i) { | ||
this.m[i] = mtx.m[i]; | ||
} | ||
return this; | ||
} | ||
|
||
MW.Matrix22.prototype.transpose = function() { | ||
for (var i = 0; i < this.rows; ++i) { | ||
for (var j = i; j < this.cols; ++j) { | ||
var tmp = this.m[(j * this.rows) + i]; | ||
this.m[(j * this.rows) + i] = this.m[(i * this.cols) + j]; | ||
this.m[(i * this.cols) + j] = tmp; | ||
} | ||
} | ||
return this; | ||
} | ||
|
||
MW.Matrix22.prototype.inverse = function() { | ||
//CTU: This is the same rule as 3x3 matrix. | ||
// Calculate the matrix made of the cofactors | ||
// Transpose the CoFactor Matrix | ||
// Scalar multiply the Transpose CoFactor Matrix by the inverse of the Det | ||
|
||
var invMtx = new MW.Matrix22(); | ||
var invDet = 1.0 / this.determinant(); | ||
|
||
invMtx.m[0] = invDet * this.m[3]; | ||
invMtx.m[1] = -invDet * this.m[1]; | ||
invMtx.m[2] = -invDet * this.m[2]; | ||
invMtx.m[3] = invDet * this.m[0]; | ||
|
||
this.copy(invMtx); | ||
return this; | ||
} | ||
|
||
MW.Matrix22.prototype.equal = function(mtx) { | ||
|
||
for (var i = (this.m.length - 1); i >= 0; --i) { | ||
if (mtx.m[i] !== this.m[i]) | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
MW.Matrix22.prototype.scalarMultiply = function(s) { | ||
for (var i = (this.m.length - 1); i >= 0; --i) { | ||
this.m[i] = this.m[i] * s; | ||
} | ||
return this; | ||
} | ||
|
||
MW.Matrix22.prototype.vectorMultiply = function(v) { | ||
|
||
var _v = []; | ||
|
||
for (var i = 0; i < this.rows; ++i) { | ||
_v[i] = this.m[(i * this.columns) + 0] * v.x + this.m[(i * this.columns) + 1] * v.y; | ||
} | ||
|
||
var nv = new MW.Vector2(); | ||
nv.arraySet(_v); | ||
return nv; | ||
} | ||
|
||
MW.Matrix22.prototype.multiply = function(rMtx) { | ||
var pMtx = new MW.Matrix22(); | ||
|
||
for (var i = 0; i < this.rows; ++i) { | ||
for (var j = 0; j < this.cols; ++j) { | ||
var value = this.m[(i * this.cols) + 0] * rMtx.m[(0 * this.rows) + j] + this.m[(i * this.cols) + 1] * rMtx.m[(1 * this.rows) + j]; | ||
|
||
pMtx.m[(i * this.cols) + j] = value; | ||
} | ||
} | ||
this.copy(pMtx); | ||
return this; | ||
} | ||
|
||
MW.Matrix22.prototype.add = function(rMtx) { | ||
for (var i = 0; i < this.m.length; ++i) { | ||
this.m[i] += rMtx.m[i]; | ||
} | ||
return this; | ||
} | ||
|
||
MW.Matrix22.prototype.makeScale = function(sx, sy) { | ||
this.zero(); | ||
this.m[0] = sx; this.m[3] = sy; | ||
return this; | ||
} | ||
|
||
MW.Matrix22.prototype.makeRotation = function(a) { | ||
var ca = Math.cos(a); | ||
var sa = Math.sin(a); | ||
this.m[0] = ca; this.m[1] = -sa; | ||
this.m[2] = sa; this.m[3] = ca; | ||
return this; | ||
} | ||
|
||
|
||
MW.Matrix22.prototype.getColumn = function(idx) { | ||
var c = []; | ||
for (var i = 0; i < this.rows; ++i) { | ||
c[i] = this.m[(i * this.cols) + idx]; | ||
} | ||
|
||
var v = new MW.Vector2(); | ||
v.arraySet(c); | ||
|
||
return v; | ||
} | ||
|
||
MW.Matrix22.prototype.setColumn = function(idx, v) { | ||
this.m[0 * this.cols + idx] = v.x; | ||
this.m[1 * this.cols + idx] = v.y; | ||
return this; | ||
} | ||
|
||
MW.Matrix22.prototype.toString = function() { | ||
var str = "Matrix:\n"; | ||
str += "" + this.m[0] + " " + this.m[1] + "\n"; | ||
str += "" + this.m[2] + " " + this.m[3] + "\n"; | ||
return str; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/** | ||
* @author CrashTheuniversE | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
java -jar compiler/compiler.jar --js *.js --js_output_file lib/mathjs.js | ||
|
||
cp lib/mathjs.js test/mathjs.js | ||
cp lib/mathjs.js test/scripts/mathjs.js | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* @author CrashTheuniversE | ||
*/ | ||
function print(str) { | ||
|
||
var txt = document.createElement('p'); | ||
txt.innerText = str; | ||
document.body.appendChild(txt); | ||
} | ||
|
||
TestSuite = function(name) { | ||
|
||
var tests = []; | ||
var passed = true; | ||
var suiteName = name || "Generic"; | ||
|
||
this.addTest = function(desc, test) { | ||
tests.push({d: desc, t: test}); | ||
} | ||
|
||
this.print = function(str) { | ||
var txt = document.createElement('p'); | ||
txt.innerText = str; | ||
document.body.appendChild(txt); | ||
} | ||
|
||
this.printHeader = function(str) { | ||
|
||
var txt = document.createElement('h2'); | ||
txt.innerText = str; | ||
document.body.appendChild(txt); | ||
} | ||
|
||
this.runTests = function() { | ||
|
||
this.printHeader("Running suite " + suiteName); | ||
this.printHeader("------------------------------------"); | ||
|
||
passed = true; | ||
|
||
for(var i = 0, count = tests.length; i < count; ++i) | ||
{ | ||
var local = tests[i].t(); | ||
var txt = local ? "PASS" : "FAIL"; | ||
this.printHeader("Function:" + tests[i].t.name + " Description:" + tests[i].d + " :" + txt); | ||
passed = passed & local; | ||
} | ||
|
||
if(passed) | ||
this.printHeader("TEST PASSED"); | ||
else | ||
this.printHeader("TEST FAILED"); | ||
|
||
return passed; | ||
} | ||
} |
Oops, something went wrong.