Go to the documentation of this file.
7 #ifndef INCLUDE_JET_VECTOR3_H_
8 #define INCLUDE_JET_VECTOR3_H_
27 static_assert(std::is_floating_point<T>::value,
28 "Vector only can be instantiated with floating point types");
42 constexpr
Vector() : x(0), y(0), z(0) {}
45 constexpr
Vector(T x_, T y_, T z_) : x(x_), y(y_), z(z_) {}
52 Vector(
const std::initializer_list<U>& lst);
63 void set(T x, T y, T z);
70 void set(
const std::initializer_list<U>& lst);
158 const T&
at(
size_t i)
const;
212 template <
typename U>
220 T epsilon = std::numeric_limits<T>::epsilon())
const;
231 template <
typename U>
269 template <
typename T>
273 template <
typename T>
277 template <
typename T>
281 template <
typename T>
285 template <
typename T>
289 template <
typename T>
293 template <
typename T>
297 template <
typename T>
301 template <
typename T>
305 template <
typename T>
309 template <
typename T>
313 template <
typename T>
317 template <
typename T>
321 template <
typename T>
325 template <
typename T>
329 template <
typename T>
333 template <
typename T>
338 template <
typename T>
342 template <
typename T>
366 template <
typename T>
372 template <
typename T>
378 #include "detail/vector3-inl.h"
380 #endif // INCLUDE_JET_VECTOR3_H_
Vector< U, 3 > castTo() const
Returns a vector with different value type.
void set(T s)
Set all x, y, and z components to s.
Vector sub(T v) const
Computes this - (v, v, v).
Vector rsub(const Vector &v) const
Computes (v.x, v.y, v.z) - this.
Point2< T > ceil(const Point2< T > &a)
Returns element-wise ceiled point.
void isub(const Vector &v)
Computes this -= (v.x, v.y, v.z).
Vector projected(const Vector &normal) const
Returns the projected vector to the surface with given surface normal.
Vector & operator=(const Vector &v)
Set x and y with other vector pt.
void iadd(const Vector &v)
Computes this += (v.x, v.y, v.z).
T distanceTo(const Vector &other) const
Returns the distance to the other vector.
T & operator[](size_t i)
Returns reference to the i -th element of the vector.
Vector rsub(T v) const
Computes (v, v, v) - this.
Vector sub(const Vector &v) const
Computes this - (v.x, v.y, v.z).
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)).
Vector & operator+=(const Vector &v)
Computes this += (v.x, v.y, v.z)
Vector(const std::initializer_list< U > &lst)
Constructs vector with initializer list.
T absmin() const
Returns the absolute minimum value among x, y, and z.
const T & at(size_t i) const
Returns const reference to the i -th element of the vector.
T sum() const
Returns the sum of all the components (i.e. x + y + z).
constexpr Vector(const Vector &v)
Copy constructor.
Definition: vector3.h:55
T y
Y (or the second) component of the vector.
Definition: vector3.h:34
Vector & operator+=(T v)
Computes this += (v, v, v)
Vector & operator*=(const Vector &v)
Computes this *= (v.x, v.y, v.z)
Vector add(T v) const
Computes this + (v, v, v).
void setZero()
Set all x, y, and z to zero.
T & at(size_t i)
Returns reference to the i -th element of the vector.
T avg() const
Returns the average of all the components.
T dot(const Vector &v) const
Computes dot product.
Vector cross(const Vector &v) const
Comptues cross product.
Generic statically-sized N-D vector class.
Definition: vector.h:31
void isub(T v)
Computes this -= (v, v, v).
bool isSimilar(const Vector &other, T epsilon=std::numeric_limits< T >::epsilon()) const
Returns true if other is similar to this vector.
bool operator==(const Vector &v) const
Returns true if other is the same as this vector.
std::tuple< Vector, Vector > tangential() const
Returns the tangential vector for this vector.
Vector mul(T v) const
Computes this * (v, v, v).
T value
Definition: vector3.h:368
Definition: advection_solver2.h:18
bool operator!=(const Vector &v) const
Returns true if other is the not same as this vector.
bool isEqual(const Vector &other) const
Returns true if other is the same as this vector.
T z
Z (or the third) component of the vector.
Definition: vector3.h:37
T x
X (or the first) component of the vector.
Definition: vector3.h:28
Vector & operator*=(T v)
Computes this *= (v, v, v)
size_t subminantAxis() const
Returns the index of the subminant axis.
size_t dominantAxis() const
Returns the index of the dominant axis.
T min() const
Returns the minimum value among x, y, and z.
void set(const Vector &v)
Set x, y, and z with other vector v.
constexpr Vector()
Constructs default vector (0, 0, 0).
Definition: vector3.h:42
Vector & operator-=(T v)
Computes this -= (v, v, v)
2-D vector class.
Definition: vector2.h:24
T clamp(T val, T low, T high)
Returns the clamped value.
Vector div(T v) const
Computes this / (v, v, v).
Matrix2x2< T > operator+(const Matrix2x2< T > &a, const Matrix2x2< T > &b)
Returns a + b (element-size).
Vector & operator/=(T v)
Computes this /= (v, v, v)
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.
const T & operator[](size_t i) const
Returns const reference to the i -th element of the vector.
void set(T x, T y, T z)
Set x, y, and z components with given parameters.
void idiv(T v)
Computes this /= (v, v, v).
constexpr Vector(const Vector2< T > &v, T z_)
Constructs vector with a 2-D vector and a scalar.
Definition: vector3.h:48
constexpr Vector(T x_, T y_, T z_)
Constructs vector with given parameters x_, y_, and z_.
Definition: vector3.h:45
Vector & operator-=(const Vector &v)
Computes this -= (v.x, v.y, v.z)
void idiv(const Vector &v)
Computes this /= (v.x, v.y, v.z).
void set(const Vector2< T > &pt, T z)
Set x, y, and z components with given pt.x, pt.y, and z.
void imul(const Vector &v)
Computes this *= (v.x, v.y, v.z).
void iadd(T v)
Computes this += (v, v, v).
Vector & operator/=(const Vector &v)
Computes this /= (v.x, v.y, v.z)
Vector normalized() const
Returns normalized vector.
Vector3< double > Vector3D
Double-type 3D vector.
Definition: vector3.h:349
Vector add(const Vector &v) const
Computes this + (v.x, v.y, v.z).
Vector reflected(const Vector &normal) const
Returns the reflection vector to the surface with given surface normal.
3-D vector class.
Definition: vector3.h:25
T length() const
Returns the length of the vector.
void imul(T v)
Computes this *= (v, v, v).
Vector div(const Vector &v) const
Computes this / (v.x, v.y, v.z).
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)).
T distanceSquaredTo(const Vector &other) const
Returns the squared distance to the other vector.
Vector mul(const Vector &v) const
Computes this * (v.x, v.y, v.z).
T absmax() const
Returns the absolute maximum value among x, y, and z.
Matrix2x2< T > operator-(const Matrix2x2< T > &a)
Returns a matrix with opposite sign.
T lengthSquared() const
Returns the squared length of the vector.
Vector & operator=(const std::initializer_list< U > &lst)
Set x and y components with given initializer list.
void normalize()
Normalizes this vector.
Vector3< float > Vector3F
Float-type 3D vector.
Definition: vector3.h:346
Matrix2x2< T > operator*(const Matrix2x2< T > &a, T b)
Returns a * b', where every element of matrix b' is b.
Vector rcross(const Vector &v) const
Computes v cross this.
constexpr Vector3D zero< Vector3D >()
Returns double-type zero vector.
Definition: vector3.h:361
Vector rdiv(const Vector &v) const
Computes (v.x, v.y, v.z) / this.
constexpr Vector3F zero< Vector3F >()
Returns float-type zero vector.
Definition: vector3.h:355
T max() const
Returns the maximum value among x, y, and z.
Vector rdiv(T v) const
Computes (v, v, v) / this.
Returns the type of the value itself.
Definition: type_helpers.h:14
void set(const std::initializer_list< U > &lst)
Set x, y, and z components with given initializer list.