More failure cases

This commit is contained in:
hkrish 2013-05-16 21:26:20 +02:00
parent f6e474da50
commit e6a98b4f18
2 changed files with 167 additions and 154 deletions

View file

@ -35,12 +35,14 @@
hari</p>
</footer>
<svg class="hide" version="1.1" id="svgrandom2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="200px" height="200px" viewBox="0 0 200 200" enable-background="new 0 0 200 200" xml:space="preserve">
</svg>
<svg class="hide" version="1.1" id="svgrandom1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="200px" height="200px" viewBox="0 0 200 200" enable-background="new 0 0 200 200" xml:space="preserve">
<path d="M121.938,15.632c-13.717-12.536 -86.488,106.314 -97.28853,96.70168c-10.79979,-9.61253 74.75206,22.03522 62.05339,14.94206c-12.69866,-7.09316 -39.33589,-120.29063 -50.13215,-122.55235c-10.79626,-2.26173 20.61549,120.92844 6.21122,120.91582c-14.40427,-0.01263 95.8736,-97.47028 79.15607,-110.0072z" />
<path d="M112.56135,26.45534c-11.3324,-19.66938 2.46546,15.5079 -15.74899,1.46029c-18.21444,-14.04761 -66.32694,49.96681 -85.68888,45.03851c-19.36194,-4.9283 25.00762,66.13871 9.65758,51.54906c-15.35004,-14.58966 80.2128,-61.80948 76.57166,-81.27628c-3.64115,-19.4668 26.54102,2.89779 15.20863,-16.77158z" />
</svg>
<svg class="hide" version="1.1" id="glyphsys" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="200px" height="200px" viewBox="0 0 200 200" enable-background="new 0 0 200 200" xml:space="preserve">
<path fill="none" d="M68.836,146.216c8.889,5.698,21.647,10.021,35.324,10.021c20.283,0,32.142-10.689,32.142-26.203

View file

