Commit 1f69e6a0c211420b9bc99130ca788cc85bce78e1

henry 2004-10-11T02:58:52

Added operator + & * to FTPoint

diff --git a/include/FTPoint.h b/include/FTPoint.h
index a9b5f89..5a20bd4 100755
--- a/include/FTPoint.h
+++ b/include/FTPoint.h
@@ -65,6 +65,43 @@ class FTGL_EXPORT FTPoint
         }
 
         /**
+         * Operator +
+         *
+         * @param point
+         * @return this plus point.
+         */
+        FTPoint operator + ( const FTPoint& point)
+        {
+            FTPoint temp;
+            temp.values[0] = values[0] + point.values[0];
+            temp.values[1] = values[1] + point.values[1];
+            temp.values[2] = values[2] + point.values[2];
+
+            return temp;
+        }
+        
+        
+        /**
+         * Operator *
+         *
+         * @param point
+         * @return this plus point.
+         */
+        FTPoint operator * ( double multiplier)
+        {
+            FTPoint temp;
+            temp.values[0] = values[0] * multiplier;
+            temp.values[1] = values[1] * multiplier;
+            temp.values[2] = values[2] * multiplier;
+
+            return temp;
+        }
+        
+        
+        friend FTPoint operator*( double multiplier, const FTPoint& point);
+
+
+        /**
          * Operator == Tests for eqaulity
          *
          * @param a
diff --git a/src/FTContour.cpp b/src/FTContour.cpp
index 9a575ff..a9a9579 100644
--- a/src/FTContour.cpp
+++ b/src/FTContour.cpp
@@ -99,9 +99,7 @@ FTContour::FTContour( FT_Vector* contour, char* pointTags, unsigned int numberOf
             
             while( nextPointTag == FT_Curve_Tag_Conic)
             {
-                nextPoint = FTPoint( static_cast<float>( controlPoint.X() + nextPoint.X()) * 0.5f,
-                                     static_cast<float>( controlPoint.Y() + nextPoint.Y()) * 0.5f,
-                                     0);
+                nextPoint = ( controlPoint + nextPoint) * 0.5f;
 
                 controlPoints[0][0] = previousPoint.X(); controlPoints[0][1] = previousPoint.Y();
                 controlPoints[1][0] = controlPoint.X();  controlPoints[1][1] = controlPoint.Y();
diff --git a/src/FTPoint.cpp b/src/FTPoint.cpp
index dd012ec..04d8cdd 100755
--- a/src/FTPoint.cpp
+++ b/src/FTPoint.cpp
@@ -10,3 +10,10 @@ bool operator != ( const FTPoint &a, const FTPoint &b)
 {
     return((a.values[0] != b.values[0]) || (a.values[1] != b.values[1]) || (a.values[2] != b.values[2]));
 }
+
+
+FTPoint operator*( double multiplier, const FTPoint& point)
+{
+        return point * multiplier;
+}
+        
diff --git a/test/FTPoint-Test.cpp b/test/FTPoint-Test.cpp
index af3b3d0..ddd8951 100755
--- a/test/FTPoint-Test.cpp
+++ b/test/FTPoint-Test.cpp
@@ -11,6 +11,8 @@ class FTPointTest : public CppUnit::TestCase
     CPPUNIT_TEST_SUITE( FTPointTest);
         CPPUNIT_TEST( testConstructor);
         CPPUNIT_TEST( testOperatorEqual);
+        CPPUNIT_TEST( testOperatorPlus);
+        CPPUNIT_TEST( testOperatorMultiply);
         CPPUNIT_TEST( testOperatorNotEqual);
         CPPUNIT_TEST( testOperatorPlusEquals);
         CPPUNIT_TEST( testOperatorDouble);
@@ -74,6 +76,34 @@ class FTPointTest : public CppUnit::TestCase
         }
         
         
+        void testOperatorPlus()
+        {
+            FTPoint point1(  1.0f, 2.0f, 3.0f);
+            FTPoint point2(  1.0f, 2.0f, 3.0f);
+            
+            FTPoint point3(  2.0f, 4.0f, 6.0f);
+            FTPoint point4 = point1 + point2;
+            
+            CPPUNIT_ASSERT( point4 == point3);
+        }
+        
+        
+        void testOperatorMultiply()
+        {
+            FTPoint point1(  1.0f, 2.0f, 3.0f);
+            FTPoint point2(  1.0f, 2.0f, 3.0f);
+            
+            FTPoint point3(  2.0f, 4.0f, 6.0f);
+            FTPoint point4 = point1 * 2.0;
+
+            CPPUNIT_ASSERT( point4 == point3);
+
+            point4 = 2.0 * point2;
+            
+            CPPUNIT_ASSERT( point4 == point3);
+        }
+        
+        
         void testOperatorPlusEquals()
         {
             FTPoint point1(  1.0f, 2.0f, 3.0f);