17 #ifndef _IGNITION_VECTOR2_HH_
18 #define _IGNITION_VECTOR2_HH_
51 this->data[0] = _v[0];
52 this->data[1] = _v[1];
63 return sqrt((this->data[0]-_pt[0])*(this->data[0]-_pt[0]) +
64 (this->data[1]-_pt[1])*(this->data[1]-_pt[1]));
70 double d = sqrt(this->data[0] * this->data[0] +
71 this->data[1] * this->data[1]);
80 public:
void Set(T _x, T _y)
91 return (this->data[0] * _v[0]) + (this->data[1] * _v[1]);
99 this->data[0] = _v[0];
100 this->data[1] = _v[1];
121 return Vector2(this->data[0] + _v[0], this->data[1] + _v[1]);
129 this->data[0] += _v[0];
130 this->data[1] += _v[1];
140 return Vector2(this->data[0] - _v[0], this->data[1] - _v[1]);
148 this->data[0] -= _v[0];
149 this->data[1] -= _v[1];
160 return Vector2(this->data[0] / _v[0], this->data[1] / _v[1]);
169 this->data[0] /= _v[0];
170 this->data[1] /= _v[1];
180 return Vector2(this->data[0] / _v, this->data[1] / _v);
199 return Vector2(this->data[0] * _v[0], this->data[1] * _v[1]);
208 this->data[0] *= _v[0];
209 this->data[1] *= _v[1];
219 return Vector2(this->data[0] * _v, this->data[1] * _v);
239 return equal(this->data[0], _v[0]) &&
equal(this->data[1], _v[1]);
246 return !(*
this == _v);
255 return std::isfinite(static_cast<double>(this->data[0])) &&
256 std::isfinite(static_cast<double>(this->data[1]));
268 return this->data[_index];
274 public:
inline T
X()
const
276 return this->data[0];
282 public:
inline T
Y()
const
284 return this->data[1];
290 public:
inline T &
X()
292 return this->data[0];
298 public:
inline T &
Y()
300 return this->data[1];
305 public:
inline void X(
const T &_v)
312 public:
inline void Y(
const T &_v)
322 public:
friend std::ostream
323 &operator<<(std::ostream &_out, const Vector2<T> &_pt)
325 _out << _pt[0] <<
" " << _pt[1];
333 public:
bool operator<(const Vector2<T> &_pt)
const
335 return this->data[0] < _pt[0] || this->data[1] < _pt[1];
343 public:
friend std::istream
348 _in.setf(std::ios_base::skipws);
const Vector2 & operator+=(const Vector2 &_v)
Addition assignment operator.
Definition: Vector2.hh:127
Vector2 operator-(const Vector2 &_v) const
Subtraction operator.
Definition: Vector2.hh:138
const Vector2 & operator*=(const Vector2 &_v)
Multiplication assignment operator.
Definition: Vector2.hh:206
void Set(T _x, T _y)
Set the contents of the vector.
Definition: Vector2.hh:80
T & X()
Return a mutable x value.
Definition: Vector2.hh:290
T Y() const
Return the y value.
Definition: Vector2.hh:282
T X() const
Return the x value.
Definition: Vector2.hh:274
Two dimensional (x, y) vector.
Definition: Vector2.hh:29
const Vector2 operator/(const Vector2 &_v) const
Division operator.
Definition: Vector2.hh:158
const Vector2 operator*(T _v) const
Multiplication operators.
Definition: Vector2.hh:217
Vector2< float > Vector2f
Definition: Vector2.hh:360
friend std::istream & operator>>(std::istream &_in, Vector2< T > &_pt)
Stream extraction operator.
Definition: Vector2.hh:344
T operator[](size_t _index) const
Array subscript operator.
Definition: Vector2.hh:264
const Vector2 & operator/=(T _v)
Division operator.
Definition: Vector2.hh:186
double Distance(const Vector2 &_pt) const
Calc distance to the given point.
Definition: Vector2.hh:61
Vector2 & operator=(const Vector2 &_v)
Assignment operator.
Definition: Vector2.hh:97
const Vector2 & operator/=(const Vector2 &_v)
Division operator.
Definition: Vector2.hh:167
T & Y()
Return a mutable y value.
Definition: Vector2.hh:298
const Vector2 operator/(T _v) const
Division operator.
Definition: Vector2.hh:178
Vector2()
Default Constructor.
Definition: Vector2.hh:32
void Y(const T &_v)
Set the y value.
Definition: Vector2.hh:312
Vector2 operator+(const Vector2 &_v) const
Addition operator.
Definition: Vector2.hh:119
T Dot(const Vector2< T > &_v) const
Get the dot product of this vector and _v.
Definition: Vector2.hh:89
bool operator!=(const Vector2 &_v) const
Not equal to operator.
Definition: Vector2.hh:244
const Vector2 & operator=(T _v)
Assignment operator.
Definition: Vector2.hh:108
Exception that is thrown when an out-of-bounds index is encountered.
Definition: IndexException.hh:30
Vector2< int > Vector2i
Definition: Vector2.hh:358
bool IsFinite() const
See if a point is finite (e.g., not nan)
Definition: Vector2.hh:251
void X(const T &_v)
Set the x value.
Definition: Vector2.hh:305
bool operator==(const Vector2 &_v) const
Equal to operator.
Definition: Vector2.hh:237
const Vector2 & operator-=(const Vector2 &_v)
Subtraction assignment operator.
Definition: Vector2.hh:146
void Normalize()
Normalize the vector length.
Definition: Vector2.hh:68
virtual ~Vector2()
Destructor.
Definition: Vector2.hh:56
Vector2(const Vector2< T > &_v)
Copy constructor.
Definition: Vector2.hh:49
Vector2< double > Vector2d
Definition: Vector2.hh:359
Vector2(const T &_x, const T &_y)
Constructor.
Definition: Vector2.hh:41
bool equal(const T &_a, const T &_b, const T &_epsilon=1e-6)
check if two values are equal, within a tolerance
Definition: Helpers.hh:177
const Vector2 operator*(const Vector2 &_v) const
Multiplication operators.
Definition: Vector2.hh:197
const Vector2 & operator*=(T _v)
Multiplication assignment operator.
Definition: Vector2.hh:225