🐛 Fixed issue with point.flipX/Y breaking when passing zero
This commit is contained in:
parent
dcf02b9236
commit
580fe7cecd
2 changed files with 16 additions and 4 deletions
|
@ -73,13 +73,13 @@ Point.prototype.copy = function() {
|
||||||
|
|
||||||
/** Mirrors this point around X value of that point */
|
/** Mirrors this point around X value of that point */
|
||||||
Point.prototype.flipX = function(that = false) {
|
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);
|
else return new Point(that.x + this.dx(that), this.y);
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Mirrors this point around Y value of that point */
|
/** Mirrors this point around Y value of that point */
|
||||||
Point.prototype.flipY = function(that = false) {
|
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));
|
else return new Point(this.x, that.y + this.dy(that));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -50,24 +50,36 @@ it("Should check points for equality", () => {
|
||||||
expect(a).to.deep.equal(b);
|
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();
|
let result = new Point(2, 4).flipX();
|
||||||
expect(result.x).to.equal(-2);
|
expect(result.x).to.equal(-2);
|
||||||
expect(result.y).to.equal(4);
|
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", () => {
|
it("Should flip point around X value", () => {
|
||||||
let result = new Point(2, 4).flipX(new Point(-20, 19));
|
let result = new Point(2, 4).flipX(new Point(-20, 19));
|
||||||
expect(result.x).to.equal(-42);
|
expect(result.x).to.equal(-42);
|
||||||
expect(result.y).to.equal(4);
|
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();
|
let result = new Point(2, 4).flipY();
|
||||||
expect(result.x).to.equal(2);
|
expect(result.x).to.equal(2);
|
||||||
expect(result.y).to.equal(-4);
|
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", () => {
|
it("Should flip point around Y value", () => {
|
||||||
let result = new Point(2, 4).flipY(new Point(12, -14));
|
let result = new Point(2, 4).flipY(new Point(12, -14));
|
||||||
expect(result.x).to.equal(2);
|
expect(result.x).to.equal(2);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue