Skip to content

Commit

Permalink
Merge pull request jriecken#53 from jriecken/fix-scaling-by-zero
Browse files Browse the repository at this point in the history
Check explicitly for undefined y param when scaling. Fixes jriecken#52
  • Loading branch information
jriecken authored May 24, 2018
2 parents 217f5c0 + ac7f329 commit 92b4ac2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion SAT.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
*/
Vector.prototype['scale'] = Vector.prototype.scale = function(x,y) {
this['x'] *= x;
this['y'] *= y || x;
this['y'] *= typeof y != 'undefined' ? y : x;
return this;
};

Expand Down
18 changes: 18 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
var SAT = require('..');
var assert = require('assert');

describe('Vector.scale', function() {
it('should scale by zero properly', function() {
var V = SAT.Vector;
var v1 = new V(5, 5);
v1.scale(10, 10);
assert(v1.x === 50);
assert(v1.y === 50);

v1.scale(0, 1);
assert(v1.x === 0);
assert(v1.y === 50);

v1.scale(1, 0);
assert(v1.x === 0);
assert(v1.y === 0);
});
});

describe("Polygon.getCentroid", function() {
it("should calculate the correct value for a square", function() {
var V = SAT.Vector;
Expand Down

0 comments on commit 92b4ac2

Please sign in to comment.