Implement tests for hit-testing compound-paths.

This commit is contained in:
Jürg Lehni 2014-04-10 22:27:29 +02:00
parent eea4e533a4
commit 1bede6f7ec

View file

@ -641,4 +641,44 @@ test('Hit testing fill with tolerance', function() {
}, 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});