17 #ifndef GZ_MATH_VECTOR4_HH_
18 #define GZ_MATH_VECTOR4_HH_
26 #include <gz/math/config.hh>
31 inline namespace GZ_MATH_VERSION_NAMESPACE {
58 public: constexpr
Vector4(
const T &_x,
const T &_y,
const T &_z,
60 : data{_x, _y, _z, _w}
76 return static_cast<T
>(sqrt(
77 (this->data[0]-_pt[0])*(this->data[0]-_pt[0]) +
78 (this->data[1]-_pt[1])*(this->data[1]-_pt[1]) +
79 (this->data[2]-_pt[2])*(this->data[2]-_pt[2]) +
80 (this->data[3]-_pt[3])*(this->data[3]-_pt[3])));
89 public: T
Distance(T _x, T _y, T _z, T _w)
const
91 return this->Distance(
Vector4(_x, _y, _z, _w));
98 return static_cast<T
>(sqrt(this->SquaredLength()));
106 this->data[0] * this->data[0] +
107 this->data[1] * this->data[1] +
108 this->data[2] * this->data[2] +
109 this->data[3] * this->data[3];
148 T d = this->Length();
150 if (!equal<T>(d,
static_cast<T
>(0.0)))
173 return this->data[0] * _v[0] +
174 this->data[1] * _v[1] +
175 this->data[2] * _v[2] +
176 this->data[3] * _v[3];
189 return std::abs(this->data[0] * _v[0]) +
190 std::abs(this->data[1] * _v[1]) +
191 std::abs(this->data[2] * _v[2]) +
192 std::abs(this->data[3] * _v[3]);
199 return Vector4(std::abs(this->data[0]),
200 std::abs(this->data[1]),
201 std::abs(this->data[2]),
202 std::abs(this->data[3]));
210 public:
void Set(T _x = 0, T _y = 0, T _z = 0, T _w = 0)
223 this->data[0] =
std::max(_v[0], this->data[0]);
224 this->data[1] =
std::max(_v[1], this->data[1]);
225 this->data[2] =
std::max(_v[2], this->data[2]);
226 this->data[3] =
std::max(_v[3], this->data[3]);
234 this->data[0] =
std::min(_v[0], this->data[0]);
235 this->data[1] =
std::min(_v[1], this->data[1]);
236 this->data[2] =
std::min(_v[2], this->data[2]);
237 this->data[3] =
std::min(_v[3], this->data[3]);
258 return this->data[0] + this->data[1] + this->data[2] + this->data[3];
270 this->data[0] = _value;
271 this->data[1] = _value;
272 this->data[2] = _value;
273 this->data[3] = _value;
284 this->data[1] + _v[1],
285 this->data[2] + _v[2],
286 this->data[3] + _v[3]);
294 this->data[0] += _v[0];
295 this->data[1] += _v[1];
296 this->data[2] += _v[2];
297 this->data[3] += _v[3];
340 return Vector4(-this->data[0], -this->data[1],
341 -this->data[2], -this->data[3]);
350 this->data[1] - _v[1],
351 this->data[2] - _v[2],
352 this->data[3] - _v[3]);
360 this->data[0] -= _v[0];
361 this->data[1] -= _v[1];
362 this->data[2] -= _v[2];
363 this->data[3] -= _v[3];
386 return {_s - _v.
X(), _s - _v.
Y(), _s - _v.
Z(), _s - _v.
W()};
410 this->data[1] / _v[1],
411 this->data[2] / _v[2],
412 this->data[3] / _v[3]);
422 this->data[0] /= _v[0];
423 this->data[1] /= _v[1];
424 this->data[2] /= _v[2];
425 this->data[3] /= _v[3];
437 return Vector4<T>(this->data[0] / _v, this->data[1] / _v,
438 this->data[2] / _v, this->data[3] / _v);
462 this->data[1] * _pt[1],
463 this->data[2] * _pt[2],
464 this->data[3] * _pt[3]);
473 this->data[0]*_m(0, 0) + this->data[1]*_m(1, 0) +
474 this->data[2]*_m(2, 0) + this->data[3]*_m(3, 0),
475 this->data[0]*_m(0, 1) + this->data[1]*_m(1, 1) +
476 this->data[2]*_m(2, 1) + this->data[3]*_m(3, 1),
477 this->data[0]*_m(0, 2) + this->data[1]*_m(1, 2) +
478 this->data[2]*_m(2, 2) + this->data[3]*_m(3, 2),
479 this->data[0]*_m(0, 3) + this->data[1]*_m(1, 3) +
480 this->data[2]*_m(2, 3) + this->data[3]*_m(3, 3));
490 this->data[0] *= _pt[0];
491 this->data[1] *= _pt[1];
492 this->data[2] *= _pt[2];
493 this->data[3] *= _pt[3];
503 return Vector4<T>(this->data[0] * _v, this->data[1] * _v,
504 this->data[2] * _v, this->data[3] * _v);
537 return equal<T>(this->data[0], _v[0], _tol)
538 && equal<T>(this->data[1], _v[1], _tol)
539 && equal<T>(this->data[2], _v[2], _tol)
540 && equal<T>(this->data[3], _v[3], _tol);
549 return this->Equal(_v,
static_cast<T
>(1e-6));
558 return !(*
this == _pt);
595 return this->data[0];
602 return this->data[1];
609 return this->data[2];
616 return this->data[3];
623 return this->data[0];
630 return this->data[1];
637 return this->data[2];
644 return this->data[3];
649 public:
inline void X(
const T &_v)
656 public:
inline void Y(
const T &_v)
663 public:
inline void Z(
const T &_v)
670 public:
inline void W(
const T &_v)
681 return this->data[0] < _pt[0] || this->data[1] < _pt[1] ||
682 this->data[2] < _pt[2] || this->data[3] < _pt[3];
692 for (
auto i : {0, 1, 2, 3})
712 _in.
setf(std::ios_base::skipws);
713 _in >> x >> y >> z >> w;
728 constexpr Vector4<T> gVector4Zero(0, 0, 0, 0);
731 constexpr Vector4<T> gVector4One(1, 1, 1, 1);
734 constexpr Vector4<T> gVector4NaN(