17 #ifndef IGNITION_MATH_VECTOR2_HH_ 18 #define IGNITION_MATH_VECTOR2_HH_ 57 this->data[0] = _v[0];
58 this->data[1] = _v[1];
69 return sqrt((this->data[0]-_pt[0])*(this->data[0]-_pt[0]) +
70 (this->data[1]-_pt[1])*(this->data[1]-_pt[1]));
84 return std::pow(this->data[0], 2)
85 + std::pow(this->data[1], 2);
93 if (!equal<T>(d, static_cast<T>(0.0)))
103 public:
void Set(T _x, T _y)
114 return (this->data[0] * _v[0]) + (this->data[1] * _v[1]);
122 this->data[0] = _v[0];
123 this->data[1] = _v[1];
144 return Vector2(this->data[0] + _v[0], this->data[1] + _v[1]);
152 this->data[0] += _v[0];
153 this->data[1] += _v[1];
192 return Vector2(-this->data[0], -this->data[1]);
200 return Vector2(this->data[0] - _v[0], this->data[1] - _v[1]);
208 this->data[0] -= _v[0];
209 this->data[1] -= _v[1];
230 return {_s - _v.
X(), _s - _v.
Y()};
250 return Vector2(this->data[0] / _v[0], this->data[1] / _v[1]);
259 this->data[0] /= _v[0];
260 this->data[1] /= _v[1];
270 return Vector2(this->data[0] / _v, this->data[1] / _v);
289 return Vector2(this->data[0] * _v[0], this->data[1] * _v[1]);
298 this->data[0] *= _v[0];
299 this->data[1] *= _v[1];
309 return Vector2(this->data[0] * _v, this->data[1] * _v);
340 return equal<T>(this->data[0], _v[0], _tol)
341 && equal<T>(this->data[1], _v[1], _tol);
350 return this->
Equal(_v, static_cast<T>(1e-6));
357 return !(*
this == _v);
366 return std::isfinite(static_cast<double>(this->data[0])) &&
367 std::isfinite(static_cast<double>(this->data[1]));
380 public:
inline T
X()
const 382 return this->data[0];
387 public:
inline T
Y()
const 389 return this->data[1];
394 public:
inline T &
X()
396 return this->data[0];
401 public:
inline T &
Y()
403 return this->data[1];
408 public:
inline void X(
const T &_v)
415 public:
inline void Y(
const T &_v)
424 public:
friend std::ostream
425 &operator<<(std::ostream &_out, const Vector2<T> &_pt)
427 _out << _pt[0] <<
" " << _pt[1];
435 public:
bool operator<(const Vector2<T> &_pt)
const 437 return this->data[0] < _pt[0] || this->data[1] < _pt[1];
444 public:
friend std::istream
449 _in.setf(std::ios_base::skipws);
friend Vector2< T > operator-(const T _s, const Vector2< T > &_v)
Subtraction operators.
Definition: Vector2.hh:227
const Vector2 & operator+=(const Vector2 &_v)
Addition assignment operator.
Definition: Vector2.hh:150
const Vector2 operator/(const Vector2 &_v) const
Division operator.
Definition: Vector2.hh:248
Vector2 operator-(const Vector2 &_v) const
Subtraction operator.
Definition: Vector2.hh:198
static const size_t IGN_ONE_SIZE_T
size_t type with a value of 1
Definition: Helpers.hh:216
const Vector2 & operator*=(const Vector2 &_v)
Multiplication assignment operator.
Definition: Vector2.hh:296
void Set(T _x, T _y)
Set the contents of the vector.
Definition: Vector2.hh:103
T & X()
Return a mutable x value.
Definition: Vector2.hh:394
const Vector2< T > & operator+=(const T _s)
Addition assignment operator.
Definition: Vector2.hh:180
T operator[](const size_t _index) const
Array subscript operator.
Definition: Vector2.hh:373
T SquaredLength() const
Returns the square of the length (magnitude) of the vector.
Definition: Vector2.hh:82
static const size_t IGN_ZERO_SIZE_T
size_t type with a value of 0
Definition: Helpers.hh:213
friend Vector2< T > operator+(const T _s, const Vector2< T > &_v)
Addition operators.
Definition: Vector2.hh:171
const Vector2< T > & operator-=(T _s)
Subtraction assignment operator.
Definition: Vector2.hh:236
Two dimensional (x, y) vector.
Definition: Vector2.hh:29
T X() const
Return the x value.
Definition: Vector2.hh:380
bool Equal(const Vector2 &_v, const T &_tol) const
Equality test with tolerance.
Definition: Vector2.hh:338
Vector2< float > Vector2f
Definition: Vector2.hh:467
Vector2< T > operator-(const T _s) const
Subtraction operators.
Definition: Vector2.hh:217
bool operator!=(const Vector2 &_v) const
Not equal to operator.
Definition: Vector2.hh:355
friend std::istream & operator>>(std::istream &_in, Vector2< T > &_pt)
Stream extraction operator.
Definition: Vector2.hh:445
const Vector2 & operator/=(T _v)
Division operator.
Definition: Vector2.hh:276
bool operator==(const Vector2 &_v) const
Equal to operator.
Definition: Vector2.hh:348
const Vector2 operator*(const Vector2 &_v) const
Multiplication operators.
Definition: Vector2.hh:287
Vector2 & operator=(const Vector2 &_v)
Assignment operator.
Definition: Vector2.hh:120
const Vector2 & operator/=(const Vector2 &_v)
Division operator.
Definition: Vector2.hh:257
T & Y()
Return a mutable y value.
Definition: Vector2.hh:401
T Dot(const Vector2< T > &_v) const
Get the dot product of this vector and _v.
Definition: Vector2.hh:112
const Vector2 operator/(T _v) const
Division operator.
Definition: Vector2.hh:268
Vector2()
Default Constructor.
Definition: Vector2.hh:38
void Y(const T &_v)
Set the y value.
Definition: Vector2.hh:415
T Length() const
Returns the length (magnitude) of the vector.
Definition: Vector2.hh:75
Vector2 operator+(const Vector2 &_v) const
Addition operator.
Definition: Vector2.hh:142
static const Vector2< T > Zero
math::Vector2(0, 0)
Definition: Vector2.hh:32
const Vector2 & operator=(T _v)
Assignment operator.
Definition: Vector2.hh:131
Vector2< int > Vector2i
Definition: Vector2.hh:465
void X(const T &_v)
Set the x value.
Definition: Vector2.hh:408
double Distance(const Vector2 &_pt) const
Calc distance to the given point.
Definition: Vector2.hh:67
const Vector2 & operator-=(const Vector2 &_v)
Subtraction assignment operator.
Definition: Vector2.hh:206
Vector2 operator-() const
Negation operator.
Definition: Vector2.hh:190
void Normalize()
Normalize the vector length.
Definition: Vector2.hh:89
virtual ~Vector2()
Destructor.
Definition: Vector2.hh:62
Vector2(const Vector2< T > &_v)
Copy constructor.
Definition: Vector2.hh:55
Vector2< double > Vector2d
Definition: Vector2.hh:466
Vector2(const T &_x, const T &_y)
Constructor.
Definition: Vector2.hh:47
Vector2< T > operator+(const T _s) const
Addition operators.
Definition: Vector2.hh:161
static const Vector2< T > One
math::Vector2(1, 1)
Definition: Vector2.hh:35
bool IsFinite() const
See if a point is finite (e.g., not nan)
Definition: Vector2.hh:362
T Y() const
Return the y value.
Definition: Vector2.hh:387
const Vector2 & operator*=(T _v)
Multiplication assignment operator.
Definition: Vector2.hh:325
const Vector2 operator*(T _v) const
Multiplication operators.
Definition: Vector2.hh:307
T clamp(T _v, T _min, T _max)
Simple clamping function.
Definition: Helpers.hh:392
friend const Vector2 operator*(const T _s, const Vector2 &_v)
Scalar left multiplication operators.
Definition: Vector2.hh:316