示例#1
0
文件: gblend.cpp 项目: vata/xarino
INT32 GBlend::BezierLength( POINT P0, POINT P1, POINT P2, POINT P3 )
{
	UINT32 dx,dy ;
	dx = abs(P1.x*3 - P0.x*2 - P3.x) ;
	dy = abs(P1.y*3 - P0.y*2 - P3.y) ;
	if ( (dx>=dy ? 3*dx+dy : dx+3*dy) > Flatness )
    	return FlattenSplit(P0,P1,P2,P3) ;
	dx = abs(P2.x*3 - P0.x - P3.x*2) ;
	dy = abs(P2.y*3 - P0.y - P3.y*2) ;
	if ( (dx>=dy ? 3*dx+dy : dx+3*dy) > Flatness )
    	return FlattenSplit(P0,P1,P2,P3) ;
	return length(P0,P3) ;
}
示例#2
0
void FlattenCurve( POINT P0, POINT P1, POINT P2, POINT P3 )
{
	UINT32 dx,dy ;
	dx = abs(P1.x*3 - P0.x*2 - P3.x) ;
	dy = abs(P1.y*3 - P0.y*2 - P3.y) ;
	if ( (dx>=dy ? 3*dx+dy : dx+3*dy) > Flatness )
    	FlattenSplit(P0,P1,P2,P3) ;
	else
	{
		dx = abs(P2.x*3 - P0.x - P3.x*2) ;
		dy = abs(P2.y*3 - P0.y - P3.y*2) ;
		if ( (dx>=dy ? 3*dx+dy : dx+3*dy) > Flatness )
    		FlattenSplit(P0,P1,P2,P3) ;
		else
			DoLine(P3) ;
	}
}
示例#3
0
BOOL ProcessPath::FlattenCurve(	INT32 Px0,INT32 Py0,
								INT32 Px1,INT32 Py1,
								INT32 Px2,INT32 Py2,
								INT32 Px3,INT32 Py3, BOOL QuantiseAll)
{
	INT32 diff;

	INT32 dx0 = (Px1*3 - Px0*2 - Px3);
	if (dx0 < 0) dx0 = -dx0;
	//dx0 = dx0 < 0 ? -dx0 : dx0;

	INT32 dy0 = (Py1*3 - Py0*2 - Py3);
	if (dy0 < 0) dy0 = -dy0;
	//dy0 = dy0 < 0 ? -dy0 : dy0;
	
	// Get the line's distance from the curve
	if (dx0 >= dy0)
		diff = 3*dx0 + dy0;
	else
		diff = dx0 + 3*dy0;
		
	// Is the straight line close enough to the curve ?
	if (diff > ProcFlatness)
	{
		// Not close enough so split it into two and recurse for each half
		BOOL ok = FlattenSplit(Px0,Py0, Px1,Py1, Px2,Py2, Px3,Py3, QuantiseAll);
    	return ok;
    }
    
	INT32 dx1 = (Px2*3 - Px0 - Px3*2);
	if (dx1 < 0) dx1 = -dx1;
	//dx1 = dx1 < 0 ? -dx1 : dx1;

	INT32 dy1 = (Py2*3 - Py0 - Py3*2);
	if (dy1 < 0) dy1 = -dy1;
	//1 = dy1 < 0 ? -dy1 : dy1;
	
	// Get the line's distance from the curve
	if (dx1 >= dy1)
		diff = 3*dx1 + dy1;
	else
		diff = dx1 + 3*dy1;

	// Is the straight line close enough to the curve ?
	if (diff > ProcFlatness)
	{
		// Not close enough so split it into two and recurse for each half
		BOOL ok = FlattenSplit(Px0,Py0, Px1,Py1, Px2,Py2, Px3,Py3, QuantiseAll);
    	return ok;
    }

	DocCoord npoint;
	npoint.x = Px3;
	npoint.y = Py3;

	// Line is now close enough so call the virtual function
    if (!QuantiseAll)
    	return NewPoint(PT_LINETO, &npoint);
    else
	{
		DocCoord spoint;
		spoint.x = Px0;
		spoint.y = Py0;
    	return InsertQuantisedLineTo(&npoint,&spoint);
	}
}