Skip to content

Commit

Permalink
Hit-Test: Pass viewMatrix as argument instead of in options object.
Browse files Browse the repository at this point in the history
  • Loading branch information
lehni committed Feb 14, 2016
1 parent 9c9f43d commit fa6c1f4
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 20 deletions.
6 changes: 4 additions & 2 deletions src/item/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 7 additions & 10 deletions src/item/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion src/item/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,5 @@ var Layer = Group.extend(/** @lends Layer# */{
},

_hitTestSelf: function() {
return null;
}
});
3 changes: 2 additions & 1 deletion src/item/Shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
4 changes: 2 additions & 2 deletions src/item/SymbolItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/path/CompoundPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/path/Path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion test/tests/Path_Boolean.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit fa6c1f4

Please sign in to comment.