Use local bounds for hit-testing.

Fixes issue #247.
This commit is contained in:
Jürg Lehni 2013-06-23 19:49:36 -07:00
parent 8c9ac92a59
commit dff39dff78
2 changed files with 13 additions and 11 deletions

View file

@ -1404,18 +1404,17 @@ var Item = Base.extend(Callback, /** @lends Item# */{
!(this instanceof Layer && !this._parent)) { !(this instanceof Layer && !this._parent)) {
// Don't get the transformed bounds, check against transformed // Don't get the transformed bounds, check against transformed
// points instead // points instead
var bounds = this.getBounds(); var bounds = this._getBounds('getBounds');
if (options.center && (res = checkBounds('center', 'Center'))) if (options.center)
return res; res = checkBounds('center', 'Center');
if (options.bounds) { if (!res && options.bounds) {
// TODO: Move these into a private scope // TODO: Move these into a private scope
var points = [ var points = [
'TopLeft', 'TopRight', 'BottomLeft', 'BottomRight', 'TopLeft', 'TopRight', 'BottomLeft', 'BottomRight',
'LeftCenter', 'TopCenter', 'RightCenter', 'BottomCenter' 'LeftCenter', 'TopCenter', 'RightCenter', 'BottomCenter'
]; ];
for (var i = 0; i < 8; i++) for (var i = 0; i < 8 && !res; i++)
if (res = checkBounds('bounds', points[i])) res = checkBounds('bounds', points[i]);
return res;
} }
} }
@ -1423,9 +1422,14 @@ var Item = Base.extend(Callback, /** @lends Item# */{
// children are matched but the parent is returned. // children are matched but the parent is returned.
// Filter for guides or selected items if that's required // Filter for guides or selected items if that's required
return this._children || !(options.guides && !this._guide if ((res || (res = this._children || !(options.guides && !this._guide
|| options.selected && !this._selected) || options.selected && !this._selected)
? this._hitTest(point, options) : null; ? this._hitTest(point, options) : null))
&& res.point) {
// Transform the point back to the outer coordinate system.
res.point = that._matrix.transform(res.point);
}
return res;
}, },
_hitTest: function(point, options) { _hitTest: function(point, options) {

View file

@ -1656,8 +1656,6 @@ var Path = PathItem.extend(/** @lends Path# */{
} }
function checkPoint(seg, pt, name) { function checkPoint(seg, pt, name) {
// TODO: We need to transform the point back to the coordinate
// system of the DOM level on which the inquiry was started!
if (point.getDistance(pt) < tolerance) if (point.getDistance(pt) < tolerance)
return new HitResult(name, that, { segment: seg, point: pt }); return new HitResult(name, that, { segment: seg, point: pt });
} }