forked from InsightSoftwareConsortium/itk-wasm
/
Matrix.js
36 lines (31 loc) · 852 Bytes
/
Matrix.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function Matrix (rows, columns) {
if (rows instanceof Matrix) {
const other = rows
this.rows = other.rows
this.columns = other.columns
this.data = other.data.slice()
} else {
this.rows = rows
this.columns = columns
this.data = new Array(rows * columns)
this.data.fill(0.0)
}
}
Matrix.prototype.setIdentity = function () {
for (let ii = 0; ii < this.rows; ++ii) {
for (let jj = 0; jj < this.columns; ++jj) {
if (ii === jj) {
this.data[jj + ii * this.columns] = 1.0
} else {
this.data[jj + ii * this.columns] = 0.0
}
}
}
}
Matrix.prototype.setElement = function (row, column, value) {
this.data[column + row * this.columns] = value
}
Matrix.prototype.getElement = function (row, column) {
return this.data[column + row * this.columns]
}
module.exports = Matrix