17#ifndef GZ_MATH_VECTOR2_HH_
18#define GZ_MATH_VECTOR2_HH_
27#include <gz/math/config.hh>
34 inline namespace GZ_MATH_VERSION_NAMESPACE {
59 public:
constexpr Vector2(
const T &_x,
const T &_y)
75 return this->data[0] + this->data[1];
83 return sqrt((this->data[0]-_pt[0])*(this->data[0]-_pt[0]) +
84 (this->data[1]-_pt[1])*(this->data[1]-_pt[1]));
91 return static_cast<T
>(sqrt(this->SquaredLength()));
99 this->data[0] * this->data[0] +
100 this->data[1] * this->data[1];
106 T d = this->Length();
108 if (!equal<T>(d,
static_cast<T
>(0.0)))
145 public:
void Set(T _x, T _y)
156 return (this->data[0] * _v[0]) + (this->data[1] * _v[1]);
163 return Vector2(std::abs(this->data[0]),
164 std::abs(this->data[1]));
177 return std::abs(this->data[0] * _v[0]) +
178 std::abs(this->data[1] * _v[1]);
197 this->data[0] =
std::max(_v[0], this->data[0]);
198 this->data[1] =
std::max(_v[1], this->data[1]);
206 this->data[0] =
std::min(_v[0], this->data[0]);
207 this->data[1] =
std::min(_v[1], this->data[1]);
214 return std::max(this->data[0], this->data[1]);
221 return std::min(this->data[0], this->data[1]);
245 return Vector2(this->data[0] + _v[0], this->data[1] + _v[1]);
253 this->data[0] += _v[0];
254 this->data[1] += _v[1];
293 return Vector2(-this->data[0], -this->data[1]);
301 return Vector2(this->data[0] - _v[0], this->data[1] - _v[1]);
309 this->data[0] -= _v[0];
310 this->data[1] -= _v[1];
331 return {_s - _v.
X(), _s - _v.
Y()};
351 return Vector2(this->data[0] / _v[0], this->data[1] / _v[1]);
360 this->data[0] /= _v[0];
361 this->data[1] /= _v[1];
371 return Vector2(this->data[0] / _v, this->data[1] / _v);
390 return Vector2(this->data[0] * _v[0], this->data[1] * _v[1]);
399 this->data[0] *= _v[0];
400 this->data[1] *= _v[1];
410 return Vector2(this->data[0] * _v, this->data[1] * _v);
441 return equal<T>(this->data[0], _v[0], _tol)
442 && equal<T>(this->data[1], _v[1], _tol);
451 return this->Equal(_v,
static_cast<T
>(1e-6));
458 return !(*
this == _v);
476 return this->data[
clamp(_index, GZ_ZERO_SIZE_T, GZ_ONE_SIZE_T)];
484 return this->data[
clamp(_index, GZ_ZERO_SIZE_T, GZ_ONE_SIZE_T)];
489 public:
inline T
X()
const
491 return this->data[0];
496 public:
inline T
Y()
const
498 return this->data[1];
503 public:
inline T &
X()
505 return this->data[0];
510 public:
inline T &
Y()
512 return this->data[1];
517 public:
inline void X(
const T &_v)
524 public:
inline void Y(
const T &_v)
536 for (
auto i : {0, 1})
552 return this->data[0] < _pt[0] || this->data[1] < _pt[1];
564 _in.
setf(std::ios_base::skipws);
580 constexpr Vector2<T> gVector2Zero(0, 0);
583 constexpr Vector2<T> gVector2One(1, 1);
586 constexpr Vector2<T> gVector2NaN(
593 const Vector2<T> &Vector2<T>::Zero = detail::gVector2Zero<T>;
596 const Vector2<T> &Vector2<T>::One = detail::gVector2One<T>;
599 const Vector2<T> &Vector2<T>::NaN = detail::gVector2NaN<T>;