mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Add 2 more HitResult tests, which test hitting selected paths and guides.
This commit is contained in:
parent
738573e224
commit
cb65399063
1 changed files with 59 additions and 1 deletions
|
@ -69,6 +69,27 @@ test('hitting a stroked path', function() {
|
||||||
}, true);
|
}, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('hitting a selected path', function() {
|
||||||
|
var path = new Path.Circle([50, 50], 50);
|
||||||
|
path.fillColor = 'red';
|
||||||
|
|
||||||
|
var hitResult = paper.project.hitTest([75, 75], {
|
||||||
|
selected: true
|
||||||
|
});
|
||||||
|
equals(function() {
|
||||||
|
return hitResult == null;
|
||||||
|
}, true, 'Since the path is not selected, the hit-test should return null');
|
||||||
|
|
||||||
|
path.selected = true;
|
||||||
|
hitResult = paper.project.hitTest([75, 75]);
|
||||||
|
equals(function() {
|
||||||
|
return hitResult.type == 'fill';
|
||||||
|
}, true);
|
||||||
|
equals(function() {
|
||||||
|
return hitResult.item == path;
|
||||||
|
}, true);
|
||||||
|
});
|
||||||
|
|
||||||
test('hitting path segments', function() {
|
test('hitting path segments', function() {
|
||||||
var path = new Path([0, 0], [10, 10], [20, 0]);
|
var path = new Path([0, 0], [10, 10], [20, 0]);
|
||||||
|
|
||||||
|
@ -297,4 +318,41 @@ test('hitting path bounding box', function() {
|
||||||
return hitResult.point.toString();
|
return hitResult.point.toString();
|
||||||
},path.bounds.topLeft.toString());
|
},path.bounds.topLeft.toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('hitting guides', function() {
|
||||||
|
var path = new Path.Circle(new Point(100, 100), 50);
|
||||||
|
path.fillColor = 'red';
|
||||||
|
|
||||||
|
var copy = path.clone();
|
||||||
|
|
||||||
|
var hitResult = paper.project.hitTest(path.position);
|
||||||
|
|
||||||
|
equals(function() {
|
||||||
|
return !!hitResult;
|
||||||
|
}, true, 'A HitResult should be returned (1)');
|
||||||
|
|
||||||
|
if (hitResult) {
|
||||||
|
equals(function() {
|
||||||
|
return hitResult.item == copy;
|
||||||
|
}, true, 'The copy is returned, because it is on top.');
|
||||||
|
}
|
||||||
|
|
||||||
|
path.guide = true;
|
||||||
|
|
||||||
|
var hitResult = paper.project.hitTest(path.position, {
|
||||||
|
guides: true
|
||||||
|
});
|
||||||
|
|
||||||
|
equals(function() {
|
||||||
|
return !!hitResult;
|
||||||
|
}, true, 'A HitResult should be returned (2)');
|
||||||
|
|
||||||
|
if (hitResult) {
|
||||||
|
equals(function() {
|
||||||
|
return hitResult.item == path;
|
||||||
|
}, true, 'The path is returned, because it is a guide.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: project.hitTest(point, {type: AnItemType});
|
Loading…
Reference in a new issue