From 01903a1005d849ce59b7555ea5e6e68995ff932c Mon Sep 17 00:00:00 2001 From: hkrish Date: Wed, 1 May 2013 22:55:50 +0200 Subject: [PATCH] Add tests for Exclusion and Division --- booleanStudy.html | 2 +- booleanTests.js | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/booleanStudy.html b/booleanStudy.html index 463958d4..c6f93c28 100644 --- a/booleanStudy.html +++ b/booleanStudy.html @@ -12,7 +12,7 @@ h1, h3 { font-family: 'Helvetica Neue'; font-weight: 300; margin: 50px 0 20px; } footer{display: block; width: 1000px; height: 100px; margin: 30px auto; color: #999; } footer p { font-family: 'Helvetica Neue'; font-style: italic; font-weight: 300; } - canvas { cursor: crosshair; width: 100%; height: 220px; margin: 5px 0;} + canvas { cursor: crosshair; width: 100%; height: 440px; margin: 5px 0;} .error { color: #a00; } .hide{ display: none; } diff --git a/booleanTests.js b/booleanTests.js index 5825deaf..056c0c97 100644 --- a/booleanTests.js +++ b/booleanTests.js @@ -160,7 +160,7 @@ function runTests() { 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, 60.5), [50, 100]) ); + 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] ); testBooleanStatic( pathA, pathB, caption ); @@ -283,7 +283,6 @@ function testBooleanStatic( path1, path2, caption, noUnion, noIntersection, noSu var boolPathI = intersect( _p1I, _p2I ); console.timeEnd( 'Intersection' ); boolPathI.style = booleanStyle; - window.p = boolPathI } if( !noSubtraction ) { @@ -295,6 +294,27 @@ function testBooleanStatic( path1, path2, caption, noUnion, noIntersection, noSu console.timeEnd( 'Subtraction' ); boolPathS.style = booleanStyle; } + + if( !noSubtraction ) { + var _p1E = path1.clone().translate( [250, 220] ); + var _p2E = path2.clone().translate( [250, 220] ); + _p1E.style = _p2E.style = pathStyleBoolean; + console.time( 'Exclusion' ); + var boolPathE = exclude( _p1E, _p2E ); + console.timeEnd( 'Exclusion' ); + boolPathE.style = booleanStyle; + } + + if( !noSubtraction && !noIntersection) { + var _p1D = path1.clone().translate( [500, 220] ); + var _p2D = path2.clone().translate( [500, 220] ); + _p1D.style = _p2D.style = pathStyleBoolean; + console.time( 'Division' ); + var boolPathD = divide( _p1D, _p2D ); + console.timeEnd( 'Division' ); + disperse( boolPathD ); + boolPathD.style = booleanStyle; + } // } catch( e ){ // console.error( e.name + ": " + e.message ); // if( caption ) { caption.className += ' error'; } @@ -309,7 +329,7 @@ function testBooleanStatic( path1, path2, caption, noUnion, noIntersection, noSu function disperse( path, distance ){ distance = distance || 10; - if( ! path instanceof CompoundPath ){ return; } + if( ! path instanceof CompoundPath || ! path instanceof Group ){ return; } var center = path.bounds.center; var children = path.children, i ,len; for (i = 0, len = children.length; i < len; i++) {