Ejemplo n.º 1
0
static void quadBezRec(struct SVGParser* p,
					   float x1, float y1, float x2, float y2, float x3, float y3,
					   int level)
{
	float x12,y12,x23,y23,x123,y123,d;

	if (level > 12) return;

	x12 = (x1+x2)*0.5f;
	y12 = (y1+y2)*0.5f;
	x23 = (x2+x3)*0.5f;
	y23 = (y2+y3)*0.5f;
	x123 = (x12+x23)*0.5f;
	y123 = (y12+y23)*0.5f;

	d = distPtSeg(x123, y123, x1,y1, x3,y3);
	if (level > 0 && d < p->tol*p->tol)
	{
		svgPathPoint(p, x123, y123);
		return;
	}

	quadBezRec(p, x1,y1, x12,y12, x123,y123, level+1);
	quadBezRec(p, x123,y123, x23,y23, x3,y3, level+1);
}
Ejemplo n.º 2
0
static void cubicBezRec(struct SVGParser* p,
						float x1, float y1, float x2, float y2,
						float x3, float y3, float x4, float y4,
						int level)
{
	float x12,y12,x23,y23,x34,y34,x123,y123,x234,y234,x1234,y1234;
	float d;

	if (level > 12) return;

	x12 = (x1+x2)*0.5f;
	y12 = (y1+y2)*0.5f;
	x23 = (x2+x3)*0.5f;
	y23 = (y2+y3)*0.5f;
	x34 = (x3+x4)*0.5f;
	y34 = (y3+y4)*0.5f;
	x123 = (x12+x23)*0.5f;
	y123 = (y12+y23)*0.5f;
	x234 = (x23+x34)*0.5f;
	y234 = (y23+y34)*0.5f;
	x1234 = (x123+x234)*0.5f;
	y1234 = (y123+y234)*0.5f;

	d = distPtSeg(x1234, y1234, x1,y1, x4,y4);
	if (level > 0 && d < p->tol*p->tol)
	{
		svgPathPoint(p, x1234, y1234);
		return;
	}

	cubicBezRec(p, x1,y1, x12,y12, x123,y123, x1234,y1234, level+1);
	cubicBezRec(p, x1234,y1234, x234,y234, x34,y34, x4,y4, level+1);
}
Ejemplo n.º 3
0
void ofxSVGPathParser::cubicBezRec(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, int level)
{
	float x12,y12,x23,y23,x34,y34,x123,y123,x234,y234,x1234,y1234;
	float d;
	
	if (level > 12) return;
	
	x12 = (x1+x2)*0.5f;
	y12 = (y1+y2)*0.5f;
	x23 = (x2+x3)*0.5f;
	y23 = (y2+y3)*0.5f;
	x34 = (x3+x4)*0.5f;
	y34 = (y3+y4)*0.5f;
	x123 = (x12+x23)*0.5f;
	y123 = (y12+y23)*0.5f;
	x234 = (x23+x34)*0.5f;
	y234 = (y23+y34)*0.5f;
	x1234 = (x123+x234)*0.5f;
	y1234 = (y123+y234)*0.5f;
	
	d = distPtSeg(x1234, y1234, x1,y1, x4,y4);
	if (level > 0 && d < 1000)//tol*tol)
	{
		pathInstance->quadBezierTo( ofPoint(x4, y4), ofPoint(x2, y2), ofPoint(x3, y3) );//svgPathPoint(x1234, y1234);
		return;
	}
	
	cubicBezRec(x1,y1, x12,y12, x123,y123, x1234,y1234, level+1); 
	cubicBezRec(x1234,y1234, x234,y234, x34,y34, x4,y4, level+1); 
}
Ejemplo n.º 4
0
static void cubicBez(float x1, float y1, float x2, float y2,
					 float x3, float y3, float x4, float y4,
					 float tol, int level)
{
	float x12,y12,x23,y23,x34,y34,x123,y123,x234,y234,x1234,y1234;
	float d;
	
	if (level > 12) return;

	x12 = (x1+x2)*0.5f;
	y12 = (y1+y2)*0.5f;
	x23 = (x2+x3)*0.5f;
	y23 = (y2+y3)*0.5f;
	x34 = (x3+x4)*0.5f;
	y34 = (y3+y4)*0.5f;
	x123 = (x12+x23)*0.5f;
	y123 = (y12+y23)*0.5f;
	x234 = (x23+x34)*0.5f;
	y234 = (y23+y34)*0.5f;
	x1234 = (x123+x234)*0.5f;
	y1234 = (y123+y234)*0.5f;

	d = distPtSeg(x1234, y1234, x1,y1, x4,y4);
	if (d > tol*tol) {
		cubicBez(x1,y1, x12,y12, x123,y123, x1234,y1234, tol, level+1); 
		cubicBez(x1234,y1234, x234,y234, x34,y34, x4,y4, tol, level+1); 
	} else {
		glVertex2f(x4, y4);
	}
}
Ejemplo n.º 5
0
void ofxSVGPathParser::quadBezRec( float x1, float y1, float x2, float y2, float x3, float y3, int level)
{
	float x12,y12,x23,y23,x123,y123,d;
	
	if (level > 12) return; // don't go too deep
	
	x12 = (x1+x2)*0.5f;                
	y12 = (y1+y2)*0.5f;
	x23 = (x2+x3)*0.5f;
	y23 = (y2+y3)*0.5f;
	x123 = (x12+x23)*0.5f;
	y123 = (y12+y23)*0.5f;
	
	d = distPtSeg(x123, y123, x1,y1, x3,y3);
	if (level > 0 && d < 1000) // tol*tol)
	{
		pathInstance->quadBezierTo(ofPoint(x1, x2), ofPoint(y2, y3), ofPoint( x123, y123 ));
		return;
	}
	
	quadBezRec(x1,y1, x12,y12, x123,y123, level+1); 
	quadBezRec(x123,y123, x23,y23, x3,y3, level+1); 
}