From ef8ba35911114dd8d4136c64ed7bd1a0f0cb16c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sat, 22 Jun 2019 18:21:47 +0200 Subject: [PATCH] Implement unit tests for 3ff5560c0c16a1ecd581ab558d6682becd6ddd75 Closes #1419, closes #1263 --- src/path/CurveLocation.js | 2 +- test/helpers.js | 4 ++-- test/tests/Path_Boolean.js | 13 +++++++++++++ test/tests/Path_Intersections.js | 13 +++++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/path/CurveLocation.js b/src/path/CurveLocation.js index 994840f7..7ebd41c8 100644 --- a/src/path/CurveLocation.js +++ b/src/path/CurveLocation.js @@ -492,7 +492,7 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{ // Count how many times curve2 angles appear between the curve1 angles. // If each pair of angles split the other two, then the edges cross. // Use t1Inside to decide which angle pair to check against. - // If t1 is inside the curve, check against a3 & a4, othrwise a1 & a2. + // If t1 is inside the curve, check against a3 & a4, otherwise a1 & a2. return !!(t1Inside ? (isInRange(a1, a3, a4) ^ isInRange(a2, a3, a4)) && (isInRange(a1, a4, a3) ^ isInRange(a2, a4, a3)) diff --git a/test/helpers.js b/test/helpers.js index 28e8be91..fcb0b356 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -227,8 +227,8 @@ var compareImageData = function(imageData1, imageData2, tolerance, diffDetail) { var entry = document.getElementById('qunit-test-output-' + id) .querySelector('li:nth-child(' + (index) + ')'), bounds = result.diffBounds; - entry.querySelector('.test-expected td').appendChild(image(imageData1)); - entry.querySelector('.test-actual td').appendChild(image(imageData2)); + entry.querySelector('.test-expected td').appendChild(image(imageData2)); + entry.querySelector('.test-actual td').appendChild(image(imageData1)); entry.querySelector('.test-diff td').innerHTML = '
' + detail
             + '

' + ''; diff --git a/test/tests/Path_Boolean.js b/test/tests/Path_Boolean.js index c965ee89..764fdcae 100644 --- a/test/tests/Path_Boolean.js +++ b/test/tests/Path_Boolean.js @@ -1202,3 +1202,16 @@ test('#1513', function () { var result = 'M100,100h200v100c0,-55.22847 -44.77153,-100 -100,-100c-55.22847,0 -100,44.77153 -100,100z'; compareBoolean(path1.subtract(path2), result); }); + +test('#1419', function() { + var circle1 = Path.Circle({ + center: [0, 0], + radius: 50 + }); + var circle2 = Path.Circle({ + center: circle1.position.subtract(25), + radius: 50 + }); + var result = 'M-50,0c0,-27.61424 22.38576,-50 50,-50c7.33673,0 14.30439,1.5802 20.58119,4.41881c-7.84546,-17.34804 -25.30368,-29.41881 -45.58119,-29.41881c-27.61424,0 -50,22.38576 -50,50c0,20.27751 12.07077,37.73573 29.41881,45.58119c-2.83861,-6.2768 -4.41881,-13.24446 -4.41881,-20.58119zM50,0c0,27.61424 -22.38576,50 -50,50c-20.27751,0 -37.73573,-12.07077 -45.58119,-29.41881c6.2768,2.83861 13.24446,4.41881 20.58119,4.41881c27.61424,0 50,-22.38576 50,-50c0,-7.33673 -1.5802,-14.30439 -4.41881,-20.58119c17.34804,7.84546 29.41881,25.30368 29.41881,45.58119z'; + compareBoolean(circle1.exclude(circle2), result); +}) diff --git a/test/tests/Path_Intersections.js b/test/tests/Path_Intersections.js index 53b25e36..4c1450df 100644 --- a/test/tests/Path_Intersections.js +++ b/test/tests/Path_Intersections.js @@ -358,3 +358,16 @@ test('#1638', function() { { point: { x: 58.83762, y: 191.16238 }, index: 3, time: 0.26569, crossing: true } ]); }) + +test('#1263', function() { + var path = new Path({ + segments: [ + [[479,495], [0,0], [-10,4]], + [[437,479], [5,12], [-22,-51]], + [[479,495], [33,-15]] + ] + }); + testIntersections(path.getIntersections(), [ + { point: { x: 479, y: 495 }, index: 0, time: 0, crossing: false } + ]); +})