diff --git a/src/basic/Point.js b/src/basic/Point.js index ddf466d5..be4deef8 100644 --- a/src/basic/Point.js +++ b/src/basic/Point.js @@ -393,7 +393,7 @@ var Point = this.Point = Base.extend(/** @lends Point# */{ * @return {Point} the transformed point */ transform: function(matrix) { - return matrix._transformPoint(this); + return matrix ? matrix._transformPoint(this) : this; }, /** diff --git a/src/item/Item.js b/src/item/Item.js index fb47d982..b9ed336d 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -677,6 +677,33 @@ var Item = this.Item = Base.extend(/** @lends Item# */{ if (!this._children && !this.getRoughBounds(matrix) .expand(options.tolerance).contains(point)) return null; + if (options.center || options.bounds) { + // Don't get the transformed bounds, check against transformed + // points instead + var bounds = this.getBounds(), + that = this, + // TODO: Move these into a private scope + points = ['TopLeft', 'TopRight', 'BottomLeft', 'BottomRight', + 'LeftCenter', 'TopCenter', 'RightCenter', 'BottomCenter'], + res; + function checkBounds(part) { + var pt = bounds['get' + part]().transform(matrix); + if (point.getDistance(pt) < options.tolerance) + return new HitResult(Base.hyphenate(part), that, + { point: pt }); + } + // Push the getter name parts onto _parts for the bounds properties + // that we are supposed to test. This is performed only once, even + // when testing many items. + if (options.center && (res = checkBounds('Center'))) + return res; + if (options.bounds) { + for (var i = 0; i < 8; i++) + if (res = checkBounds(points[i])) + return res; + } + } + // TODO: Support option.type even for things like CompoundPath where // children are matched but the parent is returned. @@ -691,8 +718,7 @@ var Item = this.Item = Base.extend(/** @lends Item# */{ // Loop backwards, so items that get drawn last are tested first for (var i = this._children.length - 1; i >= 0; i--) { var res = this._children[i].hitTest(point, options, matrix); - if (res) - return res; + if (res) return res; } } }, diff --git a/src/project/Project.js b/src/project/Project.js index dcbbfb6c..27908b5d 100644 --- a/src/project/Project.js +++ b/src/project/Project.js @@ -187,8 +187,7 @@ var Project = this.Project = Base.extend(/** @lends Project# */{ // Loop backwards, so layers that get drawn last are tested first for (var i = this.layers.length - 1; i >= 0; i--) { var res = this.layers[i].hitTest(point, options); - if (res) - return res; + if (res) return res; } return null; },