@ -56,179 +56,190 @@ function runTests() {
// window.d = randomtestdata;
// container.removeChild( canvas );
// runTest('random', function(){
// pathA = getRandomPath(5);
// pathB = getRandomPath(5);
runTest('random', function(){
pathA = getRandomPath(5);
pathB = getRandomPath(5);
return [pathA, pathB];
});
// runTest('failcase 1', function(){
// group = paper.project.importSVG( document.getElementById( 'svgrandom1' ) );
// pathA = group.children[0];
// pathB = group.children[1];
// pathA.style = pathB.style = null;
// var np1 = new Path( [pathA.segments[0], pathA.segments[1]] );
// var np2 = new Path( [pathB.segments[0], pathB.segments[1]] );
// return [pathA, pathB];
// return [np1, np2];
// });
// runTest('failcase 2', function(){
// group = paper.project.importSVG( document.getElementById( 'svgrandom2' ) );
// pathA = group.children[0];
// pathB = group.children[1];
// pathA.style = pathB.style = null;
// var np1 = new Path( [pathA.segments[0], pathA.segments[1]] );
// var np2 = new Path( [pathB.segments[0], pathB.segments[1]] );
// return [pathA, pathB];
// return [np1, np2];
// });
// runTest('Overlapping circles', function(){
// pathA = new Path.Circle(new Point(80, 110), 50);
// pathB = new Path.Circle(new Point(150, 110), 70);
// return [pathA, pathB];
// });
runTest('random 2', function(){
group = paper.project.importSVG( document.getElementById( 'svgrandom1' ) );
pathA = group.children[0];
pathB = group.children[1];
pathA.style = pathB.style = null;
var np1 = new Path( [pathA.segments[0], pathA.segments[1]] );
var np2 = new Path( [pathB.segments[0], pathB.segments[1]] );
return [pathA, pathB];
return [np1, np2];
});
// // runTest('Polygon and square', function(){
// // pathA = new Path.RegularPolygon(new Point(80, 110), 12, 80);
// // pathB = new Path.Rectangle(new Point(100, 80), [80, 80] );
// // return [pathA, pathB];
// // });
runTest('Overlapping circles', function(){
pathA = new Path.Circle(new Point(80, 110), 50);
pathB = new Path.Circle(new Point(150, 110), 70);
return [pathA, pathB];
});
// // runTest('Circle and square (overlaps exactly on existing segments)', function(){
// // pathA = new Path.Circle(new Point(110, 110), 80);
// // pathB = new Path.Rectangle(new Point(110, 110), [80, 80] );
// // return [pathA, pathB];
// // });
// runTest('Polygon and square', function(){
// pathA = new Path.RegularPolygon(new Point(80, 110), 12, 80);
// pathB = new Path.Rectangle(new Point(100, 80), [80, 80] );
// // runTest('Circle and square (existing segments overlaps on curves)', function(){
// // pathA = new Path.Circle(new Point(110, 110), 80);
// // pathB = new Path.Rectangle(new Point(110, 110), [100, 100] );
// // return [pathA, pathB];
// // });
// // runTest('Square and square (one segment overlaps on a line)', function(){
// // pathA = new Path.Rectangle(new Point(80, 125), [50, 50] );
// // pathA.rotate( 45 );
// // pathB = new Path.Rectangle(new Point(pathA.segments[2].point.x, 110), [80, 80] );
// // return [pathA, pathB];
// // });
// // runTest('Rectangle and rectangle (overlaps exactly on existing curves)', function(){
// // pathA = new Path.Rectangle(new Point(30.5, 50.5), [100, 150]);
// // pathB = new Path.Rectangle(new Point(130.5, 60.5), [100, 150]);
// // return [pathA, pathB];
// // });
// // runTest('Overlapping stars 1', function(){
// // pathA = new Path.Star(new Point(80, 110), 10, 20, 80);
// // pathB = new Path.Star(new Point(120, 110), 10, 30, 100);
// // return [pathA, pathB];
// // });
// // runTest('Overlapping stars 2', function(){
// // pathA = new Path.Star(new Point(110, 110), 20, 20, 80);
// // pathB = new Path.Star(new Point(110, 110), 6, 30, 100);
// // return [pathA, pathB];
// // });
// runTest('Circle and banana (multiple intersections within same curve segment)', function(){
// pathA = new Path.Circle(new Point(80, 110), 80);
// pathB = new Path.Circle(new Point(130, 110), 80 );
// pathB.segments[3].point = pathB.segments[3].point.add( [ 0, -120 ] );
// return [pathA, pathB];
// });
// runTest('Circle and square (overlaps exactly on existing segments)', function(){
// pathA = new Path.Circle(new Point(110, 110), 80);
// pathB = new Path.Rectangle(new Point(110, 110), [80, 80] );
// runTest('Maximum possible intersections between 2 cubic bezier curve segments - 9', function(){
// pathA = new Path();
// pathA.add( new Segment( [173, 44], [-281, 268], [-86, 152] ) );
// pathA.add( new Segment( [47, 93], [-89, 100], [240, -239] ) );
// pathA.closed = true;
// pathB = pathA.clone();
// pathB.rotate( -90 );
// pathA.translate( [-10,0] );
// pathB.translate( [10,0] );
// return [pathA, pathB];
// });
// runTest('Circle and square (existing segments overlaps on curves)', function(){
// pathA = new Path.Circle(new Point(110, 110), 80);
// pathB = new Path.Rectangle(new Point(110, 110), [100, 100] );
// runTest('SVG gears', function(){
// group = paper.project.importSVG( document.getElementById( 'svggears' ) );
// pathA = group.children[0];
// pathB = group.children[1];
// return [pathA, pathB];
// });
// runTest('Glyphs imported from SVG', function(){
// group = paper.project.importSVG( document.getElementById( 'glyphsys' ) );
// pathA = group.children[0];
// pathB = group.children[1];
// return [pathA, pathB];
// });
// runTest('Square and square (one segment overlaps on a line)', function(){
// pathA = new Path.Rectangle(new Point(80, 125), [50, 50] );
// pathA.rotate( 45 );
// pathB = new Path.Rectangle(new Point(pathA.segments[2].point.x, 110), [80, 80] );
// runTest('CompoundPaths 1', function(){
// group = paper.project.importSVG( document.getElementById( 'glyphsacirc' ) );
// pathA = group.children[0];
// pathB = group.children[1];
// return [pathA, pathB];
// });
// runTest('Rectangle and rectangle (overlaps exactly on existing curves)', function(){
// pathA = new Path.Rectangle(new Point(30.5, 50.5), [100, 150]);
// pathB = new Path.Rectangle(new Point(130.5, 60.5), [100, 150]);
// return [pathA, pathB];
// });
// runTest('Overlapping stars 1', function(){
// pathA = new Path.Star(new Point(80, 110), 10, 20, 80);
// pathB = new Path.Star(new Point(120, 110), 10, 30, 100);
// return [pathA, pathB];
// });
// runTest('Overlapping stars 2', function(){
// pathA = new Path.Star(new Point(110, 110), 20, 20, 80);
// pathB = new Path.Star(new Point(110, 110), 6, 30, 100);
// return [pathA, pathB];
// });
runTest('Circle and banana (multiple intersections within same curve segment)', function(){
pathA = new Path.Circle(new Point(80, 110), 80);
pathB = new Path.Circle(new Point(130, 110), 80 );
pathB.segments[3].point = pathB.segments[3].point.add( [ 0, -120 ] );
return [pathA, pathB];
});
runTest('Maximum possible intersections between 2 cubic bezier curve segments - 9', function(){
pathA = new Path();
pathA.add( new Segment( [173, 44], [-281, 268], [-86, 152] ) );
pathA.add( new Segment( [47, 93], [-89, 100], [240, -239] ) );
pathA.closed = true;
pathB = pathA.clone();
pathB.rotate( -90 );
pathA.translate( [-10,0] );
pathB.translate( [10,0] );
return [pathA, pathB];
});
runTest('SVG gears', function(){
group = paper.project.importSVG( document.getElementById( 'svggears' ) );
pathA = group.children[0];
pathB = group.children[1];
return [pathA, pathB];
});
runTest('Glyphs imported from SVG', function(){
group = paper.project.importSVG( document.getElementById( 'glyphsys' ) );
pathA = group.children[0];
pathB = group.children[1];
return [pathA, pathB];
});
runTest('CompoundPaths 1', function(){
group = paper.project.importSVG( document.getElementById( 'glyphsacirc' ) );
pathA = group.children[0];
pathB = group.children[1];
return [pathA, pathB];
});
runTest('CompoundPaths 2 - holes', function(){
group = paper.project.importSVG( document.getElementById( 'glyphsacirc' ) );
pathA = group.children[0];
pathB = new CompoundPath();
group.children[1].clockwise = true;
pathB.addChild(group.children[1]);
var npath = new Path.Circle([110, 110], 30);
pathB.addChild( npath );
return [pathA, pathB];
});
runTest('CompoundPaths 3 !', function(){
group = paper.project.importSVG( document.getElementById( 'svggreenland' ) );
pathA = group.children[0];
pathB = group.children[1];
pathB.scale( 0.5, 1 ).translate( [25.5, 0] );
// pathA.scale( 2 );
// pathB.scale( 2 );
return [pathA, pathB];
});
runTest('CompoundPaths 4 - holes and islands 1', function(){
group = paper.project.importSVG( document.getElementById( 'glyphsacirc' ) );
pathA = group.children[0];
pathB = new CompoundPath();
group.children[1].clockwise = true;
pathB.addChild(group.children[1]);
var npath = new Path.Circle([40, 80], 20);
pathB.addChild( npath );
return [pathA, pathB];
});
runTest('CompoundPaths 5 - holes and islands 2', function(){
group = paper.project.importSVG( document.getElementById( 'glyphsacirc' ) );
pathA = group.children[0];
pathB = new CompoundPath();
group.children[1].clockwise = true;
pathB.addChild(group.children[1]);
var npath = new Path.Circle([40, 80], 20);
pathB.addChild( npath );
npath = new Path.Circle([120, 110], 30);
pathB.addChild( npath );
return [pathA, pathB];
});
runTest('CompoundPaths 6 - holes and islands 3', function(){
group = paper.project.importSVG( document.getElementById( 'glyphsacirc' ) );
pathA = group.children[0];
pathB = new CompoundPath();
var npath = new Path.Circle([110, 110], 100);
pathB.addChild( npath );
npath = new Path.Circle([110, 110], 60);
pathB.addChild( npath );
npath = new Path.Circle([110, 110], 30);
pathB.addChild( npath );
return [pathA, pathB];
});
// runTest('CompoundPaths 6 - holes and islands 4 (curves overlap exactly on existing curves)', function(){
// pathA = new Path.Rectangle(new Point(50.5, 50.5), [100, 120]);
// runTest('CompoundPaths 2 - holes', function(){
// group = paper.project.importSVG( document.getElementById( 'glyphsacirc' ) );
// pathA = group.children[0];
// pathB = new CompoundPath();
// pathB.addChild( new Path.Rectangle(new Point(140.5, 30.5), [100, 150]) );
// pathB.addChild( new Path.Rectangle(new Point(150.5, 65.5), [50, 100]) );
// // pathB = new Path.Rectangle(new Point(150.5, 80.5), [80, 80] );
// group.children[1].clockwise = true;
// pathB.addChild(group.children[1]);
// var npath = new Path.Circle([110, 110], 30);
// pathB.addChild( npath );
// return [pathA, pathB];
// });
// runTest('CompoundPaths 3 !', function(){
// group = paper.project.importSVG( document.getElementById( 'svggreenland' ) );
// pathA = group.children[0];
// pathB = group.children[1];
// pathB.scale( 0.5, 1 ).translate( [25.5, 0] );
// // pathA.scale( 2 );
// // pathB.scale( 2 );
// return [pathA, pathB];
// });
// runTest('CompoundPaths 4 - holes and islands 1', function(){
// group = paper.project.importSVG( document.getElementById( 'glyphsacirc' ) );
// pathA = group.children[0];
// pathB = new CompoundPath();
// group.children[1].clockwise = true;
// pathB.addChild(group.children[1]);
// var npath = new Path.Circle([40, 80], 20);
// pathB.addChild( npath );
// return [pathA, pathB];
// });
// runTest('CompoundPaths 5 - holes and islands 2', function(){
// group = paper.project.importSVG( document.getElementById( 'glyphsacirc' ) );
// pathA = group.children[0];
// pathB = new CompoundPath();
// group.children[1].clockwise = true;
// pathB.addChild(group.children[1]);
// var npath = new Path.Circle([40, 80], 20);
// pathB.addChild( npath );
// npath = new Path.Circle([120, 110], 30);
// pathB.addChild( npath );
// return [pathA, pathB];
// });
// runTest('CompoundPaths 6 - holes and islands 3', function(){
// group = paper.project.importSVG( document.getElementById( 'glyphsacirc' ) );
// pathA = group.children[0];
// pathB = new CompoundPath();
// var npath = new Path.Circle([110, 110], 100);
// pathB.addChild( npath );
// npath = new Path.Circle([110, 110], 60);
// pathB.addChild( npath );
// npath = new Path.Circle([110, 110], 30);
// pathB.addChild( npath );
// return [pathA, pathB];
// });
// // runTest('CompoundPaths 6 - holes and islands 4 (curves overlap exactly on existing curves)', function(){
// // pathA = new Path.Rectangle(new Point(50.5, 50.5), [100, 120]);
// // pathB = new CompoundPath();
// // pathB.addChild( new Path.Rectangle(new Point(140.5, 30.5), [100, 150]) );
// // pathB.addChild( new Path.Rectangle(new Point(150.5, 65.5), [50, 100]) );
// // // pathB = new Path.Rectangle(new Point(150.5, 80.5), [80, 80] );
// // return [pathA, pathB];
// // });
// Plot the run times
function plotData(){
@ -411,7 +422,7 @@ var pathStyleBoolean = {
// Better if path1 and path2 fit nicely inside a 200x200 pixels rect
function testIntersections( path1, path2, caption, testname, testdata, nomark) {
var i, l, maxCount = 100, count = maxCount, st, t1, t2,
var i, l, maxCount = 1, count = maxCount, st, t1, t2,
ixsPaper, ixsFatline, success = false, maxdiff = -Infinity;
try{
path1.style = path2.style = pathStyleNormal;