Skip to content

Commit

Permalink
Move the debug helper functions to the test file for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
hkrish committed May 20, 2013
1 parent 9e02cb5 commit 068a84e
Showing 1 changed file with 149 additions and 72 deletions.
221 changes: 149 additions & 72 deletions intersectTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,8 @@ function doRandomTests( testdata ){
ixsfat = getIntersections2( p1, p2 );
t2 = (getTimestamp() - st);
// Check against paperjs output
var found = 0, tol = 1;
// tol - tolerence for computed points with in 1/10 th of a pixel
var found = 0, tol = 0.1;
if( ixsfat.length === ixspaper.length ){
for(i=0, l=ixsfat.length; i<l; i++){
pa = ixsfat[i].point;
Expand Down Expand Up @@ -668,82 +669,158 @@ function annotateCurve( crv, t, c, tc, remove ) {


// Plot the run times
function plotDataRandom( testdata ){
var x = 80.5, y = 15.5, width = 500, height = 190, i, txt, ny,
yy = y + height, xx = x + width;
var ppaper = new Path(), pfat = new Path();
var max = testdata.reduce(function( a, b ){ return Math.max( a, b.paperTime, b.fatTime ); }, 0) + 20;
testdata.sort( function(a,b){ return a.ratio - b.ratio; } );
var vscale = height / max, hscale = width / testdata.length;
var caxes = '#999', ctxt = '#222', cpaper = '#268BD2', cfat = '#D33682';
new Path.Line( x, yy, xx, yy ).style.strokeColor = caxes;
new Path.Line( x, yy, x, y ).style.strokeColor = caxes;
for( i = 0; i < 10 ; i++ ){
ny = yy - vscale * max * i / 10;
new Path.Line( x, ny, x-5, ny ).style.strokeColor = caxes;
txt = new PointText( [x-10, ny] );
txt.justification = 'right';
txt.fillColor = ctxt;
txt.content = (max * i / 10).toFixed(1) + ((!i)? ' ms' : '');
}
txt = new PointText([xx + 20, yy + 18 ]);
txt.justification = 'left';
function plotDataRandom( testdata ){
var x = 80.5, y = 15.5, width = 500, height = 190, i, txt, ny,
yy = y + height, xx = x + width;
var ppaper = new Path(), pfat = new Path();
var max = testdata.reduce(function( a, b ){ return Math.max( a, b.paperTime, b.fatTime ); }, 0) + 20;
testdata.sort( function(a,b){ return a.ratio - b.ratio; } );
var vscale = height / max, hscale = width / testdata.length;
var caxes = '#999', ctxt = '#222', cpaper = '#268BD2', cfat = '#D33682';
new Path.Line( x, yy, xx, yy ).style.strokeColor = caxes;
new Path.Line( x, yy, x, y ).style.strokeColor = caxes;
for( i = 0; i < 10 ; i++ ){
ny = yy - vscale * max * i / 10;
new Path.Line( x, ny, x-5, ny ).style.strokeColor = caxes;
txt = new PointText( [x-10, ny] );
txt.justification = 'right';
txt.fillColor = ctxt;
txt.content = (max * i / 10).toFixed(1) + ((!i)? ' ms' : '');
}
txt = new PointText([xx + 20, yy + 18 ]);
txt.justification = 'left';
txt.fillColor = ctxt;
txt.content = 'ixs / curve';
txt = new PointText([xx + 20, yy + 40]);
txt.justification = 'left';
txt.fillColor = '#999';
txt.content = '( Total Curves )';
var vx = x, step = 15, count = 0;
var avgPaper = 0, avgFat = 0;
testdata.map(function(data){
avgPaper += data.paperTime;
ny = yy - (data.paperTime + data.fatTime) * vscale;
ppaper.add( new Segment([vx, ny]) );
avgFat += data.fatTime;
ny = yy - (data.fatTime) * vscale;
pfat.add( new Segment([vx, ny]) );

new Path.Line( vx, yy, vx, yy + 5 + ((count%2)? step:0) ).style.strokeColor = caxes;
txt = new PointText( [vx, yy+18 + ((count%2)? step:0) ] );
txt.justification = 'center';
txt.fillColor = ctxt;
txt.content = 'ixs / curve';
txt = new PointText([xx + 20, yy + 40]);
txt.content = data.ratio.toFixed(1);
txt = new PointText( [vx -5, yy+40 ] );
txt.justification = 'left';
txt.fillColor = '#999';
txt.content = '( Total Curves )';
var vx = x, step = 15, count = 0;
var avgPaper = 0, avgFat = 0;
testdata.map(function(data){
avgPaper += data.paperTime;
ny = yy - (data.paperTime + data.fatTime) * vscale;
ppaper.add( new Segment([vx, ny]) );
avgFat += data.fatTime;
ny = yy - (data.fatTime) * vscale;
pfat.add( new Segment([vx, ny]) );
txt.content = data.curves;
txt.rotate( 90, [vx-5, yy+40 ] );

new Path.Line( vx, yy, vx, yy + 5 + ((count%2)? step:0) ).style.strokeColor = caxes;
txt = new PointText( [vx, yy+18 + ((count%2)? step:0) ] );
txt.justification = 'center';
txt.fillColor = ctxt;
txt.content = data.ratio.toFixed(1);
txt = new PointText( [vx -5, yy+40 ] );
txt.justification = 'left';
txt.fillColor = '#999';
txt.content = data.curves;
txt.rotate( 90, [vx-5, yy+40 ] );
if( !data.success ){
var p = new Path.Line( vx, y, vx, yy );
p.style.strokeWidth = 5;
p.style.strokeColor = '#f00';
}
++count;
vx += hscale;
});
ppaper.smooth();
ppaper.style.strokeWidth = 2;
ppaper.style.strokeColor = cpaper;
pfat.smooth();
pfat.style.strokeWidth = 2;
pfat.style.strokeColor = cfat;

avgPaper/= testdata.length;
avgFat/= testdata.length;
ny = Math.round(yy - avgPaper * vscale) + 0.5;
new Path.Line(x, ny, xx, ny).style.strokeColor = cpaper;
txt = new PointText( [xx, ny] );
txt.justification = 'right';
txt.fillColor = cpaper;
txt.content = avgPaper.toFixed(1);
ny = Math.round(yy - avgFat * vscale) + 0.5;
new Path.Line(x, ny, xx, ny).style.strokeColor = cfat;
txt = new PointText( [xx, ny] );
txt.justification = 'right';
txt.fillColor = cfat;
txt.content = avgFat.toFixed(1);

if( !data.success ){
var p = new Path.Line( vx, y, vx, yy );
p.style.strokeWidth = 5;
p.style.strokeColor = '#f00';
}
++count;
vx += hscale;
});
ppaper.smooth();
ppaper.style.strokeWidth = 2;
ppaper.style.strokeColor = cpaper;
pfat.smooth();
pfat.style.strokeWidth = 2;
pfat.style.strokeColor = cfat;
view.draw();
}

avgPaper/= testdata.length;
avgFat/= testdata.length;
ny = Math.round(yy - avgPaper * vscale) + 0.5;
new Path.Line(x, ny, xx, ny).style.strokeColor = cpaper;
txt = new PointText( [xx, ny] );
txt.justification = 'right';
txt.fillColor = cpaper;
txt.content = avgPaper.toFixed(1);
ny = Math.round(yy - avgFat * vscale) + 0.5;
new Path.Line(x, ny, xx, ny).style.strokeColor = cfat;
txt = new PointText( [xx, ny] );
txt.justification = 'right';
txt.fillColor = cfat;
txt.content = avgFat.toFixed(1);


function drawFatline( v1 ) {
function signum(num) {
return ( num > 0 )? 1 : ( num < 0 )? -1 : 0;
}
var l = new Line( [v1[0], v1[1]], [v1[6], v1[7]], false );
var p1 = new Point( v1[2], v1[3] ), p2 = new Point( v1[4], v1[5] );
var d1 = l.getSide( p1 ) * l.getDistance( p1 ) || 0;
var d2 = l.getSide( p2 ) * l.getDistance( p2 ) || 0;
var dmin, dmax;
if( d1 * d2 > 0){
// 3/4 * min{0, d1, d2}
dmin = 0.75 * Math.min( 0, d1, d2 );
dmax = 0.75 * Math.max( 0, d1, d2 );
} else {
// 4/9 * min{0, d1, d2}
dmin = 4 * Math.min( 0, d1, d2 ) / 9.0;
dmax = 4 * Math.max( 0, d1, d2 ) / 9.0;
}
var ll = new Path.Line( v1[0], v1[1], v1[6], v1[7] );
window.__p3.push( ll );
window.__p3[window.__p3.length-1].style.strokeColor = new Color( 0,0,0.9, 0.8);
var lp1 = ll.segments[0].point;
var lp2 = ll.segments[1].point;
var pm = l.vector, pm1 = pm.rotate( signum( dmin ) * -90 ), pm2 = pm.rotate( signum( dmax ) * -90 );
var p11 = lp1.add( pm1.normalize( Math.abs(dmin) ) );
var p12 = lp2.add( pm1.normalize( Math.abs(dmin) ) );
var p21 = lp1.add( pm2.normalize( Math.abs(dmax) ) );
var p22 = lp2.add( pm2.normalize( Math.abs(dmax) ) );
window.__p3.push( new Path.Line( p11, p12 ) );
window.__p3[window.__p3.length-1].style.strokeColor = new Color( 0,0,0.9);
window.__p3.push( new Path.Line( p21, p22 ) );
window.__p3[window.__p3.length-1].style.strokeColor = new Color( 0,0,0.9);
}

function plotD_vs_t( x, y, arr, arr2, v, dmin, dmax, tmin, tmax, yscale, tvalue ){
yscale = yscale || 1;
new Path.Line( x, y-100, x, y+100 ).style.strokeColor = '#aaa';
new Path.Line( x, y, x + 200, y ).style.strokeColor = '#aaa';

var clr = (tvalue)? '#a00' : '#00a';
if( window.__p3 ) window.__p3.map(function(a){a.remove();});

window.__p3 = [];

drawFatline( v );

window.__p3.push( new Path.Line( x, y + dmin * yscale, x + 200, y + dmin * yscale ) );
window.__p3[window.__p3.length-1].style.strokeColor = '#000'
window.__p3.push( new Path.Line( x, y + dmax * yscale, x + 200, y + dmax * yscale ) );
window.__p3[window.__p3.length-1].style.strokeColor = '#000'
window.__p3.push( new Path.Line( x + tmin * 190, y-100, x + tmin * 190, y+100 ) );
window.__p3[window.__p3.length-1].style.strokeColor = clr
window.__p3.push( new Path.Line( x + tmax * 190, y-100, x + tmax * 190, y+100 ) );
window.__p3[window.__p3.length-1].style.strokeColor = clr

for (var i = 0; i < arr.length; i++) {
window.__p3.push( new Path.Line( new Point( x + arr[i][0] * 190, y + arr[i][1] * yscale ),
new Point( x + arr[i][2] * 190, y + arr[i][3] * yscale ) ) );
window.__p3[window.__p3.length-1].style.strokeColor = '#999';
}
var pnt = [];
var arr2x = [ 0.0, 0.333333333, 0.6666666666, 1.0 ];
for (var i = 0; i < arr2.length; i++) {
pnt.push( new Point( x + arr2x[i] * 190, y + arr2[i] * yscale ) );
window.__p3.push( new Path.Circle( pnt[pnt.length-1], 2 ) );
window.__p3[window.__p3.length-1].style.fillColor = '#000'
}
// var pth = new Path( pnt[0], pnt[1], pnt[2], pnt[3] );
// pth.closed = true;
window.__p3.push( new Path( new Segment(pnt[0], null, pnt[1].subtract(pnt[0])), new Segment( pnt[3], pnt[2].subtract(pnt[3]), null ) ) );
window.__p3[window.__p3.length-1].style.strokeColor = clr
view.draw();
}
}

0 comments on commit 068a84e

Please sign in to comment.