00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef __SO3_POINT_H__
00029 #define __SO3_POINT_H__
00030
00031 #include "../SCOLBasic/SO3Prerequisites.h"
00032
00033 namespace SO3
00034 {
00035
00039 template <typename NUMERIC_TYPE> class _SO3_Export SPoint
00040 {
00041 public:
00042 NUMERIC_TYPE x;
00043 NUMERIC_TYPE y;
00044
00045
00046 static const SPoint ZERO;
00047 static const SPoint UNIT_X;
00048 static const SPoint UNIT_Y;
00049 static const SPoint NEGATIVE_UNIT_X;
00050 static const SPoint NEGATIVE_UNIT_Y;
00051 static const SPoint UNIT_SCALE;
00052 protected:
00053 private:
00054
00055 public:
00056 inline SPoint<NUMERIC_TYPE>()
00057 {
00058 x = 0;
00059 y = 0;
00060 }
00061
00062 inline SPoint<NUMERIC_TYPE>(const NUMERIC_TYPE fX, const NUMERIC_TYPE fY) : x(fX), y(fY)
00063 {
00064 }
00065
00066 inline explicit SPoint<NUMERIC_TYPE>(const NUMERIC_TYPE scaler) : x(scaler), y(scaler)
00067 {
00068 }
00069
00070 inline explicit SPoint<NUMERIC_TYPE>(const NUMERIC_TYPE afCoordinate[2]) : x(afCoordinate[0]), y(afCoordinate[1])
00071 {
00072 }
00073
00074 inline explicit SPoint<NUMERIC_TYPE>(NUMERIC_TYPE* const r) : x(r[0]), y(r[1])
00075 {
00076 }
00077
00078 inline float operator [] (const size_t i) const
00079 {
00080 assert(i < 2);
00081 return *(&x+i);
00082 }
00083
00084 inline float& operator [] (const size_t i)
00085 {
00086 assert(i < 2);
00087 return *(&x+i);
00088 }
00089
00093 inline NUMERIC_TYPE* ptr()
00094 {
00095 return &x;
00096 }
00097
00101 inline const NUMERIC_TYPE* ptr() const
00102 {
00103 return &x;
00104 }
00105
00110 inline SPoint<NUMERIC_TYPE>& operator = (const SPoint<NUMERIC_TYPE>& copyPoint)
00111 {
00112 x = copyPoint.x;
00113 y = copyPoint.y;
00114 return *this;
00115 }
00116
00117 inline SPoint<NUMERIC_TYPE>& operator = (const float fScalar)
00118 {
00119 x = fScalar;
00120 y = fScalar;
00121 return *this;
00122 }
00123
00124 inline bool operator == (const SPoint<NUMERIC_TYPE>& copyPoint) const
00125 {
00126 return (x == copyPoint.x && y == copyPoint.y);
00127 }
00128
00129 inline bool operator != (const SPoint<NUMERIC_TYPE>& copyPoint) const
00130 {
00131 return (x != copyPoint.x || y != copyPoint.y);
00132 }
00133
00134 inline SPoint<NUMERIC_TYPE> operator + (const SPoint<NUMERIC_TYPE>& copyPoint) const
00135 {
00136 return SPoint<NUMERIC_TYPE>(x + copyPoint.x, y + copyPoint.y);
00137 }
00138
00139 inline SPoint<NUMERIC_TYPE> operator - (const SPoint<NUMERIC_TYPE>& copyPoint) const
00140 {
00141 return SPoint<NUMERIC_TYPE>(x - copyPoint.x, y - copyPoint.y);
00142 }
00143
00144 inline SPoint<NUMERIC_TYPE> operator * (const NUMERIC_TYPE fScalar) const
00145 {
00146 return SPoint<NUMERIC_TYPE>(x * fScalar, y * fScalar);
00147 }
00148
00149 inline SPoint<NUMERIC_TYPE> operator * (const SPoint<NUMERIC_TYPE>& rhs) const
00150 {
00151 return SPoint<NUMERIC_TYPE>(x * rhs.x, y * rhs.y);
00152 }
00153
00154 inline SPoint<NUMERIC_TYPE> operator / (const float fScalar) const
00155 {
00156 assert(fScalar != 0.0);
00157 float fInv = 1.0 / fScalar;
00158 return SPoint<NUMERIC_TYPE>(x * fInv, y * fInv);
00159 }
00160
00161 inline SPoint<NUMERIC_TYPE> operator / (const SPoint<NUMERIC_TYPE>& rhs) const
00162 {
00163 return SPoint<NUMERIC_TYPE>(x / rhs.x, y / rhs.y);
00164 }
00165
00166 inline const SPoint<NUMERIC_TYPE>& operator + () const
00167 {
00168 return *this;
00169 }
00170
00171 inline SPoint<NUMERIC_TYPE> operator - () const
00172 {
00173 return SPoint<NUMERIC_TYPE>(-x, -y);
00174 }
00175
00176 inline friend SPoint<NUMERIC_TYPE> operator * (const NUMERIC_TYPE fScalar, const SPoint<NUMERIC_TYPE>& copyPoint)
00177 {
00178 return SPoint<NUMERIC_TYPE>(fScalar * copyPoint.x, fScalar * copyPoint.y);
00179 }
00180
00181 inline friend SPoint<NUMERIC_TYPE> operator / (const NUMERIC_TYPE fScalar, const SPoint<NUMERIC_TYPE>& copyPoint)
00182 {
00183 return SPoint<NUMERIC_TYPE>(fScalar / copyPoint.x, fScalar / copyPoint.y);
00184 }
00185
00186 inline friend SPoint<NUMERIC_TYPE> operator + (const SPoint<NUMERIC_TYPE>& lhs, const NUMERIC_TYPE rhs)
00187 {
00188 return SPoint<NUMERIC_TYPE>(lhs.x + rhs, lhs.y + rhs);
00189 }
00190
00191 inline friend SPoint<NUMERIC_TYPE> operator + (const NUMERIC_TYPE lhs, const SPoint<NUMERIC_TYPE>& rhs)
00192 {
00193 return SPoint<NUMERIC_TYPE>(lhs + rhs.x, lhs + rhs.y);
00194 }
00195
00196 inline friend SPoint<NUMERIC_TYPE> operator - (const SPoint<NUMERIC_TYPE>& lhs, const NUMERIC_TYPE rhs)
00197 {
00198 return SPoint<NUMERIC_TYPE>(lhs.x - rhs, lhs.y - rhs);
00199 }
00200
00201 inline friend SPoint<NUMERIC_TYPE> operator - (const NUMERIC_TYPE lhs, const SPoint<NUMERIC_TYPE>& rhs)
00202 {
00203 return SPoint<NUMERIC_TYPE>(lhs - rhs.x, lhs - rhs.y);
00204 }
00205
00206 inline SPoint<NUMERIC_TYPE>& operator += (const SPoint<NUMERIC_TYPE>& copyPoint)
00207 {
00208 x += copyPoint.x;
00209 y += copyPoint.y;
00210 return *this;
00211 }
00212
00213 inline SPoint<NUMERIC_TYPE>& operator += (const NUMERIC_TYPE fScaler)
00214 {
00215 x += fScaler;
00216 y += fScaler;
00217 return *this;
00218 }
00219
00220 inline SPoint<NUMERIC_TYPE>& operator -= (const SPoint<NUMERIC_TYPE>& copyPoint)
00221 {
00222 x -= copyPoint.x;
00223 y -= copyPoint.y;
00224 return *this;
00225 }
00226
00227 inline SPoint<NUMERIC_TYPE>& operator -= (const NUMERIC_TYPE fScaler)
00228 {
00229 x -= fScaler;
00230 y -= fScaler;
00231 return *this;
00232 }
00233
00234 inline SPoint<NUMERIC_TYPE>& operator *= (const NUMERIC_TYPE fScalar)
00235 {
00236 x *= fScalar;
00237 y *= fScalar;
00238 return *this;
00239 }
00240
00241 inline SPoint<NUMERIC_TYPE>& operator *= (const SPoint<NUMERIC_TYPE>& copyPoint)
00242 {
00243 x *= copyPoint.x;
00244 y *= copyPoint.y;
00245 return *this;
00246 }
00247
00248 inline SPoint<NUMERIC_TYPE>& operator /= (const NUMERIC_TYPE fScalar)
00249 {
00250 assert(fScalar != 0.0);
00251 float fInv = 1.0 / fScalar;
00252 x *= fInv;
00253 y *= fInv;
00254 return *this;
00255 }
00256
00257 inline SPoint<NUMERIC_TYPE>& operator /= (const SPoint<NUMERIC_TYPE>& copyPoint)
00258 {
00259 x /= copyPoint.x;
00260 y /= copyPoint.y;
00261 return *this;
00262 }
00263
00267 inline bool operator < (const SPoint<NUMERIC_TYPE>& rhs) const
00268 {
00269 if( x < rhs.x && y < rhs.y )
00270 return true;
00271
00272 return false;
00273 }
00274
00278 inline bool operator > (const SPoint<NUMERIC_TYPE>& rhs) const
00279 {
00280 if( x > rhs.x && y > rhs.y )
00281 return true;
00282
00283 return false;
00284 }
00285 protected:
00286 private:
00287 };
00288
00289 typedef SPoint<int> SPointInt;
00290 typedef SPoint<short> SPointShort;
00291 typedef SPoint<long> SPointLong;
00292 typedef SPoint<unsigned int> SPointUInt;
00293 typedef SPoint<unsigned short> SPointUShort;
00294 typedef SPoint<unsigned long> SPointULong;
00295 typedef SPoint<float> SPointFloat;
00296 typedef SPoint<double> SPointDouble;
00297
00298 }
00299
00300 #endif