Skip to content

Commit

Permalink
correctly add vector to simplified matrix.
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneycb committed Aug 16, 2019
1 parent 63c5756 commit 1613d48
Showing 1 changed file with 8 additions and 2 deletions.
Expand Up @@ -93,13 +93,16 @@ function formatMatrix(matrix, rowTemplate) {
return sprintf(MATRIX_TEMPLATE, row0, row1, row2);
}


/** Remove zeros if they are insignificant.
* i.e only remove zeros if they are not the only number in the row
*/
function simplifyResult(matrix, vector) {
var result = [];
for (i=0; i < 3; i++) {
row = "";
var hasX = false;
var hasY = false;
var hasZ = false;
if (!(matrix[i][0] == 0)) {
row += matrix[i][0] + 'x';
hasX = true;
Expand All @@ -116,9 +119,12 @@ function simplifyResult(matrix, vector) {
row += ' + '
}
row += matrix[i][2] + 'z';
hasZ = true;
}
if (!(vector[i] == 0)) {
if (!(vector[i] == 0) && (hasX || hasY || hasZ)) {
row += ' + ' + vector[i];
} else if (!(hasX || hasY || hasZ)) {
row += vector[i];
}
if (row == "") {
row = "0";
Expand Down

0 comments on commit 1613d48

Please sign in to comment.