Skip to content

Commit 906faf7

Browse files
committed
Improve handling of nested matrices in hit-testing.
Closes paperjs#134.
1 parent 450c8fc commit 906faf7

4 files changed

Lines changed: 10 additions & 9 deletions

File tree

src/item/HitResult.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,9 @@ HitResult = Base.extend(/** @lends HitResult# */{
106106
*
107107
* @private
108108
*/
109-
getOptions: function(point, options) {
109+
getOptions: function(options) {
110110
// Use _merged property to not repeatetly call merge in recursion.
111111
return options && options._merged ? options : Base.merge({
112-
point: Point.read([point]),
113112
// Type of item, for instanceof check: PathItem, TexItem, etc
114113
type: null,
115114
// Tolerance

src/item/Item.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,16 +1062,17 @@ function(name) {
10621062
* hit.
10631063
*/
10641064
hitTest: function(point, options) {
1065-
options = HitResult.getOptions(point, options);
1065+
point = Point.read(arguments);
1066+
options = HitResult.getOptions(Base.readValue(arguments));
10661067
// Check if the point is withing roughBounds + tolerance, but only if
10671068
// this item does not have children, since we'd have to travel up the
10681069
// chain already to determine the rough bounds.
10691070
if (!this._children && !this.getRoughBounds()
1070-
.expand(options.tolerance)._containsPoint(options.point))
1071+
.expand(options.tolerance)._containsPoint(point))
10711072
return null;
10721073
// Transform point to local coordinates but use untransformed point
10731074
// for bounds check above.
1074-
point = options.point = this._matrix._inverseTransform(options.point);
1075+
point = this._matrix._inverseTransform(point);
10751076
if ((options.center || options.bounds) &&
10761077
// Ignore top level layers:
10771078
!(this instanceof Layer && !this._parent)) {

src/item/PlacedItem.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ var PlacedItem = this.PlacedItem = Item.extend(/** @lends PlacedItem# */{
2828
_boundsType: { bounds: 'strokeBounds' },
2929

3030
_hitTest: function(point, options, matrix) {
31-
var hitResult = this._symbol._definition.hitTest(
32-
this.matrix._transformPoint(point), options, matrix);
31+
var hitResult = this._symbol._definition._hitTest(point, options, matrix);
3332
// TODO: When the symbol's definition is a path, should hitResult contain
3433
// information like HitResult#curve?
3534
if (hitResult)

src/project/Project.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,10 @@ var Project = this.Project = PaperScopeItem.extend(/** @lends Project# */{
223223
* hit.
224224
*/
225225
hitTest: function(point, options) {
226-
options = HitResult.getOptions(point, options);
227-
point = options.point;
226+
// We don't need to do this here, but it speeds up things since we won't
227+
// repeatetly convert in Item#hitTest() then.
228+
point = Point.read(arguments);
229+
options = HitResult.getOptions(Base.readValue(arguments));
228230
// Loop backwards, so layers that get drawn last are tested first
229231
for (var i = this.layers.length - 1; i >= 0; i--) {
230232
var res = this.layers[i].hitTest(point, options);

0 commit comments

Comments
 (0)