Go to the documentation of this file.
7 #ifndef INCLUDE_JET_VECTOR2_H_
8 #define INCLUDE_JET_VECTOR2_H_
26 static_assert(std::is_floating_point<T>::value,
27 "Vector only can be instantiated with floating point types");
41 constexpr
Vector(T x_, T y_) : x(x_), y(y_) {}
45 Vector(
const std::initializer_list<U>& lst);
60 void set(
const std::initializer_list<U>& lst);
149 const T&
at(
size_t i)
const;
203 template <
typename U>
211 T epsilon = std::numeric_limits<T>::epsilon())
const;
222 template <
typename U>
260 template <
typename T>
264 template <
typename T>
268 template <
typename T>
272 template <
typename T>
276 template <
typename T>
280 template <
typename T>
284 template <
typename T>
288 template <
typename T>
292 template <
typename T>
296 template <
typename T>
300 template <
typename T>
304 template <
typename T>
308 template <
typename T>
312 template <
typename T>
316 template <
typename T>
320 template <
typename T>
324 template <
typename T>
329 template <
typename T>
333 template <
typename T>
357 template <
typename T>
363 template <
typename T>
369 #include "detail/vector2-inl.h"
371 #endif // INCLUDE_JET_VECTOR2_H_
Vector(const std::initializer_list< U > &lst)
Constructs vector with initializer list.
T rcross(const Vector &v) const
Computes v cross this.
Vector & operator+=(const Vector &v)
Computes this += (v.x, v.y)
T distanceSquaredTo(const Vector &other) const
Returns the squared distance to the other vector.
Point2< T > ceil(const Point2< T > &a)
Returns element-wise ceiled point.
T min() const
Returns the minimum value among x and y.
bool operator!=(const Vector &v) const
Returns true if other is the not same as this vector.
Vector & operator/=(T v)
Computes this /= (v, v)
Vector add(const Vector &v) const
Computes this + (v.x, v.y).
T absmin() const
Returns the absolute minimum value among x and y.
T x
X (or the first) component of the vector.
Definition: vector2.h:27
Vector rsub(const Vector &v) const
Computes (v.x, v.y) - this.
Vector sub(const Vector &v) const
Computes this - (v.x, v.y).
Vector & operator*=(T v)
Computes this *= (v, v)
Vector rsub(T v) const
Computes (v, v) - this.
Vector< U, 2 > castTo() const
Returns a vector with different value type.
Vector2< double > Vector2D
Double-type 2D vector.
Definition: vector2.h:340
void set(const std::initializer_list< U > &lst)
Set x and y components with given initializer list.
Vector rdiv(const Vector &v) const
Computes (v.x, v.y) / this.
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)).
T & operator[](size_t i)
Returns reference to the i -th element of the vector.
bool operator==(const Vector &v) const
Returns true if other is the same as this vector.
Vector add(T v) const
Computes this + (v, v).
constexpr Vector(const Vector &v)
Copy constructor.
Definition: vector2.h:48
void normalize()
Normalizes this vector.
Vector tangential() const
Returns the tangential vector for this vector.
constexpr Vector()
Constructs default vector (0, 0).
Definition: vector2.h:38
void idiv(T v)
Computes this /= (v, v).
void isub(const Vector &v)
Computes this -= (v.x, v.y).
void setZero()
Set both x and y to zero.
void imul(const Vector &v)
Computes this *= (v.x, v.y).
T absmax() const
Returns the absolute maximum value among x and y.
Vector & operator-=(const Vector &v)
Computes this -= (v.x, v.y)
bool isSimilar(const Vector &other, T epsilon=std::numeric_limits< T >::epsilon()) const
Returns true if other is similar to this vector.
T & at(size_t i)
Returns reference to the i -th element of the vector.
Vector & operator+=(T v)
Computes this += (v, v)
Generic statically-sized N-D vector class.
Definition: vector.h:31
Vector & operator/=(const Vector &v)
Computes this /= (v.x, v.y)
Vector div(T v) const
Computes this / (v, v).
Vector & operator=(const std::initializer_list< U > &lst)
Set x and y components with given initializer list.
T sum() const
Returns the sum of all the components (i.e. x + y).
Vector sub(T v) const
Computes this - (v, v).
constexpr Vector(T x_, T y_)
Constructs vector with given parameters x_ and y_.
Definition: vector2.h:41
void set(T x, T y)
Set x and y components with given parameters.
T length() const
Returns the length of the vector.
Vector & operator=(const Vector &v)
Set x and y with other vector pt.
Vector & operator-=(T v)
Computes this -= (v, v)
Definition: advection_solver2.h:18
Vector normalized() const
Returns normalized vector.
Vector reflected(const Vector &normal) const
Returns the reflection vector to the surface with given surface normal.
void iadd(T v)
Computes this += (v, v).
Vector div(const Vector &v) const
Computes this / (v.x, v.y).
T y
Y (or the second) component of the vector.
Definition: vector2.h:33
void isub(T v)
Computes this -= (v, v).
2-D vector class.
Definition: vector2.h:24
T clamp(T val, T low, T high)
Returns the clamped value.
void imul(T v)
Computes this *= (v, v).
Matrix2x2< T > operator+(const Matrix2x2< T > &a, const Matrix2x2< T > &b)
Returns a + b (element-size).
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.
Vector mul(T v) const
Computes this * (v, v).
Vector mul(const Vector &v) const
Computes this * (v.x, v.y).
T lengthSquared() const
Returns the squared length of the vector.
T distanceTo(const Vector &other) const
Returns the distance to the other vector.
Vector & operator*=(const Vector &v)
Computes this *= (v.x, v.y)
void iadd(const Vector &v)
Computes this += (v.x, v.y).
T max() const
Returns the maximum value among x and y.
void set(const Vector &pt)
Set x and y with other vector pt.
void set(T s)
Set both x and y components to s.
Vector projected(const Vector &normal) const
Returns the projected vector to the surface with given surface normal.
void idiv(const Vector &v)
Computes this /= (v.x, v.y).
Vector rdiv(T v) const
Computes (v, v) / this.
const T & operator[](size_t i) const
Returns const reference to the i -th element of the vector.
size_t dominantAxis() const
Returns the index of the dominant axis.
Vector2< float > Vector2F
Float-type 2D vector.
Definition: vector2.h:337
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)).
bool isEqual(const Vector &other) const
Returns true if other is the same as this vector.
const T & at(size_t i) const
Returns const reference to the i -th element of the vector.
size_t subminantAxis() const
Returns the index of the subminant axis.
Matrix2x2< T > operator-(const Matrix2x2< T > &a)
Returns a matrix with opposite sign.
constexpr Vector2D zero< Vector2D >()
Returns double-type zero vector.
Definition: vector2.h:352
Matrix2x2< T > operator*(const Matrix2x2< T > &a, T b)
Returns a * b', where every element of matrix b' is b.
T cross(const Vector &v) const
Comptues cross product.
constexpr Vector2F zero< Vector2F >()
Returns float-type zero vector.
Definition: vector2.h:346
T dot(const Vector &v) const
Computes dot product.
T value
Definition: vector2.h:359
T avg() const
Returns the average of all the components.
Returns the type of the value itself.
Definition: type_helpers.h:14