UGDK
|
00001 00002 #ifndef UGDK_MATH_INTEGER2D_H_ 00003 #define UGDK_MATH_INTEGER2D_H_ 00004 00005 #include <ugdk/base/types.h> 00006 00007 #ifdef SWIG 00008 #pragma SWIG nowarn=312 00009 #endif 00010 00011 namespace ugdk { 00012 00013 class Vector2D; 00014 00015 namespace math { 00016 00017 enum RotDeg { 00018 NINETY, TWO_NINETY, THREE_NINETY 00019 }; 00020 00021 // 2 dimension vectors, using doubles. 00022 class Integer2D { 00023 public: 00025 00027 Integer2D() : x(0), y(0) {} 00028 00030 00033 explicit Integer2D(int val) : x(val), y(val) {} 00034 00036 00040 Integer2D(int _x, int _y) : x(_x), y(_y) {} 00041 00043 Integer2D(const ugdk::Vector2D& vec2d); 00044 00045 ~Integer2D() { } 00046 00047 // Fields are accessible as x/y or val[0] and val[1]. 00048 union { 00049 struct { int x, y; }; 00050 struct { int val[2]; }; 00051 }; 00052 00053 int get_x() const { return x; } 00054 int get_y() const { return y; } 00055 void set_x(int x_) { x = x_; } 00056 void set_y(int y_) { y = y_; } 00057 00058 00060 00064 int NormOne() const; 00065 00067 00072 double Length() const; 00073 00075 00080 double LengthSquared() const { return (x*x) + (y*y); } 00081 00083 00086 double Angle() const; 00087 00089 00093 void Rotate(RotDeg rotdeg); 00094 00096 00100 void Rotate(RotDeg rotdeg, const Integer2D& center) { 00101 *this -= center; 00102 Rotate(rotdeg); 00103 *this += center; 00104 } 00105 00107 00111 Integer2D Rotated(RotDeg rotdeg) const; 00112 00114 00118 Integer2D Rotated(RotDeg rotdeg, const Integer2D& center) const { 00119 return center + (*this - center).Rotated(rotdeg); 00120 } 00121 00123 00126 void Mirror(const ugdk::enums::mirroraxis::MirrorAxis mirror); 00127 00129 00132 Integer2D Mirrored(const ugdk::enums::mirroraxis::MirrorAxis mirror) const; 00133 00135 00138 void Multiply(const Integer2D& multiplier); 00139 00141 00144 Integer2D Multiplied(const Integer2D& multiplier) const; 00145 00147 00150 void Divide(const Integer2D& divider); 00151 00153 00156 Integer2D Divided(const Integer2D& divider) const; 00157 00159 00163 void Scale(const Integer2D& multiplier, const Integer2D& divisor); 00164 00166 00170 Integer2D Scaled(const Integer2D& multiplier, const Integer2D& divisor) const; 00171 00173 00175 void Mod(const Integer2D& divisor); 00176 00178 00180 Integer2D Remainder(const Integer2D& divisor) const; 00181 00182 00183 // Operators methods 00184 00185 // TODO document 00186 Integer2D& operator+=(const Integer2D &other); 00187 00188 // TODO document 00189 Integer2D& operator-=(const Integer2D &other); 00190 00191 // TODO document 00192 Integer2D& operator*=(int scalar); 00193 00194 // TODO document 00195 Integer2D& operator/=(int scalar); 00196 00197 // TODO document 00198 Integer2D& operator%=(int scalar); 00199 00201 00204 Integer2D operator+(const Integer2D &right) const; 00205 00207 00210 // TODO revise 00211 Integer2D operator-() const; 00212 00214 00217 Integer2D operator-(const Integer2D &right) const; 00218 00219 00221 00224 Integer2D operator*(int scalar) const; 00225 00227 00230 Integer2D operator/(int scalar) const; 00231 00233 Integer2D operator%(int scalar) const; 00234 00236 00239 int operator*(const Integer2D &right) const; 00240 00242 Integer2D operator%(const Integer2D& right) const; 00243 }; 00244 00246 00249 Integer2D operator*(int scalar, const Integer2D &right); 00250 00251 } // namespace math 00252 } // namespace ugdk 00253 00254 #endif // UGDK_MATH_INTEGER2D_H_