Clean-up unit test for #943 and add edge case from #944

See https://github.com/paperjs/paper.js/pull/944#issuecomment-180370569
This commit is contained in:
Jürg Lehni 2016-02-05 21:18:16 +01:00
parent ffe42a0220
commit a59a5354fb
2 changed files with 24 additions and 14 deletions

View file

@ -266,19 +266,31 @@ test('Path#contains() (straight curves with zero-winding)', function() {
for (var i = 0; i < pointData.length; i++) { for (var i = 0; i < pointData.length; i++) {
points.push(pointData[i][0]); points.push(pointData[i][0]);
} }
var path = new paper.Path({segments: points, closed: true}); var path = new Path({
path.setWindingRule("evenodd"); segments: points,
fillRule: 'evenodd',
var offsetPoint = function(p, xOffs, yOffs) { closed: true
return new paper.Point(p.x + xOffs, p.y + yOffs); });
}
for (var i = 0; i < pointData.length; i++) { for (var i = 0; i < pointData.length; i++) {
var p = new paper.Point(points[i]); var p = new Point(points[i]);
testPoint(path, p, true); // point is a segment of the path, must be inside testPoint(path, p, true); // point is a segment of the path, must be inside
testPoint(path, offsetPoint(p, 10, 0), pointData[i][1]); testPoint(path, p.add(10, 0), pointData[i][1]);
testPoint(path, offsetPoint(p, -10, 0), pointData[i][2]); testPoint(path, p.add(-10, 0), pointData[i][2]);
testPoint(path, offsetPoint(p, 0, 10), pointData[i][3]); testPoint(path, p.add(0, 10), pointData[i][3]);
testPoint(path, offsetPoint(p, 0, -10), pointData[i][4]); testPoint(path, p.add(0, -10), pointData[i][4]);
} }
}) });
test('CompoundPath#contains() (nested touching circles)', function() {
var c1 = new Path.Circle({
center: [200, 200],
radius: 100
});
var c2 = new Path.Circle({
center: [150, 200],
radius: 50
});
var cp = new CompoundPath([c1, c2]);
testPoint(cp, new Point(100, 200), true);
});

View file

@ -86,7 +86,6 @@ test('#571', function() {
]); ]);
}); });
test('overlapping circles', function() { test('overlapping circles', function() {
var path1 = new Path.Circle(new paper.Point(50, 50), 50); var path1 = new Path.Circle(new paper.Point(50, 50), 50);
var path2 = new Path.Circle(new paper.Point(100, 100), 50); var path2 = new Path.Circle(new paper.Point(100, 100), 50);
@ -96,7 +95,6 @@ test('overlapping circles', function() {
]); ]);
}); });
test('circle and square (existing segments overlaps on curves)', function() { test('circle and square (existing segments overlaps on curves)', function() {
var path1 = new Path.Circle(new Point(110, 110), 80); var path1 = new Path.Circle(new Point(110, 110), 80);
var path2 = new Path.Rectangle(new Point(110, 110), [100, 100]); var path2 = new Path.Rectangle(new Point(110, 110), [100, 100]);