* Inline most FTPoint methods and operators. This will probably make the code smaller instead of bigger, because most of what they do will be optimised out by the compiler. * Get rid of the weird GetNormal() method and reimplement it using the ^ operator (vector product) and Normalise() method instead.
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
diff --git a/src/FTGL/FTPoint.h b/src/FTGL/FTPoint.h
index 09a861c..a95e858 100644
--- a/src/FTGL/FTPoint.h
+++ b/src/FTGL/FTPoint.h
@@ -43,7 +43,7 @@ class FTGL_EXPORT FTPoint
/**
* Default constructor. Point is set to zero.
*/
- FTPoint()
+ inline FTPoint()
{
values[0] = 0;
values[1] = 0;
@@ -57,8 +57,8 @@ class FTGL_EXPORT FTPoint
* @param y Second component
* @param z Third component
*/
- FTPoint(const FTGL_DOUBLE x, const FTGL_DOUBLE y,
- const FTGL_DOUBLE z = 0)
+ inline FTPoint(const FTGL_DOUBLE x, const FTGL_DOUBLE y,
+ const FTGL_DOUBLE z = 0)
{
values[0] = x;
values[1] = y;
@@ -66,11 +66,11 @@ class FTGL_EXPORT FTPoint
}
/**
- * Constructor. This converts an FT_Vector to an FT_Point
+ * Constructor. This converts an FT_Vector to an FTPoint
*
* @param ft_vector A freetype vector
*/
- FTPoint(const FT_Vector& ft_vector)
+ inline FTPoint(const FT_Vector& ft_vector)
{
values[0] = ft_vector.x;
values[1] = ft_vector.y;
@@ -78,14 +78,12 @@ class FTGL_EXPORT FTPoint
}
/**
- * Calculate the normal vector to 2 points. This is 2D and ignores
- * the z component. The normal will be normalised
+ * Normalise a point's coordinates. If the coordinates are zero,
+ * the point is left untouched.
*
- * @param a
- * @param b
- * @return
+ * @return A vector of norm one.
*/
- static FTPoint GetNormal(const FTPoint &a, const FTPoint &b);
+ FTPoint Normalise();
/**
@@ -94,7 +92,7 @@ class FTGL_EXPORT FTPoint
* @param point
* @return this plus point.
*/
- FTPoint& operator += (const FTPoint& point)
+ inline FTPoint& operator += (const FTPoint& point)
{
values[0] += point.values[0];
values[1] += point.values[1];
@@ -109,7 +107,7 @@ class FTGL_EXPORT FTPoint
* @param point
* @return this plus point.
*/
- FTPoint operator + (const FTPoint& point)
+ inline FTPoint operator + (const FTPoint& point)
{
FTPoint temp;
temp.values[0] = values[0] + point.values[0];
@@ -125,7 +123,7 @@ class FTGL_EXPORT FTPoint
* @param point
* @return this minus point.
*/
- FTPoint& operator -= (const FTPoint& point)
+ inline FTPoint& operator -= (const FTPoint& point)
{
values[0] -= point.values[0];
values[1] -= point.values[1];
@@ -140,7 +138,7 @@ class FTGL_EXPORT FTPoint
* @param point
* @return this minus point.
*/
- FTPoint operator - (const FTPoint& point)
+ inline FTPoint operator - (const FTPoint& point)
{
FTPoint temp;
temp.values[0] = values[0] - point.values[0];
@@ -156,7 +154,7 @@ class FTGL_EXPORT FTPoint
* @param multiplier
* @return <code>this</code> multiplied by <code>multiplier</code>.
*/
- FTPoint operator * (double multiplier)
+ inline FTPoint operator * (double multiplier)
{
FTPoint temp;
temp.values[0] = values[0] * multiplier;
@@ -174,11 +172,33 @@ class FTGL_EXPORT FTPoint
* @param multiplier
* @return <code>multiplier</code> multiplied by <code>point</code>.
*/
- friend FTPoint operator * (double multiplier, FTPoint& point);
+ inline friend FTPoint operator * (double multiplier, FTPoint& point)
+ {
+ return point * multiplier;
+ }
+
+
+ /**
+ * Operator ^ Vector product
+ *
+ * @param point Second point
+ * @return this vector point.
+ */
+ inline FTPoint operator ^ (const FTPoint& point)
+ {
+ FTPoint temp;
+ temp.values[0] = values[1] * point.values[2]
+ - values[2] * point.values[1];
+ temp.values[1] = values[2] * point.values[3]
+ - values[3] * point.values[2];
+ temp.values[2] = values[3] * point.values[0]
+ - values[0] * point.values[3];
+ return temp;
+ }
/**
- * Operator == Tests for eqaulity
+ * Operator == Tests for equality
*
* @param a
* @param b
@@ -186,6 +206,7 @@ class FTGL_EXPORT FTPoint
*/
friend bool operator == (const FTPoint &a, const FTPoint &b);
+
/**
* Operator != Tests for non equality
*
@@ -199,7 +220,7 @@ class FTGL_EXPORT FTPoint
/**
* Cast to FTGL_DOUBLE*
*/
- operator const FTGL_DOUBLE*() const
+ inline operator const FTGL_DOUBLE*() const
{
return values;
}
@@ -208,17 +229,17 @@ class FTGL_EXPORT FTPoint
/**
* Setters
*/
- void X(FTGL_DOUBLE x) { values[0] = x; };
- void Y(FTGL_DOUBLE y) { values[1] = y; };
- void Z(FTGL_DOUBLE z) { values[2] = z; };
+ inline void X(FTGL_DOUBLE x) { values[0] = x; };
+ inline void Y(FTGL_DOUBLE y) { values[1] = y; };
+ inline void Z(FTGL_DOUBLE z) { values[2] = z; };
/**
* Getters
*/
- FTGL_DOUBLE X() const { return values[0]; };
- FTGL_DOUBLE Y() const { return values[1]; };
- FTGL_DOUBLE Z() const { return values[2]; };
+ inline FTGL_DOUBLE X() const { return values[0]; };
+ inline FTGL_DOUBLE Y() const { return values[1]; };
+ inline FTGL_DOUBLE Z() const { return values[2]; };
private:
/**
diff --git a/src/FTGlyph/FTExtrudeGlyph.cpp b/src/FTGlyph/FTExtrudeGlyph.cpp
index e8b9318..3929213 100644
--- a/src/FTGlyph/FTExtrudeGlyph.cpp
+++ b/src/FTGlyph/FTExtrudeGlyph.cpp
@@ -230,16 +230,16 @@ void FTExtrudeGlyphImpl::RenderSide()
unsigned int next = (cur == n - 1) ? 0 : cur + 1;
FTPoint frontPt = contour->FrontPoint(cur);
+ FTPoint nextPt = contour->FrontPoint(next);
FTPoint backPt = contour->BackPoint(cur);
- FTPoint normal = FTPoint::GetNormal(frontPt, contour->FrontPoint(next));
+ FTPoint normal = FTPoint(0.f, 0.f, 1.f) ^ (frontPt - nextPt);
if(normal != FTPoint(0.0f, 0.0f, 0.0f))
{
- glNormal3dv(static_cast<const FTGL_DOUBLE*>(normal));
+ glNormal3dv(static_cast<const FTGL_DOUBLE*>(normal.Normalise()));
}
- glTexCoord2f(frontPt.X() / hscale,
- frontPt.Y() / vscale);
+ glTexCoord2f(frontPt.X() / hscale, frontPt.Y() / vscale);
if(contourFlag & ft_outline_reverse_fill)
{
diff --git a/src/FTPoint.cpp b/src/FTPoint.cpp
index dbb9a2b..6fd38ee 100644
--- a/src/FTPoint.cpp
+++ b/src/FTPoint.cpp
@@ -34,35 +34,24 @@ 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]));
}
+
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, FTPoint& point)
-{
- return point * multiplier;
-}
-
-FTPoint FTPoint::GetNormal(const FTPoint &a, const FTPoint &b)
+FTPoint FTPoint::Normalise()
{
- float vectorX = a.X() - b.X();
- float vectorY = a.Y() - b.Y();
-
- float length = sqrt(vectorX * vectorX + vectorY * vectorY);
-
- if(length > 0.01f)
- {
- length = 1 / length;
- }
- else
+ float norm = sqrt(values[0] * values[0]
+ + values[1] * values[1]
+ + values[2] * values[2]);
+ if(norm == 0.f)
{
- length = 0.0f;
+ return *this;
}
- return FTPoint(-vectorY * length,
- vectorX * length,
- 0.0f);
+ FTPoint temp(values[0] / norm, values[1] / norm, values[2] / norm);
+ return temp;
}