D:/Zythum/DinoKod/Common/Point.h

00001 #ifndef __POINT_H__
00002 #define __POINT_H__
00003 
00004 #include "Common/CommonDll.h"
00005 #include <math.h>
00006 
00007 //--------------------------------------------------------------------------------------------------------------------------
00008 class COMMON_API KPt
00009 {
00010 public:
00011         s32     x;
00012         s32     y;
00013 
00014         inline KPt()
00015         {
00016                 x = 0;
00017                 y = 0;
00018         }
00019 
00020         inline KPt( s32 x, s32 y )
00021         {
00022                 this->x = x;
00023                 this->y = y;
00024         }
00025 
00026         inline KPt operator +( KPt pt )
00027         {
00028                 KPt     result;
00029                 result.x = x + pt.x;
00030                 result.y = y + pt.y;
00031 
00032                 return result;
00033         }
00034 
00035         inline KPt operator -( KPt pt )
00036         {
00037                 KPt     result;
00038                 result.x = x - pt.x;
00039                 result.y = y - pt.y;
00040 
00041                 return result;
00042         }
00043 
00044         inline KPt operator -( s32 value )
00045         {
00046                 KPt result;
00047                 result.x = x - value;
00048                 result.y = y - value;
00049 
00050                 return result;
00051         }
00052 
00053         inline KPt operator /( s32 value )
00054         {
00055                 KPt result;
00056                 result.x = x / value;
00057                 result.y = y / value;
00058 
00059                 return result;
00060         }
00061 
00062         inline bool operator ==( KPt pt )
00063         {
00064                 return (x == pt.x) && (y == pt.y);
00065         }
00066 
00067         inline bool operator !=( KPt pt )
00068         {
00069                 return (x != pt.x) || (y != pt.y);
00070         }
00071 };
00072 
00073 //--------------------------------------------------------------------------------------------------------------------------
00074 class COMMON_API KFPt
00075 {
00076 public:
00077         float   x;
00078         float   y;
00079 
00080         inline KFPt()
00081         {
00082                 x = 0;
00083                 y = 0;
00084         }
00085 
00086         inline KFPt( float x, float y )
00087         {
00088                 this->x = x;
00089                 this->y = y;
00090         }
00091 
00092         inline KFPt operator +( KFPt pt )
00093         {
00094                 KFPt    result;
00095                 result.x = x + pt.x;
00096                 result.y = y + pt.y;
00097 
00098                 return result;
00099         }
00100 
00101         inline KFPt& operator +=( KFPt pt )
00102         {
00103                 x += pt.x;
00104                 y += pt.y;
00105                 return *this;
00106         }
00107 
00108         inline KFPt operator -( KFPt pt )
00109         {
00110                 KFPt    result;
00111                 result.x = x - pt.x;
00112                 result.y = y - pt.y;
00113 
00114                 return result;
00115         }
00116 
00117         inline KFPt operator -( float value )
00118         {
00119                 KFPt result;
00120                 result.x = x - value;
00121                 result.y = y - value;
00122 
00123                 return result;
00124         }
00125 
00126         inline KFPt operator *( float value )
00127         {
00128                 KFPt result;
00129                 result.x = x * value;
00130                 result.y = y * value;
00131 
00132                 return result;
00133         }
00134 
00135         inline KFPt operator /( float value )
00136         {
00137                 KFPt result;
00138                 result.x = x / value;
00139                 result.y = y / value;
00140 
00141                 return result;
00142         }
00143 
00144         inline KFPt operator *( KFPt& value )
00145         {
00146                 KFPt result;
00147                 result.x = x * value.x;
00148                 result.y = y * value.y;
00149 
00150                 return result;
00151         }
00152 
00153         inline KFPt& operator *=( KFPt& value )
00154         {
00155                 x *= value.x;
00156                 y *= value.y;
00157 
00158                 return *this;
00159         }
00160 
00161         //----------------------------------
00162         inline float SquareMagnitude()
00163         {
00164                 return x * x + y * y;
00165         }
00166 
00167         inline float Magnitude()
00168         {
00169                 return sqrtf( SquareMagnitude() );
00170         }
00171 
00172         inline void Normalize()
00173         {
00174                 float magnitude = Magnitude();
00175                 
00176                 if( !magnitude )
00177                         return;
00178 
00179                 x = x / magnitude;
00180                 y = y / magnitude;
00181         }
00182 
00183 };
00184 
00185 #endif // __POINT_H__

Generated on Sun Mar 25 20:02:11 2007 for Zythum Project by  doxygen 1.5.1-p1