diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index cd574ac..4f9ae43 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -390,11 +390,11 @@ const x1 = -width * this.anchor.x; let y1 = 0; - if (tempPoint.x > x1 && tempPoint.x < x1 + width) + if (tempPoint.x >= x1 && tempPoint.x < x1 + width) { y1 = -height * this.anchor.y; - if (tempPoint.y > y1 && tempPoint.y < y1 + height) + if (tempPoint.y >= y1 && tempPoint.y < y1 + height) { return true; } diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index cd574ac..4f9ae43 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -390,11 +390,11 @@ const x1 = -width * this.anchor.x; let y1 = 0; - if (tempPoint.x > x1 && tempPoint.x < x1 + width) + if (tempPoint.x >= x1 && tempPoint.x < x1 + width) { y1 = -height * this.anchor.y; - if (tempPoint.y > y1 && tempPoint.y < y1 + height) + if (tempPoint.y >= y1 && tempPoint.y < y1 + height) { return true; } diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 72fee21..8a75780 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -310,11 +310,11 @@ const height = this._height; const x1 = -width * this.anchor._x; - if (tempPoint.x > x1 && tempPoint.x < x1 + width) + if (tempPoint.x >= x1 && tempPoint.x < x1 + width) { const y1 = -height * this.anchor._y; - if (tempPoint.y > y1 && tempPoint.y < y1 + height) + if (tempPoint.y >= y1 && tempPoint.y < y1 + height) { return true; } diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index cd574ac..4f9ae43 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -390,11 +390,11 @@ const x1 = -width * this.anchor.x; let y1 = 0; - if (tempPoint.x > x1 && tempPoint.x < x1 + width) + if (tempPoint.x >= x1 && tempPoint.x < x1 + width) { y1 = -height * this.anchor.y; - if (tempPoint.y > y1 && tempPoint.y < y1 + height) + if (tempPoint.y >= y1 && tempPoint.y < y1 + height) { return true; } diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 72fee21..8a75780 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -310,11 +310,11 @@ const height = this._height; const x1 = -width * this.anchor._x; - if (tempPoint.x > x1 && tempPoint.x < x1 + width) + if (tempPoint.x >= x1 && tempPoint.x < x1 + width) { const y1 = -height * this.anchor._y; - if (tempPoint.y > y1 && tempPoint.y < y1 + height) + if (tempPoint.y >= y1 && tempPoint.y < y1 + height) { return true; } diff --git a/test/core/Sprite.js b/test/core/Sprite.js index b14419d..c9bc4cb 100755 --- a/test/core/Sprite.js +++ b/test/core/Sprite.js @@ -91,11 +91,26 @@ describe('containsPoint', function () { + const texture = new PIXI.RenderTexture.create(20, 30); + const sprite = new PIXI.Sprite(texture); + it('should return true when point inside', function () { const point = new PIXI.Point(10, 10); - const texture = new PIXI.RenderTexture.create(20, 30); - const sprite = new PIXI.Sprite(texture); + + expect(sprite.containsPoint(point)).to.be.true; + }); + + it('should return true when point on left edge', function () + { + const point = new PIXI.Point(0, 15); + + expect(sprite.containsPoint(point)).to.be.true; + }); + + it('should return true when point on top edge', function () + { + const point = new PIXI.Point(10, 0); expect(sprite.containsPoint(point)).to.be.true; }); @@ -103,8 +118,6 @@ it('should return false when point outside', function () { const point = new PIXI.Point(100, 100); - const texture = new PIXI.RenderTexture.create(20, 30); - const sprite = new PIXI.Sprite(texture); expect(sprite.containsPoint(point)).to.be.false; }); diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index cd574ac..4f9ae43 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -390,11 +390,11 @@ const x1 = -width * this.anchor.x; let y1 = 0; - if (tempPoint.x > x1 && tempPoint.x < x1 + width) + if (tempPoint.x >= x1 && tempPoint.x < x1 + width) { y1 = -height * this.anchor.y; - if (tempPoint.y > y1 && tempPoint.y < y1 + height) + if (tempPoint.y >= y1 && tempPoint.y < y1 + height) { return true; } diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 72fee21..8a75780 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -310,11 +310,11 @@ const height = this._height; const x1 = -width * this.anchor._x; - if (tempPoint.x > x1 && tempPoint.x < x1 + width) + if (tempPoint.x >= x1 && tempPoint.x < x1 + width) { const y1 = -height * this.anchor._y; - if (tempPoint.y > y1 && tempPoint.y < y1 + height) + if (tempPoint.y >= y1 && tempPoint.y < y1 + height) { return true; } diff --git a/test/core/Sprite.js b/test/core/Sprite.js index b14419d..c9bc4cb 100755 --- a/test/core/Sprite.js +++ b/test/core/Sprite.js @@ -91,11 +91,26 @@ describe('containsPoint', function () { + const texture = new PIXI.RenderTexture.create(20, 30); + const sprite = new PIXI.Sprite(texture); + it('should return true when point inside', function () { const point = new PIXI.Point(10, 10); - const texture = new PIXI.RenderTexture.create(20, 30); - const sprite = new PIXI.Sprite(texture); + + expect(sprite.containsPoint(point)).to.be.true; + }); + + it('should return true when point on left edge', function () + { + const point = new PIXI.Point(0, 15); + + expect(sprite.containsPoint(point)).to.be.true; + }); + + it('should return true when point on top edge', function () + { + const point = new PIXI.Point(10, 0); expect(sprite.containsPoint(point)).to.be.true; }); @@ -103,8 +118,6 @@ it('should return false when point outside', function () { const point = new PIXI.Point(100, 100); - const texture = new PIXI.RenderTexture.create(20, 30); - const sprite = new PIXI.Sprite(texture); expect(sprite.containsPoint(point)).to.be.false; }); diff --git a/test/core/TilingSprite.js b/test/core/TilingSprite.js index 7694792..0b6c87f 100644 --- a/test/core/TilingSprite.js +++ b/test/core/TilingSprite.js @@ -30,7 +30,9 @@ const texture = new PIXI.Texture(new PIXI.BaseTexture()); const tilingSprite = new PIXI.extras.TilingSprite(texture, 200, 300); - expect(tilingSprite.containsPoint(new PIXI.Point(1, 1))).to.equal(true); + expect(tilingSprite.containsPoint(new PIXI.Point(0, 0))).to.equal(true); + expect(tilingSprite.containsPoint(new PIXI.Point(10, 10))).to.equal(true); + expect(tilingSprite.containsPoint(new PIXI.Point(200, 300))).to.equal(false); expect(tilingSprite.containsPoint(new PIXI.Point(300, 400))).to.equal(false); });