Handle non-invertible matrices in Item#contains() (#1651)

This commit is contained in:
Dan Stucky 2019-06-19 14:59:41 -05:00 committed by Jürg Lehni
parent 55dbf010a8
commit 32aff8e895
2 changed files with 24 additions and 2 deletions

View file

@ -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) {

View file

@ -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();