Hit-Tests: Fix issue with non-invertible matrices.

Closes #1271
This commit is contained in:
Jürg Lehni 2017-03-09 12:42:11 +01:00
parent 3ffd7c4ac2
commit 083a09604d
2 changed files with 16 additions and 2 deletions

View file

@ -1901,7 +1901,7 @@ new function() { // Injection scope for hit-test functions shared with project
// need to apply the inverted item matrix. // need to apply the inverted item matrix.
tolerancePadding = options._tolerancePadding = new Size( tolerancePadding = options._tolerancePadding = new Size(
Path._getStrokePadding(tolerance, Path._getStrokePadding(tolerance,
matrix.inverted()._shiftless())); matrix._shiftless().invert()));
// Transform point to local coordinates. // Transform point to local coordinates.
point = matrix._inverseTransform(point); point = matrix._inverseTransform(point);
// If the matrix is non-reversible, point will now be `null`: // If the matrix is non-reversible, point will now be `null`:
@ -1980,7 +1980,7 @@ new function() { // Injection scope for hit-test functions shared with project
// If the item has a non-scaling stroke, we need to // If the item has a non-scaling stroke, we need to
// apply the inverted viewMatrix to stroke dimensions. // apply the inverted viewMatrix to stroke dimensions.
this.getStrokeScaling() ? null this.getStrokeScaling() ? null
: viewMatrix.inverted()._shiftless())) : viewMatrix._shiftless().invert()))
|| null; || null;
} }
// Transform the point back to the outer coordinate system. // Transform the point back to the outer coordinate system.

View file

@ -854,4 +854,18 @@ test('hit-testing scaled items with different settings of view.zoom and item.str
testItem(Path, 2, true); testItem(Path, 2, true);
}); });
test('hit-testing items scaled to 0', function() {
var item = new Shape.Rectangle({
point: [0, 0],
size: [100, 100],
fillColor: 'red',
selected: true
});
item.scale(0);
testHitResult(project.hitTest(item.position), null,
'should not throw an exception.');
});
// TODO: project.hitTest(point, {type: AnItemType}); // TODO: project.hitTest(point, {type: AnItemType});