diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 3e7f088..fc503dc 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -423,8 +423,16 @@ */ lineTo(x, y) { - this.currentPath.shape.points.push(x, y); - this.dirty++; + const points = this.currentPath.shape.points; + + const fromX = points[points.length - 2]; + const fromY = points[points.length - 1]; + + if (fromX !== x || fromY !== y) + { + points.push(x, y); + this.dirty++; + } return this; } diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 3e7f088..fc503dc 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -423,8 +423,16 @@ */ lineTo(x, y) { - this.currentPath.shape.points.push(x, y); - this.dirty++; + const points = this.currentPath.shape.points; + + const fromX = points[points.length - 2]; + const fromY = points[points.length - 1]; + + if (fromX !== x || fromY !== y) + { + points.push(x, y); + this.dirty++; + } return this; } diff --git a/test/core/Graphics.js b/test/core/Graphics.js index 23c277c..971f678 100644 --- a/test/core/Graphics.js +++ b/test/core/Graphics.js @@ -104,6 +104,18 @@ expect(graphics.width).to.be.equals(70); expect(graphics.height).to.be.equals(70); }); + + it('should ignore duplicate calls', function () + { + const graphics = new PIXI.Graphics(); + + graphics.moveTo(0, 0); + graphics.lineTo(0, 0); + graphics.lineTo(10, 0); + graphics.lineTo(10, 0); + + expect(graphics.currentPath.shape.points).to.deep.equal([0, 0, 10, 0]); + }); }); describe('containsPoint', function ()