Commit a1ed83ae37fc1297006ccddc92162c079a460844

henry 2001-08-05T22:28:29

const rampage:) added next2 to curve code

diff --git a/include/FTVectoriser.h b/include/FTVectoriser.h
index e80ada5..bb1e7fa 100644
--- a/include/FTVectoriser.h
+++ b/include/FTVectoriser.h
@@ -48,15 +48,15 @@ class ftPoint
 		ftPoint()
 		: x(0), y(0), z(0){}
 		
-		ftPoint( float X, float Y, float Z)
+		ftPoint( const float X, const float Y, const float Z)
 		: x(X), y(Y), z(Z){}
 		
-		friend bool operator == (const ftPoint &a, const ftPoint &b)
+		friend bool operator == (const ftPoint &a, const ftPoint &b) 
 		{
 			return((a.x == b.x) && (a.y == b.y) && (a.z == b.z));
 		}
 
-		friend bool operator != (const ftPoint &a, const ftPoint &b)
+		friend bool operator != (const ftPoint &a, const ftPoint &b) 
 		{
 			return((a.x != b.x) || (a.y != b.y) || (a.z != b.z));
 		}
@@ -74,7 +74,7 @@ class FTContour
 		FTContour();
 		~FTContour();
 	
-		void AddPoint( int x, int y);
+		void AddPoint( const int x, const int y);
 		
 		int size() const { return pointList.size();}
 
@@ -107,23 +107,21 @@ class FTVectoriser
 		
 	private:
 		// methods
-		int Conic( int index, int first, int last);
-		int Cubic( int index, int first, int last);
-		void deCasteljau( GLfloat t, int n);
-		void evaluateCurve( int n);
+		int Conic( const int index, const int first, const int last);
+		int Cubic( const int index, const int first, const int last);
+		void deCasteljau( const float t, const int n);
+		void evaluateCurve( const int n);
 
 		// attributes
-		vector< FTContour*> contourList;
-		float ctrlPtArray[4][2]; // Magic numbers
+		vector< const FTContour*> contourList;
 			
 		FTContour* contour;
 
 		FT_Outline ftOutline;
 		
 		 // Magic numbers -- #define MAX_DEG 4
-		float bValues[4][4][2];	//3D array storing values
-                                        	//of de Casteljau algorithm.
-
+		float bValues[4][4][2];	//3D array storing values of de Casteljau algorithm.
+		float ctrlPtArray[4][2]; // Magic numbers
 
 };
 
diff --git a/src/FTVectoriser.cpp b/src/FTVectoriser.cpp
index 6f20f1a..3896eed 100644
--- a/src/FTVectoriser.cpp
+++ b/src/FTVectoriser.cpp
@@ -1,5 +1,3 @@
-#include	"gl.h"
-
 #include	"FTVectoriser.h"
 #include	"FTGL.h"
 
@@ -16,12 +14,12 @@ FTContour::~FTContour()
 }
 
 
