Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

matrix's calcRotVec() fails with TypeError #20

Open
omgm opened this issue Aug 27, 2014 · 0 comments · May be fixed by #21
Open

matrix's calcRotVec() fails with TypeError #20

omgm opened this issue Aug 27, 2014 · 0 comments · May be fixed by #21

Comments

@omgm
Copy link

omgm commented Aug 27, 2014

This issue was found thanks to performing mutation analysis with Mutator (http://ortask.com/mutator/) on test suite matrix-test.js.

Calling function calcRotVec() of matrix.js on a matrix that is not 4x4 will crash the application with:

TypeError: Cannot call method 'set' of undefined

As suggested by mutation analysis, I added this test to matrix-test.js:

    it('calculates the rotation vector for the matrix', function () {
      var D = new Matrix(2,2);
      D.set(0,0,0);
      D.set(0,1,0);
      D.set(1,0,0);
      D.set(1,1,0);
      var C = D.calcRotVec();
      // oracle TBD
    });

But it fails with the above TypeError due to the fact that calcRotVec() calls getRot(), and the creation of the inner/temp matrix in getRot() is bypassed when the caller matrix is not 4x4:

  getRot: function () {
    if (this.rows === 4 && this.cols === 4)
      var C = new Matrix(3, 3);        <--- Skipped when matrix is not 4x4
      for (var r = 0; r < 3; ++r) {
        for (var c = 0; c < 3; ++c) {
          var val = this.get(r,c);
          C.set(r,c, val);             <--- TypeError here because C is truly undefined
        }
      }
      return C;
  },

The root-cause is that the getRot() function is missing curly braces to enclose the logic for the different sizes of matrices. However, even with braces, its implementation does not appear to suggest any paths for non-4x4 matrices.

@omgm omgm linked a pull request Aug 29, 2014 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant