mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 14:10:14 -05:00
Support hit-testing of placed-symbols and add test. Closes #131.
This commit is contained in:
parent
51d6e5e52d
commit
90e475b5f9
2 changed files with 26 additions and 2 deletions
|
@ -25,5 +25,16 @@
|
||||||
*/
|
*/
|
||||||
var PlacedItem = this.PlacedItem = Item.extend(/** @lends PlacedItem# */{
|
var PlacedItem = this.PlacedItem = Item.extend(/** @lends PlacedItem# */{
|
||||||
// PlacedItem uses strokeBounds for bounds
|
// 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;
|
||||||
|
}
|
||||||
|
});
|
|
@ -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.');
|
}, 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});
|
// TODO: project.hitTest(point, {type: AnItemType});
|
Loading…
Reference in a new issue