mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Replace the "straight curves with zero-winding" test with a more comprehensive one containing more special cases. Also, this test requires that all points on a curve of a path must be counted as inside the path.
This commit is contained in:
parent
41aca10112
commit
e03c8cd198
1 changed files with 59 additions and 57 deletions
|
@ -216,67 +216,69 @@ test('Path#contains() (complex shape)', function() {
|
||||||
|
|
||||||
|
|
||||||
test('Path#contains() (straight curves with zero-winding)', function() {
|
test('Path#contains() (straight curves with zero-winding)', function() {
|
||||||
var pathPoints = [
|
var pointData = [
|
||||||
[140, 100],
|
[[250, 230], true, true, false, true],
|
||||||
[140, 10],
|
[[200, 230], true, true, true, true],
|
||||||
[100, 10],
|
[[200, 280], false, true, false, true],
|
||||||
[100, 20],
|
[[190, 280], true, false, false, true],
|
||||||
[120, 20],
|
[[175, 270], true, true, false, true],
|
||||||
[120, 40],
|
[[175, 220], true, true, true, true],
|
||||||
[100, 40],
|
[[175, 270], true, true, false, true],
|
||||||
[100, 60],
|
[[160, 280], false, true, false, true],
|
||||||
[200, 60],
|
[[150, 280], true, false, false, true],
|
||||||
[120, 60],
|
[[150, 220], true, false, true, true],
|
||||||
[120, 100],
|
[[150, 200], true, true, true, true],
|
||||||
[300, 100],
|
[[100, 200], true, false, false, true],
|
||||||
[50, 100]
|
[[100, 190], true, true, true, true],
|
||||||
|
[[50, 190], true, false, false, false],
|
||||||
|
[[100, 190], true, true, true, true],
|
||||||
|
[[100, 180], true, false, true, false],
|
||||||
|
[[150, 180], true, true, true, true],
|
||||||
|
[[150, 160], true, false, true, true],
|
||||||
|
[[150, 100], true, false, true, false],
|
||||||
|
[[160, 100], false, true, true, false],
|
||||||
|
[[175, 110], true, true, true, false],
|
||||||
|
[[175, 160], true, true, true, true],
|
||||||
|
[[175, 110], true, true, true, false],
|
||||||
|
[[190, 100], true, false, true, false],
|
||||||
|
[[200, 100], false, true, true, false],
|
||||||
|
[[200, 150], true, true, true, true],
|
||||||
|
[[250, 150], true, true, true, false],
|
||||||
|
[[270, 120], false, false, true, true],
|
||||||
|
[[270, 90], false, false, true, false],
|
||||||
|
[[270, 120], false, false, true, true],
|
||||||
|
[[290, 150], false, true, true, false],
|
||||||
|
[[290, 180], true, true, true, true],
|
||||||
|
[[340, 180], false, true, true, false],
|
||||||
|
[[340, 190], true, true, true, true],
|
||||||
|
[[390, 190], false, true, false, false],
|
||||||
|
[[340, 190], true, true, true, true],
|
||||||
|
[[340, 200], false, true, false, true],
|
||||||
|
[[290, 200], true, true, true, true],
|
||||||
|
[[290, 230], false, true, false, true],
|
||||||
|
[[270, 260], false, false, true, true],
|
||||||
|
[[270, 290], false, false, false, true],
|
||||||
|
[[270, 260], false, false, true, true],
|
||||||
|
[[250, 230], true, true, false, true]
|
||||||
];
|
];
|
||||||
|
|
||||||
var path1 = new Path({
|
var points = [];
|
||||||
segments: pathPoints,
|
for (var i = 0; i < pointData.length; i++) {
|
||||||
closed: true,
|
points.push(pointData[i][0]);
|
||||||
fillRule: 'evenodd'
|
}
|
||||||
});
|
var path = new paper.Path({segments: points, closed: true});
|
||||||
|
path.setWindingRule("evenodd");
|
||||||
|
|
||||||
var hitPoints = [
|
var offsetPoint = function(p, xOffs, yOffs) {
|
||||||
[[30,10], false],
|
return new paper.Point(p.x + xOffs, p.y + yOffs);
|
||||||
[[110,10], true],
|
|
||||||
[[30,20], false],
|
|
||||||
[[110,20], true],
|
|
||||||
[[130,20], true],
|
|
||||||
[[170,20], false],
|
|
||||||
[[110,50], true],
|
|
||||||
[[30,60], false],
|
|
||||||
[[110,60], true],
|
|
||||||
[[130,60], true],
|
|
||||||
[[150,60], false],
|
|
||||||
[[230,60], false],
|
|
||||||
[[10,100], false],
|
|
||||||
[[60,100], false],
|
|
||||||
[[130,100], true],
|
|
||||||
[[170,100], false],
|
|
||||||
[[370,100], false]
|
|
||||||
];
|
|
||||||
|
|
||||||
for (var i = 0; i < hitPoints.length; i++) {
|
|
||||||
var entry = hitPoints[i];
|
|
||||||
testPoint(path1, new Point(entry[0]), entry[1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now test the x-y-reversed shape
|
for (var i = 0; i < pointData.length; i++) {
|
||||||
|
var p = new paper.Point(points[i]);
|
||||||
for (var i = 0; i < pathPoints.length; i++) {
|
testPoint(path, p, true); // point is a segment of the path, must be inside
|
||||||
pathPoints[i].reverse();
|
testPoint(path, offsetPoint(p, 10, 0), pointData[i][1]);
|
||||||
}
|
testPoint(path, offsetPoint(p, -10, 0), pointData[i][2]);
|
||||||
|
testPoint(path, offsetPoint(p, 0, 10), pointData[i][3]);
|
||||||
var path1 = new Path({
|
testPoint(path, offsetPoint(p, 0, -10), pointData[i][4]);
|
||||||
segments: pathPoints,
|
|
||||||
closed: true,
|
|
||||||
fillRule: 'evenodd'
|
|
||||||
});
|
|
||||||
|
|
||||||
for (var i = 0; i < hitPoints.length; i++) {
|
|
||||||
var entry = hitPoints[i];
|
|
||||||
testPoint(path1, new Point(entry[0].reverse()), entry[1]);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue