From 90e475b5f928008289c0cffb5cc13786d866471e Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Fri, 23 Nov 2012 20:29:36 +0100 Subject: [PATCH] Support hit-testing of placed-symbols and add test. Closes #131. --- src/item/PlacedItem.js | 15 +++++++++++++-- test/tests/HitResult.js | 13 +++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/item/PlacedItem.js b/src/item/PlacedItem.js index 77750e5b..9f4e65f3 100644 --- a/src/item/PlacedItem.js +++ b/src/item/PlacedItem.js @@ -25,5 +25,16 @@ */ var PlacedItem = this.PlacedItem = Item.extend(/** @lends PlacedItem# */{ // PlacedItem uses strokeBounds for bounds - _boundsType: { bounds: 'strokeBounds' } -}); + _boundsType: { bounds: 'strokeBounds' }, + + _hitTest: function(point, options, matrix) { + console.log(point); + point = point.transform(this.matrix); + var hitResult = this._symbol._definition.hitTest(point, options, matrix); + // TODO: When the symbol's definition is a path, should hitResult contain + // information like HitResult#curve? + if (hitResult) + hitResult.item = this; + return hitResult; + } +}); \ No newline at end of file diff --git a/test/tests/HitResult.js b/test/tests/HitResult.js index af955035..0574f41f 100644 --- a/test/tests/HitResult.js +++ b/test/tests/HitResult.js @@ -518,4 +518,17 @@ test('Check hit testing of items that come after a transformed group.', function }, true, 'After moving group before path1, hit testing path1 for point1 should give us path1.'); }); +test('Check hit testing of placed symbols.', function() { + var point = new Point(100, 100); + + var path = new Path.Circle([0, 0], 20); + path.fillColor = 'black'; + var symbol = new Symbol(path); + var placedItem = symbol.place(point); + var hitResult = placedItem.hitTest(point); + equals(function() { + return hitResult && hitResult.item == placedItem; + }, true, 'hitResult.item should be placedItem'); + +}); // TODO: project.hitTest(point, {type: AnItemType}); \ No newline at end of file