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 {
66 return this->data[0] + this->data[1];
74 return sqrt((this->data[0]-
_pt[0])*(this->data[0]-
_pt[0]) +
75 (this->data[1]-
_pt[1])*(this->data[1]-
_pt[1]));
82 return static_cast<T
>(sqrt(this->SquaredLength()));
90 this->data[0] * this->data[0] +
91 this->data[1] * this->data[1];
99 if (!
equal<T>(d,
static_cast<T
>(0.0)))
147 return (this->data[0] *
_v[0]) + (this->data[1] *
_v[1]);
154 return Vector2(std::abs(this->data[0]),
155 std::abs(this->data[1]));
168 return std::abs(this->data[0] *
_v[0]) +
169 std::abs(this->data[1] *
_v[1]);
188 this->data[0] =
std::max(
_v[0], this->data[0]);
189 this->data[1] =
std::max(
_v[1], this->data[1]);
197 this->data[0] =
std::min(
_v[0], this->data[0]);
198 this->data[1] =
std::min(
_v[1], this->data[1]);
205 return std::max(this->data[0], this->data[1]);
212 return std::min(this->data[0], this->data[1]);
231 return Vector2(this->data[0] +
_v[0], this->data[1] +
_v[1]);
239 this->data[0] +=
_v[0];
240 this->data[1] +=
_v[1];
279 return Vector2(-this->data[0], -this->data[1]);
287 return Vector2(this->data[0] -
_v[0], this->data[1] -
_v[1]);
295 this->data[0] -=
_v[0];
296 this->data[1] -=
_v[1];
337 return Vector2(this->data[0] /
_v[0], this->data[1] /
_v[1]);
346 this->data[0] /=
_v[0];
347 this->data[1] /=
_v[1];
357 return Vector2(this->data[0] /
_v, this->data[1] /
_v);
376 return Vector2(this->data[0] *
_v[0], this->data[1] *
_v[1]);
385 this->data[0] *=
_v[0];
386 this->data[1] *=
_v[1];
396 return Vector2(this->data[0] *
_v, this->data[1] *
_v);
437 return this->Equal(
_v,
static_cast<T
>(1
e-6));
444 return !(*
this ==
_v);
462 return this->data[
clamp(
_index, GZ_ZERO_SIZE_T, GZ_ONE_SIZE_T)];
470 return this->data[
clamp(
_index, GZ_ZERO_SIZE_T, GZ_ONE_SIZE_T)];
475 public:
inline T
X()
const
477 return this->data[0];
482 public:
inline T
Y()
const
484 return this->data[1];
489 public:
inline T &
X()
491 return this->data[0];
496 public:
inline T &
Y()
498 return this->data[1];
503 public:
inline void X(
const T &
_v)
510 public:
inline void Y(
const T &
_v)
522 for (
auto i : {0, 1})
538 return this->data[0] <
_pt[0] || this->data[1] <
_pt[1];
550 _in.setf(std::ios_base::skipws);
566 constexpr Vector2<T> gVector2Zero(0, 0);
569 constexpr Vector2<T> gVector2One(1, 1);
572 constexpr Vector2<T> gVector2NaN(