Commit b2bd1ab852af04e1379dc439bcd1aaafa3a96d37

henry 2004-10-10T11:14:58

Refactoring FTPoint

diff --git a/include/FTPoint.h b/include/FTPoint.h
index d2d677c..6b93ad9 100755
--- a/include/FTPoint.h
+++ b/include/FTPoint.h
@@ -18,7 +18,11 @@ class FTGL_EXPORT FTPoint
          */
         FTPoint()
         : x(0), y(0), z(0)
-        {}
+        {
+            elements[0] = 0;
+            elements[1] = 0;
+            elements[2] = 0;
+        }
         
         /**
          * Constructor.
@@ -29,7 +33,11 @@ class FTGL_EXPORT FTPoint
          */
         FTPoint( const FTGL_DOUBLE X, const FTGL_DOUBLE Y, const FTGL_DOUBLE Z)
         : x(X), y(Y), z(Z)
-        {}
+        {
+            elements[0] = X;
+            elements[1] = Y;
+            elements[2] = Z;
+        }
         
         /**
          * Constructor. This converts an FT_Vector to an FT_Point
@@ -38,7 +46,11 @@ class FTGL_EXPORT FTPoint
          */
         FTPoint( const FT_Vector& ft_vector)
         : x(ft_vector.x), y(ft_vector.y), z(0)
-        {}
+        {
+            elements[0] = ft_vector.x;
+            elements[1] = ft_vector.y;
+            elements[2] = 0;
+        }
         
         /**
          * Operator +=
@@ -52,6 +64,10 @@ class FTGL_EXPORT FTPoint
             y += point.y;
             z += point.z;
         
+            elements[0] = point.elements[0];
+            elements[1] = point.elements[1];
+            elements[2] = point.elements[2];
+
             return *this;
         }
 
@@ -78,6 +94,13 @@ class FTGL_EXPORT FTPoint
             return &x;
         }
         
+        void X( FTGL_DOUBLE x) { elements[0] = x;};
+        void Y( FTGL_DOUBLE y) { elements[1] = y;};
+        void Z( FTGL_DOUBLE x) { elements[2] = z;};
+        FTGL_DOUBLE X() const { return elements[0];};
+        FTGL_DOUBLE Y() const { return elements[1];};
+        FTGL_DOUBLE Z() const { return elements[2];};
+        
         /**
          * The point data
          */
@@ -85,6 +108,7 @@ class FTGL_EXPORT FTPoint
 //        FTGL_FLOAT x, y, z; // FIXME make private
         
     private:
+        FTGL_DOUBLE elements[3];
 };
 
 #endif  //  __FTPoint__
diff --git a/src/FTPoint.cpp b/src/FTPoint.cpp
index 365f4df..633c780 100755
--- a/src/FTPoint.cpp
+++ b/src/FTPoint.cpp
@@ -3,10 +3,12 @@
 
 bool operator == ( const FTPoint &a, const FTPoint &b) 
 {
-    return((a.x == b.x) && (a.y == b.y) && (a.z == b.z));
+    return((a.elements[0] == b.elements[0]) && (a.elements[1] == b.elements[1]) && (a.elements[2] == b.elements[2]));
+//    return((a.x == b.x) && (a.y == b.y) && (a.z == b.z));
 }
 
 bool operator != ( const FTPoint &a, const FTPoint &b) 
 {
-    return((a.x != b.x) || (a.y != b.y) || (a.z != b.z));
+    return((a.elements[0] != b.elements[0]) || (a.elements[1] != b.elements[1]) || (a.elements[2] != b.elements[2]));
+//    return((a.x != b.x) || (a.y != b.y) || (a.z != b.z));
 }
diff --git a/test/FTPoint-Test.cpp b/test/FTPoint-Test.cpp
index aac49bd..f7a0234 100755
--- a/test/FTPoint-Test.cpp
+++ b/test/FTPoint-Test.cpp
@@ -13,7 +13,9 @@ class FTPointTest : public CppUnit::TestCase
         CPPUNIT_TEST( testOperatorEqual);
         CPPUNIT_TEST( testOperatorNotEqual);
         CPPUNIT_TEST( testOperatorPlusEquals);
-        CPPUNIT_TEST( testOperatorStar);
+        CPPUNIT_TEST( testOperatorDouble);
+        CPPUNIT_TEST( testSetters);
+        CPPUNIT_TEST( testGetters);        
     CPPUNIT_TEST_SUITE_END();
         
     public:
@@ -94,6 +96,27 @@ class FTPointTest : public CppUnit::TestCase
             CPPUNIT_ASSERT(pointer[2] == 3.0f);
         }
         
+        void testSetters()
+        {
+            FTPoint point;
+            FTPoint point1( 1.0, 2.0, 3.0);
+            
+            point.X(1.0);
+            point.Y(2.0);
+            point.Z(3.0);
+            
+            CPPUNIT_ASSERT(point == point1);
+        }
+        
+        void testGetters()
+        {
+            FTPoint point( 1.0f, 2.0f, 3.0f);
+            
+            CPPUNIT_ASSERT(point.X() == 1.0);
+            CPPUNIT_ASSERT(point.Y() == 2.0);
+            CPPUNIT_ASSERT(point.Z() == 3.0);
+        }
+        
         
         void setUp() 
         {}