diff --git a/packages/graphics/src/GraphicsGeometry.js b/packages/graphics/src/GraphicsGeometry.js index 85dae91..75e1125 100644 --- a/packages/graphics/src/GraphicsGeometry.js +++ b/packages/graphics/src/GraphicsGeometry.js @@ -1,4 +1,4 @@ -import { SHAPES } from '@pixi/math'; +import { SHAPES, Point } from '@pixi/math'; import { Bounds } from '@pixi/display'; import { BatchGeometry, BatchDrawCall, BaseTexture } from '@pixi/core'; import { DRAW_MODES, WRAP_MODES } from '@pixi/constants'; @@ -13,6 +13,7 @@ const BATCH_POOL = []; const DRAW_CALL_POOL = []; +const tmpPoint = new Point(); /** * Map of fill commands for each shape type. @@ -388,7 +389,16 @@ // only deal with fills.. if (data.shape) { - if (data.shape.contains(point.x, point.y)) + if (data.matrix) + { + data.matrix.applyInverse(point, tmpPoint); + } + else + { + tmpPoint.copyFrom(point); + } + + if (data.shape.contains(tmpPoint.x, tmpPoint.y)) { if (data.holes) { @@ -396,7 +406,7 @@ { const hole = data.holes[i]; - if (hole.shape.contains(point.x, point.y)) + if (hole.shape.contains(tmpPoint.x, tmpPoint.y)) { return false; } diff --git a/packages/graphics/src/GraphicsGeometry.js b/packages/graphics/src/GraphicsGeometry.js index 85dae91..75e1125 100644 --- a/packages/graphics/src/GraphicsGeometry.js +++ b/packages/graphics/src/GraphicsGeometry.js @@ -1,4 +1,4 @@ -import { SHAPES } from '@pixi/math'; +import { SHAPES, Point } from '@pixi/math'; import { Bounds } from '@pixi/display'; import { BatchGeometry, BatchDrawCall, BaseTexture } from '@pixi/core'; import { DRAW_MODES, WRAP_MODES } from '@pixi/constants'; @@ -13,6 +13,7 @@ const BATCH_POOL = []; const DRAW_CALL_POOL = []; +const tmpPoint = new Point(); /** * Map of fill commands for each shape type. @@ -388,7 +389,16 @@ // only deal with fills.. if (data.shape) { - if (data.shape.contains(point.x, point.y)) + if (data.matrix) + { + data.matrix.applyInverse(point, tmpPoint); + } + else + { + tmpPoint.copyFrom(point); + } + + if (data.shape.contains(tmpPoint.x, tmpPoint.y)) { if (data.holes) { @@ -396,7 +406,7 @@ { const hole = data.holes[i]; - if (hole.shape.contains(point.x, point.y)) + if (hole.shape.contains(tmpPoint.x, tmpPoint.y)) { return false; } diff --git a/packages/graphics/test/index.js b/packages/graphics/test/index.js index b6b4951..a2ccc35 100644 --- a/packages/graphics/test/index.js +++ b/packages/graphics/test/index.js @@ -2,7 +2,7 @@ const { Renderer, BatchRenderer } = require('@pixi/core'); const { Graphics, GRAPHICS_CURVES } = require('../'); const { BLEND_MODES } = require('@pixi/constants'); -const { Point } = require('@pixi/math'); +const { Point, Matrix } = require('@pixi/math'); const { skipHello } = require('@pixi/utils'); Renderer.registerPlugin('batch', BatchRenderer); @@ -181,6 +181,27 @@ expect(graphics.containsPoint(point1)).to.be.true; expect(graphics.containsPoint(point2)).to.be.false; }); + + it('should take a matrix into account', function () + { + const g = new Graphics(); + const m = new Matrix(); + + g.beginFill(0xffffff, 1.0); + m.identity().translate(0, 100); + g.setMatrix(m.clone()); + g.drawRect(0, 0, 10, 10); + m.identity().translate(200, 0); + g.setMatrix(m.clone()); + g.drawRect(0, 0, 10, 10); + g.setMatrix(null); + g.drawRect(30, 40, 10, 10); + + expect(g.containsPoint(new Point(5, 5))).to.be.false; + expect(g.containsPoint(new Point(5, 105))).to.be.true; + expect(g.containsPoint(new Point(205, 5))).to.be.true; + expect(g.containsPoint(new Point(35, 45))).to.be.true; + }); }); describe('chaining', function ()