UGDK  0.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
integer2D.h
Go to the documentation of this file.
1 
2 #ifndef UGDK_MATH_INTEGER2D_H_
3 #define UGDK_MATH_INTEGER2D_H_
4 
5 #include <ugdk/base/types.h>
6 
7 #ifdef SWIG
8 #pragma SWIG nowarn=312
9 #endif
10 
11 namespace ugdk {
12 
13 class Vector2D;
14 
15 namespace math {
16 
17 enum RotDeg {
19 };
20 
21 // 2 dimension vectors, using doubles.
22 class Integer2D {
23  public:
25 
27  Integer2D() : x(0), y(0) {}
28 
30 
33  explicit Integer2D(int val) : x(val), y(val) {}
34 
36 
40  Integer2D(int _x, int _y) : x(_x), y(_y) {}
41 
43  Integer2D(const ugdk::Vector2D& vec2d);
44 
45  ~Integer2D() { }
46 
47  // Fields are accessible as x/y or val[0] and val[1].
48  union {
49  struct { int x, y; };
50  struct { int val[2]; };
51  };
52 
53  int get_x() const { return x; }
54  int get_y() const { return y; }
55  void set_x(int x_) { x = x_; }
56  void set_y(int y_) { y = y_; }
57 
58 
60 
64  int NormOne() const;
65 
67 
72  double Length() const;
73 
75 
80  double LengthSquared() const { return (x*x) + (y*y); }
81 
83 
86  double Angle() const;
87 
89 
93  void Rotate(RotDeg rotdeg);
94 
96 
100  void Rotate(RotDeg rotdeg, const Integer2D& center) {
101  *this -= center;
102  Rotate(rotdeg);
103  *this += center;
104  }
105 
107 
111  Integer2D Rotated(RotDeg rotdeg) const;
112 
114 
118  Integer2D Rotated(RotDeg rotdeg, const Integer2D& center) const {
119  return center + (*this - center).Rotated(rotdeg);
120  }
121 
123 
126  void Mirror(const ugdk::enums::mirroraxis::MirrorAxis mirror);
127 
129 
133 
135 
138  void Multiply(const Integer2D& multiplier);
139 
141 
144  Integer2D Multiplied(const Integer2D& multiplier) const;
145 
147 
150  void Divide(const Integer2D& divider);
151 
153 
156  Integer2D Divided(const Integer2D& divider) const;
157 
159 
163  void Scale(const Integer2D& multiplier, const Integer2D& divisor);
164 
166 
170  Integer2D Scaled(const Integer2D& multiplier, const Integer2D& divisor) const;
171 
173 
175  void Mod(const Integer2D& divisor);
176 
178 
180  Integer2D Remainder(const Integer2D& divisor) const;
181 
182 
183  // Operators methods
184 
185  // TODO document
186  Integer2D& operator+=(const Integer2D &other);
187 
188  // TODO document
189  Integer2D& operator-=(const Integer2D &other);
190 
191  // TODO document
192  Integer2D& operator*=(int scalar);
193 
194  // TODO document
195  Integer2D& operator/=(int scalar);
196 
197  // TODO document
198  Integer2D& operator%=(int scalar);
199 
201 
204  Integer2D operator+(const Integer2D &right) const;
205 
207 
210  // TODO revise
211  Integer2D operator-() const;
212 
214 
217  Integer2D operator-(const Integer2D &right) const;
218 
219 
221 
224  Integer2D operator*(int scalar) const;
225 
227 
230  Integer2D operator/(int scalar) const;
231 
233  Integer2D operator%(int scalar) const;
234 
236 
239  int operator*(const Integer2D &right) const;
240 
242  Integer2D operator%(const Integer2D& right) const;
243 };
244 
246 
249 Integer2D operator*(int scalar, const Integer2D &right);
250 
251 } // namespace math
252 } // namespace ugdk
253 
254 #endif // UGDK_MATH_INTEGER2D_H_