Go to the documentation of this file.
7 #ifndef INCLUDE_JET_VECTOR4_H_
8 #define INCLUDE_JET_VECTOR4_H_
27 static_assert(std::is_floating_point<T>::value,
28 "Vector only can be instantiated with floating point types");
45 constexpr
Vector() : x(0), y(0), z(0), w(0) {}
48 constexpr
Vector(T x_, T y_, T z_, T w_) : x(x_), y(y_), z(z_), w(w_) {}
52 : x(v.x), y(v.y), z(v.z), w(w_) {}
56 Vector(
const std::initializer_list<U>& lst);
59 constexpr
Vector(
const Vector& v) : x(v.x), y(v.y), z(v.z), w(v.w) {}
67 void set(T x, T y, T z, T w);
74 void set(
const std::initializer_list<U>& lst);
156 const T&
at(
size_t i)
const;
201 template <
typename U>
209 T epsilon = std::numeric_limits<T>::epsilon())
const;
220 template <
typename U>
258 template <
typename T>
262 template <
typename T>
266 template <
typename T>
270 template <
typename T>
274 template <
typename T>
278 template <
typename T>
282 template <
typename T>
286 template <
typename T>
290 template <
typename T>
294 template <
typename T>
298 template <
typename T>
302 template <
typename T>
306 template <
typename T>
310 template <
typename T>
314 template <
typename T>
318 template <
typename T>
322 template <
typename T>
326 template <
typename T>
331 template <
typename T>
335 template <
typename T>
349 return Vector4F(0.f, 0.f, 0.f, 0.f);
355 return Vector4D(0.0, 0.0, 0.0, 0.0);
359 template <
typename T>
365 template <
typename T>
371 #include "detail/vector4-inl.h"
373 #endif // INCLUDE_JET_VECTOR4_H_
bool isSimilar(const Vector &other, T epsilon=std::numeric_limits< T >::epsilon()) const
Returns true if other is similar to this vector.
Vector normalized() const
Returns normalized vector.
Point2< T > ceil(const Point2< T > &a)
Returns element-wise ceiled point.
Vector sub(const Vector &v) const
Computes this - (v.x, v.y, v.z, v.w).
T sum() const
Returns the sum of all the components (i.e. x + y + z + w).
T distanceSquaredTo(const Vector &other) const
Returns the squared distance to the other vector.
constexpr Vector()
Constructs default vector (0, 0, 0, 0).
Definition: vector4.h:45
T dot(const Vector &v) const
Computes dot product.
void set(const std::initializer_list< U > &lst)
Set x, y, z, and w components with given initializer list.
T length() const
Returns the length of the vector.
T absmin() const
Returns the absolute minimum value among x, y, z, and w.
T y
Y (or the second) component of the vector.
Definition: vector4.h:34
Vector mul(const Vector &v) const
Computes this * (v.x, v.y, v.z, v.w).
Point2< T > max(const Point2< T > &a, const Point2< T > &b)
Returns element-wise max point: (max(a.x, b.x), max(a.y, b.y)).
Vector4< float > Vector4F
Float-type 4D vector.
Definition: vector4.h:339
Vector(const std::initializer_list< U > &lst)
Constructs vector with initializer list.
void idiv(const Vector &v)
Computes this /= (v.x, v.y, v.z, v.w).
Vector add(const Vector &v) const
Computes this + (v.x, v.y, v.z, v.w).
T absmax() const
Returns the absolute maximum value among x, y, z, and w.
Generic statically-sized N-D vector class.
Definition: vector.h:31
void set(T s)
Set both x, y, z, and w components to s.
size_t subminantAxis() const
Returns the index of the subminant axis.
Vector< U, 4 > castTo() const
Returns a vector with different value type.
Vector & operator+=(const Vector &v)
Computes this += (v.x, v.y, v.z, v.w)
4-D vector class.
Definition: vector4.h:25
Vector rsub(T v) const
Computes (v, v, v, v) - this.
bool isEqual(const Vector &other) const
Returns true if other is the same as this vector.
Definition: advection_solver2.h:18
Vector & operator/=(const Vector &v)
Computes this /= (v.x, v.y, v.z, v.w)
const T & operator[](size_t i) const
Returns const reference to the i -th element of the vector.
void isub(T v)
Computes this -= (v, v, v, v).
void imul(const Vector &v)
Computes this *= (v.x, v.y, v.z, v.w).
T lengthSquared() const
Returns the squared length of the vector.
Vector & operator-=(T v)
Computes this -= (v, v, v, v)
size_t dominantAxis() const
Returns the index of the dominant axis.
void idiv(T v)
Computes this /= (v, v, v, v).
T clamp(T val, T low, T high)
Returns the clamped value.
Vector & operator+=(T v)
Computes this += (v, v, v, v)
void set(T x, T y, T z, T w)
Set x, y, z, and w components with given parameters.
constexpr Vector(const Vector &v)
Copy constructor.
Definition: vector4.h:59
bool operator!=(const Vector &v) const
Returns true if other is the not same as this vector.
T value
Definition: vector4.h:361
T w
W (or the fourth) component of the vector.
Definition: vector4.h:40
Matrix2x2< T > operator+(const Matrix2x2< T > &a, const Matrix2x2< T > &b)
Returns a + b (element-size).
Vector rdiv(const Vector &v) const
Computes (v.x, v.y, v.z, v.w) / this.
Point2< T > floor(const Point2< T > &a)
Returns element-wise floored point.
T monotonicCatmullRom(const T &f0, const T &f1, const T &f2, const T &f3, T t)
Computes monotonic Catmull-Rom interpolation.
T & operator[](size_t i)
Returns reference to the i -th element of the vector.
Vector add(T v) const
Computes this + (v, v, v, v).
constexpr Vector4D zero< Vector4D >()
Returns double-type zero vector.
Definition: vector4.h:354
Vector div(const Vector &v) const
Computes this / (v.x, v.y, v.z, v.w).
Vector4< double > Vector4D
Double-type 4D vector.
Definition: vector4.h:342
Vector sub(T v) const
Computes this - (v, v, v, v).
T avg() const
Returns the average of all the components.
Vector rdiv(T v) const
Computes (v, v, v, v) / this.
void set(const Vector &v)
Set x, y, z, and w with other vector v.
T & at(size_t i)
Returns reference to the i -th element of the vector.
T x
X (or the first) component of the vector.
Definition: vector4.h:28
void setZero()
Set all x, y, z, and w to zero.
constexpr Vector4F zero< Vector4F >()
Returns float-type zero vector.
Definition: vector4.h:348
constexpr Vector(T x_, T y_, T z_, T w_)
Constructs vector with given parameters x_, y_, z_, and w_.
Definition: vector4.h:48
const T & at(size_t i) const
Returns const reference to the i -th element of the vector.
T max() const
Returns the maximum value among x, y, z, and w.
T z
Z (or the third) component of the vector.
Definition: vector4.h:37
Vector & operator=(const Vector &v)
Set x and y with other vector v.
void iadd(const Vector &v)
Computes this += (v.x, v.y, v.z, v.w).
constexpr Vector(const Vector3< T > &v, T w_)
Constructs vector with a 3-D vector (x, y, and z) and a scalar (w).
Definition: vector4.h:51
3-D vector class.
Definition: vector3.h:25
T min() const
Returns the minimum value among x, y, z, and w.
void isub(const Vector &v)
Computes this -= (v.x, v.y, v.z, v.w).
void set(const Vector< T, 3 > &pt, T z)
Set x, y, z, and w components with pt.x, pt.y, z, and w.
Vector & operator/=(T v)
Computes this /= (v, v, v, v)
Matrix2x2< T > operator/(const Matrix2x2< T > &a, T b)
Returns a' / b, where every element of matrix a' is a.
Point2< T > min(const Point2< T > &a, const Point2< T > &b)
Returns element-wise min point: (min(a.x, b.x), min(a.y, b.y)).
Vector & operator*=(const Vector &v)
Computes this *= (v.x, v.y, v.z, v.w)
Vector div(T v) const
Computes this / (v, v, v, v).
Vector & operator-=(const Vector &v)
Computes this -= (v.x, v.y, v.z, v.w)
void iadd(T v)
Computes this += (v, v, v, v).
bool operator==(const Vector &v) const
Returns true if other is the same as this vector.
Matrix2x2< T > operator-(const Matrix2x2< T > &a)
Returns a matrix with opposite sign.
T distanceTo(const Vector &other) const
Returns the distance to the other vector.
void imul(T v)
Computes this *= (v, v, v, v).
Matrix2x2< T > operator*(const Matrix2x2< T > &a, T b)
Returns a * b', where every element of matrix b' is b.
Vector mul(T v) const
Computes this * (v, v, v, v).
Vector & operator=(const std::initializer_list< U > &lst)
Set x and y components with given initializer list.
Vector rsub(const Vector &v) const
Computes (v.x, v.y, v.z, v.w) - this.
Vector & operator*=(T v)
Computes this *= (v, v, v, v)
void normalize()
Normalizes this vector.
Returns the type of the value itself.
Definition: type_helpers.h:14