Skip to content

Commit dff39df

Browse files
committed
Use local bounds for hit-testing.
Fixes issue paperjs#247.
1 parent 8c9ac92 commit dff39df

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

src/item/Item.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,28 +1404,32 @@ var Item = Base.extend(Callback, /** @lends Item# */{
14041404
!(this instanceof Layer && !this._parent)) {
14051405
// Don't get the transformed bounds, check against transformed
14061406
// points instead
1407-
var bounds = this.getBounds();
1408-
if (options.center && (res = checkBounds('center', 'Center')))
1409-
return res;
1410-
if (options.bounds) {
1407+
var bounds = this._getBounds('getBounds');
1408+
if (options.center)
1409+
res = checkBounds('center', 'Center');
1410+
if (!res && options.bounds) {
14111411
// TODO: Move these into a private scope
14121412
var points = [
14131413
'TopLeft', 'TopRight', 'BottomLeft', 'BottomRight',
14141414
'LeftCenter', 'TopCenter', 'RightCenter', 'BottomCenter'
14151415
];
1416-
for (var i = 0; i < 8; i++)
1417-
if (res = checkBounds('bounds', points[i]))
1418-
return res;
1416+
for (var i = 0; i < 8 && !res; i++)
1417+
res = checkBounds('bounds', points[i]);
14191418
}
14201419
}
14211420

14221421
// TODO: Support option.type even for things like CompoundPath where
14231422
// children are matched but the parent is returned.
14241423

14251424
// Filter for guides or selected items if that's required
1426-
return this._children || !(options.guides && !this._guide
1425+
if ((res || (res = this._children || !(options.guides && !this._guide
14271426
|| options.selected && !this._selected)
1428-
? this._hitTest(point, options) : null;
1427+
? this._hitTest(point, options) : null))
1428+
&& res.point) {
1429+
// Transform the point back to the outer coordinate system.
1430+
res.point = that._matrix.transform(res.point);
1431+
}
1432+
return res;
14291433
},
14301434

14311435
_hitTest: function(point, options) {

src/path/Path.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,8 +1656,6 @@ var Path = PathItem.extend(/** @lends Path# */{
16561656
}
16571657

16581658
function checkPoint(seg, pt, name) {
1659-
// TODO: We need to transform the point back to the coordinate
1660-
// system of the DOM level on which the inquiry was started!
16611659
if (point.getDistance(pt) < tolerance)
16621660
return new HitResult(name, that, { segment: seg, point: pt });
16631661
}

0 commit comments

Comments
 (0)