Support hit-testing of placed-symbols and add test. Closes #131.

This commit is contained in:
Jonathan Puckey 2012-11-23 20:29:36 +01:00
parent 51d6e5e52d
commit 90e475b5f9
2 changed files with 26 additions and 2 deletions

View file

@ -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;
}
});

View file

@ -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});