From 580fe7cecd07370d5dbefa1f500fe25adf8580cd Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Sun, 24 Feb 2019 13:00:55 +0100 Subject: [PATCH] :bug: Fixed issue with point.flipX/Y breaking when passing zero --- src/point.js | 4 ++-- tests/point.test.js | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/point.js b/src/point.js index 2120140181e..310d6919a1e 100644 --- a/src/point.js +++ b/src/point.js @@ -73,13 +73,13 @@ Point.prototype.copy = function() { /** Mirrors this point around X value of that point */ Point.prototype.flipX = function(that = false) { - if (that === false) return new Point(this.x * -1, this.y); + if (that === false || that === 0) return new Point(this.x * -1, this.y); else return new Point(that.x + this.dx(that), this.y); }; /** Mirrors this point around Y value of that point */ Point.prototype.flipY = function(that = false) { - if (that === false) return new Point(this.x, this.y * -1); + if (that === false || that === 0) return new Point(this.x, this.y * -1); else return new Point(this.x, that.y + this.dy(that)); }; diff --git a/tests/point.test.js b/tests/point.test.js index 7725c54879d..534bd47cc60 100644 --- a/tests/point.test.js +++ b/tests/point.test.js @@ -50,24 +50,36 @@ it("Should check points for equality", () => { expect(a).to.deep.equal(b); }); -it("Should flip point around X value zero", () => { +it("Should flip point around unset X value", () => { let result = new Point(2, 4).flipX(); expect(result.x).to.equal(-2); expect(result.y).to.equal(4); }); +it("Should flip point around X value that is zero", () => { + let result = new Point(2, 4).flipX(0); + expect(result.x).to.equal(-2); + expect(result.y).to.equal(4); +}); + it("Should flip point around X value", () => { let result = new Point(2, 4).flipX(new Point(-20, 19)); expect(result.x).to.equal(-42); expect(result.y).to.equal(4); }); -it("Should flip point around Y value zero", () => { +it("Should flip point around unset Y value", () => { let result = new Point(2, 4).flipY(); expect(result.x).to.equal(2); expect(result.y).to.equal(-4); }); +it("Should flip point around Y value that is zero", () => { + let result = new Point(2, 4).flipY(0); + expect(result.x).to.equal(2); + expect(result.y).to.equal(-4); +}); + it("Should flip point around Y value", () => { let result = new Point(2, 4).flipY(new Point(12, -14)); expect(result.x).to.equal(2);