Skip to content
Open
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
20 changes: 14 additions & 6 deletions lib/matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,33 @@ var v = require('./vector');
// -----------------------------------------------------------
// Matrices
// -----------------------------------------------------------
var Matrix = function Matrix (rows, cols, isIdentity) {
var Matrix = function Matrix (rows, cols) {
// initialize the matrix
this.rows = rows;
this.cols = cols ? cols : rows; // make it a square matrix if only one argument

this.m = new Array(rows);
for (var r = 0; r < rows; ++r) {
this.m[r] = new Array(cols);
for (var c = 0; c < cols; ++c) {
this.m = new Array(this.rows);
for (var r = 0; r < this.rows; ++r) {
this.m[r] = new Array(this.cols);
for (var c = 0; c < this.cols; ++c) {
this.m[r][c] = 0;
}
}

this.isVector = false;

this.size = {rows: this.rows, cols: this.cols};

};

Matrix.identity = function(size) {
var I = new Matrix(size);
for (var i = 0; i < size; ++i) {
I.set(i, i, 1);
}
return I;
}

Matrix.prototype = {
set : function (i, j, val) {
this.m[i][j] = parseFloat(val.toFixed(6));
Expand Down