SO3Engine
SO3Point.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
25#ifndef __SO3_POINT_H__
26#define __SO3_POINT_H__
27
29
30namespace SO3
31{
32
36template <typename NUMERIC_TYPE> class SPoint
37{
38public:
39 NUMERIC_TYPE x;
40 NUMERIC_TYPE y;
41
42 // special points
43 static const SPoint ZERO;
44 static const SPoint UNIT_X;
45 static const SPoint UNIT_Y;
46 static const SPoint NEGATIVE_UNIT_X;
47 static const SPoint NEGATIVE_UNIT_Y;
48 static const SPoint UNIT_SCALE;
49protected:
50private:
51
52public:
54 {
55 x = 0;
56 y = 0;
57 }
58
59 inline SPoint<NUMERIC_TYPE>(const NUMERIC_TYPE& fX, const NUMERIC_TYPE& fY) : x(fX), y(fY)
60 {
61 }
62
63 inline explicit SPoint<NUMERIC_TYPE>(const NUMERIC_TYPE& scaler) : x(scaler), y(scaler)
64 {
65 }
66
67 inline explicit SPoint<NUMERIC_TYPE>(const NUMERIC_TYPE afCoordinate[2]) : x(afCoordinate[0]), y(afCoordinate[1])
68 {
69 }
70
71 inline explicit SPoint<NUMERIC_TYPE>(NUMERIC_TYPE* const r) : x(r[0]), y(r[1])
72 {
73 }
74
75 inline float operator [] (const size_t& i) const
76 {
77 //assert(i < 2);
78 return *(&x+i);
79 }
80
81 inline float& operator [] (const size_t& i)
82 {
83 //assert(i < 2);
84 return *(&x+i);
85 }
86
90 inline NUMERIC_TYPE* ptr()
91 {
92 return &x;
93 }
94
98 inline const NUMERIC_TYPE* ptr() const
99 {
100 return &x;
101 }
102
108 {
109 x = copyPoint.x;
110 y = copyPoint.y;
111 return *this;
112 }
113
114 inline SPoint<NUMERIC_TYPE>& operator = (const float& fScalar)
115 {
116 x = fScalar;
117 y = fScalar;
118 return *this;
119 }
120
121 inline bool operator == (const SPoint<NUMERIC_TYPE>& copyPoint) const
122 {
123 return (x == copyPoint.x && y == copyPoint.y);
124 }
125
126 inline bool operator != (const SPoint<NUMERIC_TYPE>& copyPoint) const
127 {
128 return (x != copyPoint.x || y != copyPoint.y);
129 }
130
132 {
133 return SPoint<NUMERIC_TYPE>(x + copyPoint.x, y + copyPoint.y);
134 }
135
137 {
138 return SPoint<NUMERIC_TYPE>(x - copyPoint.x, y - copyPoint.y);
139 }
140
141 inline SPoint<NUMERIC_TYPE> operator * (const NUMERIC_TYPE& fScalar) const
142 {
143 return SPoint<NUMERIC_TYPE>(x * fScalar, y * fScalar);
144 }
145
147 {
148 return SPoint<NUMERIC_TYPE>(x * rhs.x, y * rhs.y);
149 }
150
151 inline SPoint<NUMERIC_TYPE> operator / (const float& fScalar) const
152 {
153 //assert(fScalar != 0.0);
154 float fInv = 1.0 / fScalar;
155 return SPoint<NUMERIC_TYPE>(x * fInv, y * fInv);
156 }
157
159 {
160 return SPoint<NUMERIC_TYPE>(x / rhs.x, y / rhs.y);
161 }
162
163 inline const SPoint<NUMERIC_TYPE>& operator + () const
164 {
165 return *this;
166 }
167
169 {
170 return SPoint<NUMERIC_TYPE>(-x, -y);
171 }
172
173 inline friend SPoint<NUMERIC_TYPE> operator * (const NUMERIC_TYPE& fScalar, const SPoint<NUMERIC_TYPE>& copyPoint)
174 {
175 return SPoint<NUMERIC_TYPE>(fScalar * copyPoint.x, fScalar * copyPoint.y);
176 }
177
178 inline friend SPoint<NUMERIC_TYPE> operator / (const NUMERIC_TYPE& fScalar, const SPoint<NUMERIC_TYPE>& copyPoint)
179 {
180 return SPoint<NUMERIC_TYPE>(fScalar / copyPoint.x, fScalar / copyPoint.y);
181 }
182
183 inline friend SPoint<NUMERIC_TYPE> operator + (const SPoint<NUMERIC_TYPE>& lhs, const NUMERIC_TYPE rhs)
184 {
185 return SPoint<NUMERIC_TYPE>(lhs.x + rhs, lhs.y + rhs);
186 }
187
188 inline friend SPoint<NUMERIC_TYPE> operator + (const NUMERIC_TYPE& lhs, const SPoint<NUMERIC_TYPE>& rhs)
189 {
190 return SPoint<NUMERIC_TYPE>(lhs + rhs.x, lhs + rhs.y);
191 }
192
193 inline friend SPoint<NUMERIC_TYPE> operator - (const SPoint<NUMERIC_TYPE>& lhs, const NUMERIC_TYPE& rhs)
194 {
195 return SPoint<NUMERIC_TYPE>(lhs.x - rhs, lhs.y - rhs);
196 }
197
198 inline friend SPoint<NUMERIC_TYPE> operator - (const NUMERIC_TYPE& lhs, const SPoint<NUMERIC_TYPE>& rhs)
199 {
200 return SPoint<NUMERIC_TYPE>(lhs - rhs.x, lhs - rhs.y);
201 }
202
204 {
205 x += copyPoint.x;
206 y += copyPoint.y;
207 return *this;
208 }
209
210 inline SPoint<NUMERIC_TYPE>& operator += (const NUMERIC_TYPE& fScaler)
211 {
212 x += fScaler;
213 y += fScaler;
214 return *this;
215 }
216
218 {
219 x -= copyPoint.x;
220 y -= copyPoint.y;
221 return *this;
222 }
223
224 inline SPoint<NUMERIC_TYPE>& operator -= (const NUMERIC_TYPE& fScaler)
225 {
226 x -= fScaler;
227 y -= fScaler;
228 return *this;
229 }
230
231 inline SPoint<NUMERIC_TYPE>& operator *= (const NUMERIC_TYPE& fScalar)
232 {
233 x *= fScalar;
234 y *= fScalar;
235 return *this;
236 }
237
239 {
240 x *= copyPoint.x;
241 y *= copyPoint.y;
242 return *this;
243 }
244
245 inline SPoint<NUMERIC_TYPE>& operator /= (const NUMERIC_TYPE& fScalar)
246 {
247 assert(fScalar != 0.0);
248 float fInv = 1.0 / fScalar;
249 x *= fInv;
250 y *= fInv;
251 return *this;
252 }
253
255 {
256 x /= copyPoint.x;
257 y /= copyPoint.y;
258 return *this;
259 }
260
264 inline bool operator < (const SPoint<NUMERIC_TYPE>& rhs) const
265 {
266 if( x < rhs.x && y < rhs.y )
267 return true;
268
269 return false;
270 }
271
275 inline bool operator > (const SPoint<NUMERIC_TYPE>& rhs) const
276 {
277 if( x > rhs.x && y > rhs.y )
278 return true;
279
280 return false;
281 }
282protected:
283private:
284};
285
294
295}
296
297#endif
librairies include
SPoint< NUMERIC_TYPE > & operator=(const SPoint< NUMERIC_TYPE > &copyPoint)
Definition SO3Point.h:107
static const SPoint ZERO
Definition SO3Point.h:43
NUMERIC_TYPE y
Definition SO3Point.h:40
float operator[](const size_t &i) const
Definition SO3Point.h:75
NUMERIC_TYPE x
Definition SO3Point.h:39
friend SPoint< NUMERIC_TYPE > operator*(const NUMERIC_TYPE &fScalar, const SPoint< NUMERIC_TYPE > &copyPoint)
Definition SO3Point.h:173
const NUMERIC_TYPE * ptr() const
Definition SO3Point.h:98
SPoint< NUMERIC_TYPE > operator-() const
Definition SO3Point.h:168
static const SPoint NEGATIVE_UNIT_X
Definition SO3Point.h:46
const SPoint< NUMERIC_TYPE > & operator+() const
Definition SO3Point.h:163
NUMERIC_TYPE * ptr()
Definition SO3Point.h:90
SPoint< NUMERIC_TYPE > & operator-=(const SPoint< NUMERIC_TYPE > &copyPoint)
Definition SO3Point.h:217
SPoint< NUMERIC_TYPE > & operator*=(const NUMERIC_TYPE &fScalar)
Definition SO3Point.h:231
static const SPoint UNIT_SCALE
Definition SO3Point.h:48
bool operator<(const SPoint< NUMERIC_TYPE > &rhs) const
Definition SO3Point.h:264
static const SPoint UNIT_X
Definition SO3Point.h:44
static const SPoint UNIT_Y
Definition SO3Point.h:45
SPoint< NUMERIC_TYPE > & operator/=(const NUMERIC_TYPE &fScalar)
Definition SO3Point.h:245
bool operator>(const SPoint< NUMERIC_TYPE > &rhs) const
Definition SO3Point.h:275
bool operator!=(const SPoint< NUMERIC_TYPE > &copyPoint) const
Definition SO3Point.h:126
friend SPoint< NUMERIC_TYPE > operator/(const NUMERIC_TYPE &fScalar, const SPoint< NUMERIC_TYPE > &copyPoint)
Definition SO3Point.h:178
bool operator==(const SPoint< NUMERIC_TYPE > &copyPoint) const
Definition SO3Point.h:121
static const SPoint NEGATIVE_UNIT_Y
Definition SO3Point.h:47
SPoint< NUMERIC_TYPE > & operator+=(const SPoint< NUMERIC_TYPE > &copyPoint)
Definition SO3Point.h:203
SPoint< double > SPointDouble
Definition SO3Point.h:293
SPoint< float > SPointFloat
Definition SO3Point.h:292
SPoint< long > SPointLong
Definition SO3Point.h:288
SPoint< unsigned int > SPointUInt
Definition SO3Point.h:289
SPoint< unsigned long > SPointULong
Definition SO3Point.h:291
SPoint< int > SPointInt
Definition SO3Point.h:286
SPoint< unsigned short > SPointUShort
Definition SO3Point.h:290
SPoint< short > SPointShort
Definition SO3Point.h:287