Hummingbird Framework
 All Classes Functions Variables Modules Pages
Vector2d.h
1 #ifndef HB_VECTOR_2D_H
2 #define HB_VECTOR_2D_H
3 #include <cmath>
4 #include <string>
5 #include <cstdlib>
6 
7 namespace hb
8 {
14  class Vector2d
15  {
16  public:
17  double x;
18  double y;
19 
24  Vector2d(): x(0), y(0){};
30  Vector2d(double x, double y): x(x), y(y){};
35  Vector2d(const Vector2d& v): x(v.x), y(v.y){};
36 
41  double module() const
42  {return sqrt(pow(x, 2) + pow(y, 2));}
43 
49  {
50  Vector2d v = *this;
51  double module = this->module();
52  if (module != 0.)
53  {
54  v.x /= module;
55  v.y /= module;
56  }
57  return v;
58  }
59  };
60 
61 }
62 
63 hb::Vector2d operator -(const hb::Vector2d& right);
64 hb::Vector2d& operator +=(hb::Vector2d& left, const hb::Vector2d& right);
65 hb::Vector2d& operator -=(hb::Vector2d& left, const hb::Vector2d& right);
66 hb::Vector2d operator +(const hb::Vector2d& left, const hb::Vector2d& right);
67 hb::Vector2d operator -(const hb::Vector2d& left, const hb::Vector2d& right);
68 hb::Vector2d operator *(const hb::Vector2d& left, double right);
69 hb::Vector2d operator *(double left, const hb::Vector2d& right);
70 hb::Vector2d& operator *=(hb::Vector2d& left, double right);
71 hb::Vector2d operator /(const hb::Vector2d& left, double right);
72 hb::Vector2d& operator /=(hb::Vector2d& left, double right);
73 bool operator ==(const hb::Vector2d& left, const hb::Vector2d& right);
74 bool operator !=(const hb::Vector2d& left, const hb::Vector2d& right);
75 #endif
76 
Vector2d(const Vector2d &v)
Copy constructor.
Definition: Vector2d.h:35
double y
y component of the vector.
Definition: Vector2d.h:18
Vector2d normalized() const
Get the vector normalied.
Definition: Vector2d.h:48
Vector2d(double x, double y)
Contruct a Vector2d from two doubles.
Definition: Vector2d.h:30
Definition: Box2DPlugin.h:6
double x
x component of the vector.
Definition: Vector2d.h:17
A 2D vector.
Definition: Vector2d.h:14
Vector2d()
Default constructor.
Definition: Vector2d.h:24
double module() const
Get the module of the Vector2d.
Definition: Vector2d.h:41