1 /*
2  * FTGL - OpenGL font library
3  *
4  * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
5  * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
6  * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27 
28 #ifndef __ftgl__
29 #   warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
30 #   include <FTGL/ftgl.h>
31 #endif
32 
33 #ifndef __FTPoint__
34 #define __FTPoint__
35 
36 #ifdef __cplusplus
37 
38 
39 /**
40  * FTPoint class is a basic 3-dimensional point or vector.
41  */
42 class FTGL_EXPORT FTPoint
43 {
44     public:
45         /**
46          * Default constructor. Point is set to zero.
47          */
FTPoint()48         inline FTPoint()
49         {
50             values[0] = 0;
51             values[1] = 0;
52             values[2] = 0;
53         }
54 
55         /**
56          * Constructor. Z coordinate is set to zero if unspecified.
57          *
58          * @param x First component
59          * @param y Second component
60          * @param z Third component
61          */
62         inline FTPoint(const FTGL_DOUBLE x, const FTGL_DOUBLE y,
63                        const FTGL_DOUBLE z = 0)
64         {
65             values[0] = x;
66             values[1] = y;
67             values[2] = z;
68         }
69 
70         /**
71          * Constructor. This converts an FT_Vector to an FTPoint
72          *
73          * @param ft_vector A freetype vector
74          */
FTPoint(const FT_Vector & ft_vector)75         inline FTPoint(const FT_Vector& ft_vector)
76         {
77             values[0] = ft_vector.x;
78             values[1] = ft_vector.y;
79             values[2] = 0;
80         }
81 
82         /**
83          * Normalise a point's coordinates. If the coordinates are zero,
84          * the point is left untouched.
85          *
86          * @return A vector of norm one.
87          */
88         FTPoint Normalise();
89 
90 
91         /**
92          * Operator += In Place Addition.
93          *
94          * @param point
95          * @return this plus point.
96          */
97         inline FTPoint& operator += (const FTPoint& point)
98         {
99             values[0] += point.values[0];
100             values[1] += point.values[1];
101             values[2] += point.values[2];
102 
103             return *this;
104         }
105 
106         /**
107          * Operator +
108          *
109          * @param point
110          * @return this plus point.
111          */
112         inline FTPoint operator + (const FTPoint& point) const
113         {
114             FTPoint temp;
115             temp.values[0] = values[0] + point.values[0];
116             temp.values[1] = values[1] + point.values[1];
117             temp.values[2] = values[2] + point.values[2];
118 
119             return temp;
120         }
121 
122          /**
123          * Operator -= In Place Substraction.
124          *
125          * @param point
126          * @return this minus point.
127          */
128         inline FTPoint& operator -= (const FTPoint& point)
129         {
130             values[0] -= point.values[0];
131             values[1] -= point.values[1];
132             values[2] -= point.values[2];
133 
134             return *this;
135         }
136 
137         /**
138          * Operator -
139          *
140          * @param point
141          * @return this minus point.
142          */
143         inline FTPoint operator - (const FTPoint& point) const
144         {
145             FTPoint temp;
146             temp.values[0] = values[0] - point.values[0];
147             temp.values[1] = values[1] - point.values[1];
148             temp.values[2] = values[2] - point.values[2];
149 
150             return temp;
151         }
152 
153         /**
154          * Operator *  Scalar multiplication
155          *
156          * @param multiplier
157          * @return <code>this</code> multiplied by <code>multiplier</code>.
158          */
159         inline FTPoint operator * (double multiplier) const
160         {
161             FTPoint temp;
162             temp.values[0] = values[0] * multiplier;
163             temp.values[1] = values[1] * multiplier;
164             temp.values[2] = values[2] * multiplier;
165 
166             return temp;
167         }
168 
169 
170         /**
171          * Operator *  Scalar multiplication
172          *
173          * @param point
174          * @param multiplier
175          * @return <code>multiplier</code> multiplied by <code>point</code>.
176          */
177         inline friend FTPoint operator * (double multiplier, FTPoint& point)
178         {
179             return point * multiplier;
180         }
181 
182 
183         /**
184          * Operator *  Scalar product
185          *
186          * @param a  First vector.
187          * @param b  Second vector.
188          * @return  <code>a.b</code> scalar product.
189          */
190         inline friend double operator * (FTPoint &a, FTPoint& b)
191         {
192             return a.values[0] * b.values[0]
193                  + a.values[1] * b.values[1]
194                  + a.values[2] * b.values[2];
195         }
196 
197 
198         /**
199          * Operator ^  Vector product
200          *
201          * @param point Second point
202          * @return this vector point.
203          */
204         inline FTPoint operator ^ (const FTPoint& point)
205         {
206             FTPoint temp;
207             temp.values[0] = values[1] * point.values[2]
208                               - values[2] * point.values[1];
209             temp.values[1] = values[2] * point.values[0]
210                               - values[0] * point.values[2];
211             temp.values[2] = values[0] * point.values[1]
212                               - values[1] * point.values[0];
213             return temp;
214         }
215 
216 
217         /**
218          * Operator == Tests for equality
219          *
220          * @param a
221          * @param b
222          * @return true if a & b are equal
223          */
224         friend bool operator == (const FTPoint &a, const FTPoint &b);
225 
226 
227         /**
228          * Operator != Tests for non equality
229          *
230          * @param a
231          * @param b
232          * @return true if a & b are not equal
233          */
234         friend bool operator != (const FTPoint &a, const FTPoint &b);
235 
236 
237         /**
238          * Cast to FTGL_DOUBLE*
239          */
240         inline operator const FTGL_DOUBLE*() const
241         {
242             return values;
243         }
244 
245 
246         /**
247          * Setters
248          */
X(FTGL_DOUBLE x)249         inline void X(FTGL_DOUBLE x) { values[0] = x; };
Y(FTGL_DOUBLE y)250         inline void Y(FTGL_DOUBLE y) { values[1] = y; };
Z(FTGL_DOUBLE z)251         inline void Z(FTGL_DOUBLE z) { values[2] = z; };
252 
253 
254         /**
255          * Getters
256          */
X()257         inline FTGL_DOUBLE X() const { return values[0]; };
Y()258         inline FTGL_DOUBLE Y() const { return values[1]; };
Z()259         inline FTGL_DOUBLE Z() const { return values[2]; };
Xf()260         inline FTGL_FLOAT Xf() const { return static_cast<FTGL_FLOAT>(values[0]); };
Yf()261         inline FTGL_FLOAT Yf() const { return static_cast<FTGL_FLOAT>(values[1]); };
Zf()262         inline FTGL_FLOAT Zf() const { return static_cast<FTGL_FLOAT>(values[2]); };
263 
264     private:
265         /**
266          * The point data
267          */
268         FTGL_DOUBLE values[3];
269 };
270 
271 #endif //__cplusplus
272 
273 #endif  //  __FTPoint__
274 
275