mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-04 03:45:58 -05:00
Implement tests for hit-testing compound-paths.
This commit is contained in:
parent
eea4e533a4
commit
1bede6f7ec
1 changed files with 50 additions and 10 deletions
|
@ -641,4 +641,44 @@ test('Hit testing fill with tolerance', function() {
|
||||||
}, true);
|
}, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Hit testing compound-paths', function() {
|
||||||
|
var center = new Point(100, 100);
|
||||||
|
var path1 = new Path.Circle({
|
||||||
|
center: center,
|
||||||
|
radius: 100
|
||||||
|
});
|
||||||
|
var path2 = new Path.Circle({
|
||||||
|
center: center,
|
||||||
|
radius: 50
|
||||||
|
});
|
||||||
|
var compoundPath = new CompoundPath({
|
||||||
|
children: [path1, path2],
|
||||||
|
fillColor: 'blue'
|
||||||
|
});
|
||||||
|
// When hit-testing a side, we should get a result on the torus
|
||||||
|
equals(function() {
|
||||||
|
var result = paper.project.hitTest(center.add([75, 0]), {
|
||||||
|
fill: true
|
||||||
|
});
|
||||||
|
return result && result.item === compoundPath;
|
||||||
|
}, true);
|
||||||
|
// When hit-testing the center, we should not get a result on the torus
|
||||||
|
equals(function() {
|
||||||
|
var result = paper.project.hitTest(center, {
|
||||||
|
fill: true
|
||||||
|
});
|
||||||
|
return result === null ;
|
||||||
|
}, true);
|
||||||
|
// When asking specifically for paths, she should get the top-most path in
|
||||||
|
// the center (the one that cuts out the hole)
|
||||||
|
equals(function() {
|
||||||
|
var result = paper.project.hitTest(center, {
|
||||||
|
type: Path,
|
||||||
|
fill: true
|
||||||
|
});
|
||||||
|
return result && result.item === path2;
|
||||||
|
}, true);
|
||||||
|
});
|
||||||
|
|
||||||
// TODO: project.hitTest(point, {type: AnItemType});
|
// TODO: project.hitTest(point, {type: AnItemType});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue