From 1b3d4773a3c04c790e1928e75c2b195cabdfadec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Fri, 8 Jul 2011 21:01:34 +0200 Subject: [PATCH] Optimise hit-testing by checking point to lie within #roughBounds + tolerance first. --- src/item/Item.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/item/Item.js b/src/item/Item.js index 3f4ab185..37c36293 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -670,6 +670,12 @@ var Item = this.Item = Base.extend(/** @lends Item# */{ hitTest: function(point, options, matrix) { options = HitResult.getOptions(options); + // Check if the point is withing roughBounds + tolerance, but only if + // this item does not have children, since we'd have to travel up the + // chain already to determine the rough bounds. + if (!this._children && !this.getRoughBounds(matrix) + .expand(options.tolerance).contains(point)) + return null; // TODO: Support option.type even for things like CompoundPath where // children are matched but the parent is returned.