-void FTContour::AddPoint( int x, int y)
+void FTContour::AddPoint( const int x, const int y)
 {
 	ftPoint point( static_cast<float>( x), static_cast<float>( y), 0.0); 
 	
 	// Eliminate duplicate points.
-	if( ( pointList[pointList.size() - 1] != point) || pointList[0] != point)
+	if( ( pointList[pointList.size() - 1] != point) && pointList[0] != point)
 	{
 		pointList.push_back( point);
 	}
@@ -29,13 +27,11 @@ void FTContour::AddPoint( int x, int y)
 
 
 // De Casteljau algorithm supplied by Jed Soane
-void FTVectoriser::deCasteljau( float t, int n)
+void FTVectoriser::deCasteljau( const float t, const int n)
 {
-    int i, k;
-
     //Calculating successive b(i)'s using de Casteljau algorithm.
-    for ( i = 1; i <= n; i++)
-        for (k = 0; k <= (n - i); k++)
+    for( int i = 1; i <= n; i++)
+        for( int k = 0; k <= (n - i); k++)
         {
 			bValues[i][k][0] = (1 - t) * bValues[i - 1][k][0] + t * bValues[i - 1][k + 1][0];
 			bValues[i][k][1] = (1 - t) * bValues[i - 1][k][1] + t * bValues[i - 1][k + 1][1];
@@ -46,20 +42,20 @@ void FTVectoriser::deCasteljau( float t, int n)
 }
 
 
-void FTVectoriser::evaluateCurve( int n)
+// De Casteljau algorithm supplied by Jed Soane
+void FTVectoriser::evaluateCurve( const int n)
 {
-    int m, i;            					//loop counters
-    float t;            					//parameter for curve point calc. [0.0, 1.0]
-    float stepSize = 0.2;
-
     // setting the b(0) equal to the control points
-    for (i = 0; i <= n; i++)
+    for( int i = 0; i <= n; i++)
 	{
 		bValues[0][i][0] = ctrlPtArray[i][0];
 		bValues[0][i][1] = ctrlPtArray[i][1];
     } //end for(i..)
 
-    for (m = 0; m <= (1 / stepSize); m++)
+    float t;            					//parameter for curve point calc. [0.0, 1.0]
+    const float stepSize = 0.2; // FIXME variable
+
+    for( int m = 0; m <= (1 / stepSize); m++)
     {
     	t = m * stepSize;
         deCasteljau( t, n);  //calls to evaluate point on curve att.
@@ -67,7 +63,9 @@ void FTVectoriser::evaluateCurve( int n)
 }
 
 
-FTVectoriser::FTVectoriser( FT_Glyph glyph)
+FTVectoriser::FTVectoriser( const FT_Glyph glyph)
+:	contourFlag(0),
+	contour(0)
 {
 	FT_OutlineGlyph outline = (FT_OutlineGlyph)glyph;
 	ftOutline = outline->outline;
@@ -101,19 +99,18 @@ int FTVectoriser::points()
 
 bool FTVectoriser::Ingest()
 {
-    if ( ( ftOutline.n_contours < 1) || ( ftOutline.n_points < 1))
+    if ( ( ftOutline.n_contours < 1) || ( ftOutline.n_points < 3)) //FIXME check this
 		return false;
 
 	short first = 0;
-	short cont = ftOutline.n_contours;
+	short last;
+	const short cont = ftOutline.n_contours;
 	
 	for( short c = 0; c < cont; ++c)
 	{
 		contour = new FTContour;
-		
 		contourFlag = ftOutline.flags;
-		
-		short last = ftOutline.contours[c];
+		last = ftOutline.contours[c];
 
 		for( short p = first; p <= last; ++p)
 		{
@@ -132,16 +129,14 @@ bool FTVectoriser::Ingest()
 		}
 		
 		contourList.push_back( contour);
-
 		first = last + 1;
 	}
 	
 	return true;
-
 }
 
 
-int FTVectoriser::Conic( int index, int first, int last)
+int FTVectoriser::Conic( const int index, const int first, const int last)
 {
 	int next = index + 1;
 	int prev = index - 1;
@@ -155,7 +150,7 @@ int FTVectoriser::Conic( int index, int first, int last)
 	if( ftOutline.tags[next] != FT_Curve_Tag_Conic)
 	{
 		ctrlPtArray[0][0] = ftOutline.points[prev].x;	ctrlPtArray[0][1] = ftOutline.points[prev].y;
-		ctrlPtArray[1][0] = ftOutline.points[index].x;		ctrlPtArray[1][1] = ftOutline.points[index].y;
+		ctrlPtArray[1][0] = ftOutline.points[index].x;	ctrlPtArray[1][1] = ftOutline.points[index].y;
 		ctrlPtArray[2][0] = ftOutline.points[next].x;	ctrlPtArray[2][1] = ftOutline.points[next].y;
 		
 		evaluateCurve( 2);
@@ -163,29 +158,25 @@ int FTVectoriser::Conic( int index, int first, int last)
 	}
 	else
 	{
+		int next2 = next + 1;
+		if( next == last)
+			next2 = first;
+		
 		//create a phantom point
 		float x = ( ftOutline.points[index].x + ftOutline.points[next].x) / 2;
 		float y = ( ftOutline.points[index].y + ftOutline.points[next].y) / 2;
 		
 		// process first curve
 		ctrlPtArray[0][0] = ftOutline.points[prev].x;	ctrlPtArray[0][1] = ftOutline.points[prev].y;
-		ctrlPtArray[1][0] = ftOutline.points[index].x;		ctrlPtArray[1][1] = ftOutline.points[index].y;
-		ctrlPtArray[2][0] = x;	ctrlPtArray[2][1] = y;
+		ctrlPtArray[1][0] = ftOutline.points[index].x;	ctrlPtArray[1][1] = ftOutline.points[index].y;
+		ctrlPtArray[2][0] = x;							ctrlPtArray[2][1] = y;
 		
 		evaluateCurve( 2);
 		
 		// process second curve
-		ctrlPtArray[0][0] = x;	ctrlPtArray[0][1] = y;
-		ctrlPtArray[1][0] = ftOutline.points[next].x;		ctrlPtArray[1][1] = ftOutline.points[next].y;
-		
-		if( index != last -1)
-		{
-			ctrlPtArray[2][0] = ftOutline.points[index+2].x;	ctrlPtArray[2][1] = ftOutline.points[index+2].y;
-		}
-		else
-		{
-			ctrlPtArray[2][0] = ftOutline.points[first].x;	ctrlPtArray[2][1] = ftOutline.points[first].y;
-		}
+		ctrlPtArray[0][0] = x;							ctrlPtArray[0][1] = y;
+		ctrlPtArray[1][0] = ftOutline.points[next].x;	ctrlPtArray[1][1] = ftOutline.points[next].y;
+		ctrlPtArray[2][0] = ftOutline.points[next2].x;	ctrlPtArray[2][1] = ftOutline.points[next2].y;
 		evaluateCurve( 2);
 		
 		return 2;
@@ -193,7 +184,7 @@ int FTVectoriser::Conic( int index, int first, int last)
 }
 
 
-int FTVectoriser::Cubic( int index, int first, int last)
+int FTVectoriser::Cubic( const int index, const int first, const int last)
 {
 	int next = index + 1;
 	int prev = index - 1;
@@ -201,20 +192,19 @@ int FTVectoriser::Cubic( int index, int first, int last)
 	if( index == last)
 		next = first; 
 	
+	int next2 = next + 1;
+	
+	if( next == last)
+		next2 = first;
+	
 	if( index == first)
 		prev = last; 
 
-	ctrlPtArray[0][0] = ftOutline.points[prev].x;	ctrlPtArray[0][1] = ftOutline.points[prev].y;
+	ctrlPtArray[0][0] = ftOutline.points[prev].x;		ctrlPtArray[0][1] = ftOutline.points[prev].y;
 	ctrlPtArray[1][0] = ftOutline.points[index].x;		ctrlPtArray[1][1] = ftOutline.points[index].y;
 	ctrlPtArray[2][0] = ftOutline.points[next].x;		ctrlPtArray[2][1] = ftOutline.points[next].y;
-	if( index != last -1)
-	{
-		ctrlPtArray[3][0] = ftOutline.points[index+2].x;	ctrlPtArray[3][1] = ftOutline.points[index+2].y;
-	}
-	else
-	{
-		ctrlPtArray[3][0] = ftOutline.points[first].x;	ctrlPtArray[3][1] = ftOutline.points[first].y;
-	}
+	ctrlPtArray[3][0] = ftOutline.points[next2].x;		ctrlPtArray[3][1] = ftOutline.points[next2].y;
+
 	evaluateCurve( 3);
 	return 2;
 }
@@ -226,13 +216,13 @@ void FTVectoriser::Output( double* data)
 	
 	for( int c= 0; c < contours(); ++c)
 	{
-		FTContour* contour = contourList[c];
+		const FTContour* contour = contourList[c];
 		
 		for( int p = 0; p < contour->size(); ++p)
 		{
 			data[i] = static_cast<double>(contour->pointList[p].x / 64.0f); // is 64 correct?
 			data[i + 1] = static_cast<double>(contour->pointList[p].y / 64.0f);
-			data[i + 2] = static_cast<double>(contour->pointList[p].z / 64.0f);
+			data[i + 2] = 0.0; // static_cast<double>(contour->pointList[p].z / 64.0f);
 			i += 3;
 		}
 	}