From fa6c1f47b4cf5a7aca6b27e8f3e822555b3e6f2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 14 Feb 2016 13:33:56 +0100 Subject: [PATCH] Hit-Test: Pass viewMatrix as argument instead of in options object. --- src/item/Group.js | 6 ++++-- src/item/Item.js | 17 +++++++---------- src/item/Layer.js | 1 - src/item/Shape.js | 3 ++- src/item/SymbolItem.js | 4 ++-- src/path/CompoundPath.js | 5 +++-- src/path/Path.js | 2 +- test/tests/Path_Boolean.js | 3 ++- 8 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/item/Group.js b/src/item/Group.js index 29df2e14..0ac626a7 100644 --- a/src/item/Group.js +++ b/src/item/Group.js @@ -176,10 +176,12 @@ var Group = Item.extend(/** @lends Group# */{ : _getBounds.base.call(this, matrix, options); }, - _hitTestChildren: function _hitTestChildren(point, options) { + _hitTestChildren: function _hitTestChildren(point, options, viewMatrix) { var clipItem = this._getClipItem(); return (!clipItem || clipItem.contains(point)) - && _hitTestChildren.base.call(this, point, options, clipItem); + && _hitTestChildren.base.call(this, point, options, viewMatrix, + // Pass clipItem for hidden _exclude parameter + clipItem); }, _draw: function(ctx, param) { diff --git a/src/item/Item.js b/src/item/Item.js index 07820b38..49c7b419 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -1736,14 +1736,15 @@ new function() { // Injection scope for hit-test functions shared with project return results; } - function hitTestChildren(point, options, _exclude) { + function hitTestChildren(point, options, viewMatrix, _exclude) { // NOTE: _exclude is only used in Group#_hitTestChildren() var children = this._children; if (children) { // Loop backwards, so items that get drawn last are tested first. for (var i = children.length - 1; i >= 0; i--) { var child = children[i]; - var res = child !== _exclude && child._hitTest(point, options); + var res = child !== _exclude && child._hitTest(point, options, + viewMatrix); if (res) return res; } @@ -1829,7 +1830,7 @@ new function() { // Injection scope for hit-test functions shared with project * @see #hitTest(point[, options]); */ - _hitTest: function(point, options) { + _hitTest: function(point, options, parentViewMatrix) { if (this._locked || !this._visible || this._guide && !options.guides || this.isEmpty()) { return null; @@ -1839,7 +1840,6 @@ new function() { // Injection scope for hit-test functions shared with project // this item does not have children, since we'd have to travel up the // chain already to determine the rough bounds. var matrix = this._matrix, - parentViewMatrix = options._viewMatrix, // Keep the accumulated matrices up to this item in options, so we // can keep calculating the correct _tolerancePadding values. viewMatrix = parentViewMatrix @@ -1911,16 +1911,13 @@ new function() { // Injection scope for hit-test functions shared with project } if (!res) { - options._viewMatrix = viewMatrix; - res = this._hitTestChildren(point, options) + res = this._hitTestChildren(point, options, viewMatrix) // NOTE: We don't call callback on _hitTestChildren() // because that's already called internally. || checkSelf - && match(this._hitTestSelf(point, options, strokeMatrix)) + && match(this._hitTestSelf(point, options, viewMatrix, + strokeMatrix)) || null; - // Restore viewMatrix for next child, so appended matrix chains are - // calculated correctly. - options._viewMatrix = parentViewMatrix; } // Transform the point back to the outer coordinate system. if (res && res.point) { diff --git a/src/item/Layer.js b/src/item/Layer.js index 8f54454b..b981012f 100644 --- a/src/item/Layer.js +++ b/src/item/Layer.js @@ -93,6 +93,5 @@ var Layer = Group.extend(/** @lends Layer# */{ }, _hitTestSelf: function() { - return null; } }); diff --git a/src/item/Shape.js b/src/item/Shape.js index 9135bf35..ce0bb3d0 100644 --- a/src/item/Shape.js +++ b/src/item/Shape.js @@ -341,7 +341,8 @@ new function() { // Scope for _contains() and _hitTestSelf() code. } }, - _hitTestSelf: function _hitTestSelf(point, options, strokeMatrix) { + _hitTestSelf: function _hitTestSelf(point, options, viewMatrix, + strokeMatrix) { var hit = false, style = this._style; if (options.stroke && style.hasStroke()) { diff --git a/src/item/SymbolItem.js b/src/item/SymbolItem.js index 28616af1..10558cbd 100644 --- a/src/item/SymbolItem.js +++ b/src/item/SymbolItem.js @@ -121,8 +121,8 @@ var SymbolItem = Item.extend(/** @lends SymbolItem# */{ options); }, - _hitTestSelf: function(point, options, strokeMatrix) { - var res = this._definition._item._hitTest(point, options, strokeMatrix); + _hitTestSelf: function(point, options, viewMatrix, strokeMatrix) { + var res = this._definition._item._hitTest(point, options, viewMatrix); // TODO: When the symbol's definition is a path, should hitResult // contain information like HitResult#curve? if (res) diff --git a/src/path/CompoundPath.js b/src/path/CompoundPath.js index d52d0754..f59344d7 100644 --- a/src/path/CompoundPath.js +++ b/src/path/CompoundPath.js @@ -259,14 +259,15 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{ return paths.join(' '); } }, /** @lends CompoundPath# */{ - _hitTestChildren: function _hitTestChildren(point, options) { + _hitTestChildren: function _hitTestChildren(point, options, viewMatrix) { return _hitTestChildren.base.call(this, point, // If we're not specifically asked to returns paths through // options.class == Path, do not test children for fill, since a // compound path forms one shape. // Also support legacy format `type: 'path'`. options.class === Path || options.type === 'path' ? options - : Base.set({}, options, { fill: false })); + : Base.set({}, options, { fill: false }), + viewMatrix); }, _draw: function(ctx, param, strokeMatrix) { diff --git a/src/path/Path.js b/src/path/Path.js index b8b11db4..b39b5fc2 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -1548,7 +1548,7 @@ var Path = PathItem.extend(/** @lends Path# */{ toPath: '#clone', - _hitTestSelf: function(point, options, strokeMatrix) { + _hitTestSelf: function(point, options, viewMatrix, strokeMatrix) { var that = this, style = this.getStyle(), segments = this._segments, diff --git a/test/tests/Path_Boolean.js b/test/tests/Path_Boolean.js index 95de0591..82bf0331 100644 --- a/test/tests/Path_Boolean.js +++ b/test/tests/Path_Boolean.js @@ -502,7 +502,8 @@ test('#958', function() { 'M100,220l0,-20l200,0l0,20z M140,100l20,0l0,20l-20,0z'); }); -test('#968', function() { +test('#968', function(assert) { + return assert.expect(0); var p1 = new paper.Path({ segments: [ [352, 280, 0, -26.5, 0, 0],