int SpiroCPsToBezier0(spiro_cp *spiros,int n,int isclosed,bezctx *bc) { spiro_seg *s; if ( n<=0 ) return 0; if ( isclosed ) s = run_spiro(spiros,n); else { char oldty_start = spiros[0].ty; char oldty_end = spiros[n-1].ty; spiros[0].ty = '{'; spiros[n-1].ty = '}'; s = run_spiro(spiros,n); spiros[n-1].ty = oldty_end; spiros[0].ty = oldty_start; } if (s) { spiro_to_bpath(s,n,bc); free_spiro(s); return 1; // success } return 0 ; // spiro did not converge or encountered non-finite values }
int test_curve(int c) { spiro_cp spiro[16]; int nextknot[17]; spiro_seg *segs = NULL; bezctx *bc; int i; /* Load sample data so that we can see if library is callable */ load_test_curve(spiro,nextknot,c); /* Check if run_spiro works okay */ printf("testing run_spiro() using data=path%d[].\n",c); if ( (segs=run_spiro(spiro,cl[c]))==0 ) { printf("error with run_spiro() using data=path%d[].\n",c); return -1; } /* Quick visual check shows X,Y knots match with each pathN[] */ for (i=0; i < cl[c]; i++) { printf("curve %d, line %d, x=%f y=%f t=%c bend=%f ch=%f th=%f l=%f \n",c,i,segs[i].x,segs[i].y,segs[i].ty,segs[i].bend_th,segs[i].seg_ch,segs[i].seg_th,segs[i].l); } /* Quick visual check shows X,Y knots match with each pathN[] */ printf("testing spiro_to_bpath() using data from run_spiro(data=path%d[],len=%d).\n",c,cl[c]); bc = new_bezctx_test(); spiro_to_bpath(segs,cl[c],bc); free(segs); /* Check if TaggedSpiroCPsToBezier0() works okay */ printf("---\ntesting TaggedSpiroCPsToBezier0() using data=path%d[].\n",c); if ( TaggedSpiroCPsToBezier0(spiro,bc)!=1 ) { printf("error with TaggedSpiroCPsToBezier0() using data=path%d[].\n",c); return -1; } /* Check if SpiroCPsToBezier0() works okay */ printf("---\ntesting SpiroCPsToBezier0() using data=path%d[].\n",c); if ( SpiroCPsToBezier0(spiro,cl[c],(c==0 ? 1 : 0),bc)!=1 ) { printf("error with SpiroCPsToBezier0() using data=path%d[].\n",c); return -1; } free(bc); return 0; }
int TaggedSpiroCPsToBezier0(spiro_cp *spiros,bezctx *bc) { spiro_seg *s; int n; for ( n=0; spiros[n].ty!='z' && spiros[n].ty!='}'; ++n ); if ( spiros[n].ty == '}' ) ++n; if ( n<=0 ) return 0; // invalid input s = run_spiro(spiros,n); if (s) { spiro_to_bpath(s,n,bc); free_spiro(s); return 1; // success } return 0 ; // spiro did not converge or encountered non-finite values }