UGDK  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
integer2D.h
Go to the documentation of this file.
1 #ifndef UGDK_MATH_INTEGER2D_H_
2 #define UGDK_MATH_INTEGER2D_H_
3 
4 #include <ugdk/structure/types.h>
5 #include <ugdk/math.h>
6 
7 #ifdef SWIG
8 #pragma SWIG nowarn=312
9 #endif
10 
11 namespace ugdk {
12 
13 namespace math {
14 
15 enum RotDeg {
17 };
18 
19 // 2 dimension vectors, using doubles.
20 class Integer2D {
21  public:
23 
25  Integer2D() : x(0), y(0) {}
26 
28 
31  explicit Integer2D(int val) : x(val), y(val) {}
32 
34 
38  Integer2D(int _x, int _y) : x(_x), y(_y) {}
39 
41  explicit Integer2D(const ugdk::math::Vector2D& vec2d);
42 
43  ~Integer2D() { }
44 
45  // Fields are accessible as x/y or val[0] and val[1].
46  union {
47  struct { int x, y; };
48  struct { int val[2]; };
49  };
50 
51  int get_x() const { return x; }
52  int get_y() const { return y; }
53  void set_x(int x_) { x = x_; }
54  void set_y(int y_) { y = y_; }
55 
56 
58 
62  int NormOne() const;
63 
65 
70  double Length() const;
71 
73 
78  double LengthSquared() const { return (x*x) + (y*y); }
79 
81 
84  double Angle() const;
85 
87 
91  void Rotate(RotDeg rotdeg);
92 
94 
98  void Rotate(RotDeg rotdeg, const Integer2D& center) {
99  *this -= center;
100  Rotate(rotdeg);
101  *this += center;
102  }
103 
105 
109  Integer2D Rotated(RotDeg rotdeg) const;
110 
112 
116  Integer2D Rotated(RotDeg rotdeg, const Integer2D& center) const {
117  return center + (*this - center).Rotated(rotdeg);
118  }
119 
121 
124  void Mirror(const ugdk::enums::mirroraxis::MirrorAxis mirror);
125 
127 
131 
133 
136  void Multiply(const Integer2D& multiplier);
137 
139 
142  Integer2D Multiplied(const Integer2D& multiplier) const;
143 
145 
148  void Divide(const Integer2D& divider);
149 
151 
154  Integer2D Divided(const Integer2D& divider) const;
155 
157 
161  void Scale(const Integer2D& multiplier, const Integer2D& divisor);
162 
164 
168  Integer2D Scaled(const Integer2D& multiplier, const Integer2D& divisor) const;
169 
171 
173  void Mod(const Integer2D& divisor);
174 
176 
178  Integer2D Remainder(const Integer2D& divisor) const;
179 
180 
181  // Operators methods
182 
183  // TODO document
184  Integer2D& operator+=(const Integer2D &other);
185 
186  // TODO document
187  Integer2D& operator-=(const Integer2D &other);
188 
189  // TODO document
190  Integer2D& operator*=(int scalar);
191 
192  // TODO document
193  Integer2D& operator/=(int scalar);
194 
195  // TODO document
196  Integer2D& operator%=(int scalar);
197 
199 
202  Integer2D operator+(const Integer2D &right) const;
203 
205 
208  // TODO revise
209  Integer2D operator-() const;
210 
212 
215  Integer2D operator-(const Integer2D &right) const;
216 
217 
219 
222  Integer2D operator*(int scalar) const;
223 
225 
228  Vector2D operator*(double scalar) const;
229 
231 
234  Integer2D operator/(int scalar) const;
235 
237  Integer2D operator%(int scalar) const;
238 
240 
243  int operator*(const Integer2D &right) const;
244 
246  Integer2D operator%(const Integer2D& right) const;
247 
249  bool operator==(const Integer2D& right) const {
250  return this->x == right.x && this->y == right.y;
251  }
252 
254  bool operator!=(const Integer2D& right) const { return !(right == *this); }
255 };
256 
258 
261 Integer2D operator*(int scalar, const Integer2D &right);
262 
264 
267 Vector2D operator*(double scalar, const Integer2D &right);
268 
269 } // namespace math
270 } // namespace ugdk
271 
272 #endif // UGDK_MATH_INTEGER2D_H_
Integer2D operator*(int scalar, const Integer2D &right)
Method that returns a integer equal to the a integer multiplied by a scalar.
Integer2D & operator+=(const Integer2D &other)
Integer2D operator%(int scalar) const
Remainder of integer division by "scalar" in each coordinate.
Definition: vector2D.h:18
Integer2D Mirrored(const ugdk::enums::mirroraxis::MirrorAxis mirror) const
Returns a new Integer2D, mirrored by the "axis" axis. Include types.h and use "using namespace ugdk::...
Integer2D Rotated(RotDeg rotdeg) const
Returns a new integer equal to this integer rotated by "angle" (in radians) counter-clockwise.
Integer2D operator-() const
Method that returns a integer equal to the oposite of another.
double LengthSquared() const
Returns the norm-2 squared.
Definition: integer2D.h:78
Definition: integer2D.h:20
Integer2D & operator/=(int scalar)
Integer2D & operator%=(int scalar)
~Integer2D()
Definition: integer2D.h:43
void Rotate(RotDeg rotdeg, const Integer2D &center)
Returns a new integer equal to this integer rotated by "angle" (in radians) counter-clockwise.
Definition: integer2D.h:98
Definition: animation.h:11
Integer2D & operator*=(int scalar)
Integer2D Remainder(const Integer2D &divisor) const
Returns a new Integer2D that is equal to the remainder of the integer division by "divisor"...
int get_y() const
Definition: integer2D.h:52
Integer2D Rotated(RotDeg rotdeg, const Integer2D &center) const
Returns a new integer equal to this integer rotated by "angle" (in radians) counter-clockwise.
Definition: integer2D.h:116
void Mod(const Integer2D &divisor)
In-place remainder (coordinate by coordinate) of integer division by "divisor".
void set_y(int y_)
Definition: integer2D.h:54
bool operator!=(const Integer2D &right) const
True when operator== is false.
Definition: integer2D.h:254
Integer2D(int _x, int _y)
Initializes both fields with given values.
Definition: integer2D.h:38
double Length() const
Returns the norm-2 of this integer.
Definition: integer2D.h:16
RotDeg
Definition: integer2D.h:15
Integer2D Scaled(const Integer2D &multiplier, const Integer2D &divisor) const
Returns a new Integer2D, multiplied by "multiplier", and divided by "divisor".
int get_x() const
Definition: integer2D.h:51
int y
Definition: integer2D.h:47
Integer2D operator+(const Integer2D &right) const
Method that returns a integer equal to the sum of two others.
Integer2D()
Initializes both fields with 0.
Definition: integer2D.h:25
Definition: integer2D.h:16
Definition: integer2D.h:16
void Mirror(const ugdk::enums::mirroraxis::MirrorAxis mirror)
Mirrors this Integer2D (in-place) by the "axis" axis. Include types.h and use "using namespace ugdk::...
void set_x(int x_)
Definition: integer2D.h:53
int val[2]
Definition: integer2D.h:48
double Angle() const
Returns the angle (in radians) of this integer.
Integer2D & operator-=(const Integer2D &other)
void Multiply(const Integer2D &multiplier)
In-place integer multiplication, coordinate by coordinate.
void Rotate(RotDeg rotdeg)
Returns a new integer equal to this integer rotated by "angle" (in radians) counter-clockwise.
Integer2D operator/(int scalar) const
Method that returns a integer equal to the a integer multiplied by the inverse of a scalar...
Integer2D operator*(int scalar) const
Method that returns a integer equal to the a integer multiplied by a int.
int NormOne() const
Returns the norm-1 of this integer.
void Scale(const Integer2D &multiplier, const Integer2D &divisor)
Multiplies in-place by "multiplier", and then divides by "divisor".
Integer2D(int val)
Initializes both fields with val.
Definition: integer2D.h:31
bool operator==(const Integer2D &right) const
Checks if their coordinates are equal, coordinate by coordinate.
Definition: integer2D.h:249
Integer2D Divided(const Integer2D &divider) const
Returns a new Integer2D equal to this divided coordinate by coordinate by "multiplier".
Integer2D Multiplied(const Integer2D &multiplier) const
Returns a new Integer2D equal to this multiplied coordinate by coordinate by "multiplier".
MirrorAxis
Definition: types.h:29
int x
Definition: integer2D.h:47
void Divide(const Integer2D &divider)
In-place integer division, coordinate by coordinate.