// ---------------------------------------------------------------------------
// 
// ------------
void bSmoothElement::makecurve(	float *xpts, 
								float *ypts, 
								int npts, 
								int *cur, 
								curve *crv, 
								int level, 
								float *lastx, 
								float *lasty){
							
	curve	left,right;

	if(level>0){
		left.startx=crv->startx;
		left.starty=crv->starty;
		
		mid(&left.controlx,&left.controly,crv->startx,crv->starty,crv->controlx,crv->controly);
		mid(&right.controlx,&right.controly,crv->controlx,crv->controly,crv->endx,crv->endy);
		mid(&left.endx,&left.endy,left.controlx,left.controly,right.controlx,right.controly);
				
		right.startx=left.endx;
		right.starty=left.endy;
		
		right.endx=crv->endx;
		right.endy=crv->endy;
		
		makecurve(xpts,ypts,npts,cur,&left,level-1,lastx,lasty);
		makecurve(xpts,ypts,npts,cur,&right,level-1,lastx,lasty);
	}
	else{
		
		xpts[(*cur)]=crv->endx;
		ypts[(*cur)]=crv->endy;
		
		(*lastx)=crv->endx;
		(*lasty)=crv->endy;
		
		(*cur)++;
	}
}
Beispiel #2
0
// QBezierOutline makes a quadratic bezier curve, outlined 
void QbezierOutline(VGfloat sx, VGfloat sy, VGfloat cx, VGfloat cy, VGfloat ex, VGfloat ey) {
	VGubyte segments[] = { VG_MOVE_TO_ABS, VG_QUAD_TO };
	VGfloat coords[] = { sx, sy, cx, cy, ex, ey };
	makecurve(segments, coords, VG_STROKE_PATH);
}
Beispiel #3
0
// CBezier makes a quadratic bezier curve
void Cbezier(VGfloat sx, VGfloat sy, VGfloat cx, VGfloat cy, VGfloat px, VGfloat py, VGfloat ex, VGfloat ey) {
	VGubyte segments[] = { VG_MOVE_TO_ABS, VG_CUBIC_TO };
	VGfloat coords[] = { sx, sy, cx, cy, px, py, ex, ey };
	makecurve(segments, coords, VG_FILL_PATH | VG_STROKE_PATH);
}
// ---------------------------------------------------------------------------
// 
// -----------
bool bSmoothElement::smooth_one(float* xpts,
								float* ypts,
								float* newxpts,
								float* newypts,
								int npts,
								int* gcurs){
	if(npts<3){
		if(npts==2){
			newxpts[0]=xpts[0];
			newxpts[1]=xpts[1];
			newypts[0]=ypts[0];
			newypts[1]=ypts[1];
			gcurs+=2;
		}
		return(true);
	}
	
int		n=npts-1;	
bool	closed=((xpts[0]==xpts[npts-1])&&(ypts[0]==ypts[npts-1]));
int		curs,i,bkcurs,nnewpts=npts*16L+((int)closed);
float	x1,x2,x3,y1,y2,y3,lastx,lasty,firstx,firsty;
curve	crv;
	
	curs=0;
	for(i=1;i<=n-(int)(!closed);i++){
		x1=xpts[i-1];
		y1=ypts[i-1];
		x2=xpts[i];
		y2=ypts[i];
		if(i==n){
			x3=xpts[1];
			y3=ypts[1];
		}
		else{
			x3=xpts[i+1];
			y3=ypts[i+1];
		}
		
		if((!closed)&&(i==1)){
			newxpts[curs]=lastx=x1;
			newypts[curs]=lasty=y1;
			curs++;
			(*gcurs)++;
		}
		
		if((closed)||(i!=1)){
			mid(&x1,&y1,x1,y1,x2,y2);
		}
			
		if((closed)||(i!=n-1)){
			mid(&x3,&y3,x2,y2,x3,y3);
		}
		
		if((closed)&&(i==1)){			
			newxpts[curs]=firstx=lastx=x1;
			newypts[curs]=firsty=lasty=y1;
			curs++;
			(*gcurs)++;
		}
		
		if(((x1==x2)&&(y1==y2))||((x2==x3)&&(y2==y3))){
			continue;
		}
		
		crv.startx=x1;
		crv.starty=y1;
		
		crv.controlx=x2;
		crv.controly=y2;
		
		crv.endx=x3;
		crv.endy=y3;
		
		bkcurs=curs;
		makecurve(newxpts,newypts,nnewpts,&curs,&crv,4,&lastx,&lasty);
		(*gcurs)+=(curs-bkcurs);
	}
	
	if(closed){
		newxpts[curs]=newxpts[0];
		newypts[curs]=newypts[0];
		(*gcurs)++;
	}
		
	return(true);
}