From a59a5354fba4fcdab5af58eb834e9ad81563f934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Fri, 5 Feb 2016 21:18:16 +0100 Subject: [PATCH] Clean-up unit test for #943 and add edge case from #944 See https://github.com/paperjs/paper.js/pull/944#issuecomment-180370569 --- test/tests/PathItem_Contains.js | 36 +++++++++++++++++++++----------- test/tests/Path_Intersections.js | 2 -- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/test/tests/PathItem_Contains.js b/test/tests/PathItem_Contains.js index f633977b..a3b3d6f0 100644 --- a/test/tests/PathItem_Contains.js +++ b/test/tests/PathItem_Contains.js @@ -266,19 +266,31 @@ test('Path#contains() (straight curves with zero-winding)', function() { for (var i = 0; i < pointData.length; i++) { points.push(pointData[i][0]); } - var path = new paper.Path({segments: points, closed: true}); - path.setWindingRule("evenodd"); - - var offsetPoint = function(p, xOffs, yOffs) { - return new paper.Point(p.x + xOffs, p.y + yOffs); - } + var path = new Path({ + segments: points, + fillRule: 'evenodd', + closed: true + }); 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, 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]); - testPoint(path, offsetPoint(p, 0, -10), pointData[i][4]); + testPoint(path, p.add(10, 0), pointData[i][1]); + testPoint(path, p.add(-10, 0), pointData[i][2]); + testPoint(path, p.add(0, 10), pointData[i][3]); + 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); +}); diff --git a/test/tests/Path_Intersections.js b/test/tests/Path_Intersections.js index 07b983cb..c3ba5208 100644 --- a/test/tests/Path_Intersections.js +++ b/test/tests/Path_Intersections.js @@ -86,7 +86,6 @@ test('#571', function() { ]); }); - test('overlapping circles', function() { var path1 = new Path.Circle(new paper.Point(50, 50), 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() { var path1 = new Path.Circle(new Point(110, 110), 80); var path2 = new Path.Rectangle(new Point(110, 110), [100, 100]);