diff --git a/packages/graphics/src/Graphics.js b/packages/graphics/src/Graphics.js index d132433..29d4298 100644 --- a/packages/graphics/src/Graphics.js +++ b/packages/graphics/src/Graphics.js @@ -417,8 +417,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/packages/graphics/src/Graphics.js b/packages/graphics/src/Graphics.js index d132433..29d4298 100644 --- a/packages/graphics/src/Graphics.js +++ b/packages/graphics/src/Graphics.js @@ -417,8 +417,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/packages/graphics/test/index.js b/packages/graphics/test/index.js index 0068775..b746532 100644 --- a/packages/graphics/test/index.js +++ b/packages/graphics/test/index.js @@ -118,6 +118,18 @@ expect(graphics.width).to.be.equals(70); expect(graphics.height).to.be.equals(70); }); + + it('should ignore duplicate calls', function () + { + const graphics = new 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 ()