Added operator + & * to 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
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);