17 #ifndef GZ_MATH_VECTOR2_HH_
18 #define GZ_MATH_VECTOR2_HH_
27 #include <gz/math/config.hh>
32 inline namespace GZ_MATH_VERSION_NAMESPACE {
57 public: constexpr
Vector2(
const T &_x,
const T &_y)
73 return this->data[0] + this->data[1];
81 return sqrt((this->data[0]-_pt[0])*(this->data[0]-_pt[0]) +
82 (this->data[1]-_pt[1])*(this->data[1]-_pt[1]));
89 return static_cast<T
>(sqrt(this->SquaredLength()));
97 this->data[0] * this->data[0] +
98 this->data[1] * this->data[1];
104 T d = this->Length();
106 if (!equal<T>(d,
static_cast<T
>(0.0)))
143 public:
void Set(T _x, T _y)
154 return (this->data[0] * _v[0]) + (this->data[1] * _v[1]);
161 return Vector2(std::abs(this->data[0]),
162 std::abs(this->data[1]));
175 return std::abs(this->data[0] * _v[0]) +
176 std::abs(this->data[1] * _v[1]);
195 this->data[0] =
std::max(_v[0], this->data[0]);
196 this->data[1] =
std::max(_v[1], this->data[1]);
204 this->data[0] =
std::min(_v[0], this->data[0]);
205 this->data[1] =
std::min(_v[1], this->data[1]);
212 return std::max(this->data[0], this->data[1]);
219 return std::min(this->data[0], this->data[1]);
243 return Vector2(this->data[0] + _v[0], this->data[1] + _v[1]);
251 this->data[0] += _v[0];
252 this->data[1] += _v[1];
291 return Vector2(-this->data[0], -this->data[1]);
299 return Vector2(this->data[0] - _v[0], this->data[1] - _v[1]);
307 this->data[0] -= _v[0];
308 this->data[1] -= _v[1];
329 return {_s - _v.
X(), _s - _v.
Y()};
349 return Vector2(this->data[0] / _v[0], this->data[1] / _v[1]);
358 this->data[0] /= _v[0];
359 this->data[1] /= _v[1];
369 return Vector2(this->data[0] / _v, this->data[1] / _v);
388 return Vector2(this->data[0] * _v[0], this->data[1] * _v[1]);
397 this->data[0] *= _v[0];
398 this->data[1] *= _v[1];
408 return Vector2(this->data[0] * _v, this->data[1] * _v);
439 return equal<T>(this->data[0], _v[0], _tol)
440 && equal<T>(this->data[1], _v[1], _tol);
449 return this->Equal(_v,
static_cast<T
>(1e-6));
456 return !(*
this == _v);
487 public:
inline T
X()
const
489 return this->data[0];
494 public:
inline T
Y()
const
496 return this->data[1];
501 public:
inline T &
X()
503 return this->data[0];
508 public:
inline T &
Y()
510 return this->data[1];
515 public:
inline void X(
const T &_v)
522 public:
inline void Y(
const T &_v)
534 for (
auto i : {0, 1})
550 return this->data[0] < _pt[0] || this->data[1] < _pt[1];
562 _in.
setf(std::ios_base::skipws);
578 constexpr Vector2<T> gVector2Zero(0, 0);
581 constexpr Vector2<T> gVector2One(1, 1);
584 constexpr Vector2<T> gVector2NaN(