Refactoring FTPoint
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
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()
{}