diff --git a/src/item/Item.js b/src/item/Item.js index 5a7fd3fc..1a9d483a 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -1816,8 +1816,11 @@ new function() { // Injection scope for various item event handlers */ contains: function(/* point */) { // See CompoundPath#_contains() for the reason for !! - return !!this._contains( - this._matrix._inverseTransform(Point.read(arguments))); + var matrix = this._matrix; + return ( + matrix.isInvertible() && + !!this._contains(matrix._inverseTransform(Point.read(arguments))) + ); }, _contains: function(point) { diff --git a/test/tests/Item.js b/test/tests/Item.js index 0f751996..d8b679a3 100644 --- a/test/tests/Item.js +++ b/test/tests/Item.js @@ -877,6 +877,25 @@ test('Item#pivot', function() { 'Changing position of an item with applyMatrix = true should change pivot'); }); +test('Item#contains', function() { + var point = new Point(50,50); + var path1 = new Path({matrix: new Matrix(0,0,0,0,0,0)}); + + equals(path1.contains(point), false, + 'An irregularly shaped item cannot contain a point'); + + var path2 = new Path.Rectangle({ + point: [50, 50], + size: [100, 100] + }); + equals(path2.contains(point), true, + 'A regularly shaped item with a point inside it, contains that point'); + + var point2 = new Point(0,0); + equals(path2.contains(point2), false, + 'A regularly shaped item with a point outside it, does not contain that point'); +}); + test('Item#position with irregular shape, #pivot and rotation', function() { var path1 = new Path([ [0, 0], [200, 100], [0, 100] ]); var path2 = path1.clone();