21 #ifndef GF_VECTOR_OPS_H    22 #define GF_VECTOR_OPS_H    27 #include <type_traits>    33 #ifndef DOXYGEN_SHOULD_SKIP_THIS    41   template<
typename T, std::
size_t N>
    44     for (std::size_t i = 0; i < 
N; ++i) {
    45       if (lhs[i] != rhs[i]) {
    57   template<
typename T, std::
size_t N>
    67   template<
typename T, std::
size_t N>
    72     for (std::size_t i = 0; i < 
N; ++i) {
    83   template<
typename T, 
typename U, std::
size_t N>
    88     for (std::size_t i = 0; i < 
N; ++i) {
    89       out[i] = lhs[i] + rhs[i];
    99   template<
typename T, 
typename U, std::
size_t N>
   102     for (std::size_t i = 0; i < 
N; ++i) {
   113   template<typename T, typename U, std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<U>::value, 
U>::type>
   118     for (std::size_t i = 0; i < 
N; ++i) {
   119       out[i] = lhs[i] + rhs;
   129   template<
typename T, 
typename U, std::
size_t N>
   132     for (std::size_t i = 0; i < 
N; ++i) {
   143   template<typename T, typename U, std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<T>::value, 
T>::type>
   148     for (std::size_t i = 0; i < 
N; ++i) {
   149       out[i] = lhs + rhs[i];
   160   template<
typename T, 
typename U, std::
size_t N>
   165     for (std::size_t i = 0; i < 
N; ++i) {
   166       out[i] = lhs[i] - rhs[i];
   176   template<
typename T, 
typename U, std::
size_t N>
   179     for (std::size_t i = 0; i < 
N; ++i) {
   191   template<typename T, typename U, std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<U>::value, 
U>::type>
   196     for (std::size_t i = 0; i < 
N; ++i) {
   197       out[i] = lhs[i] - rhs;
   207   template<
typename T, 
typename U, std::
size_t N>
   210     for (std::size_t i = 0; i < 
N; ++i) {
   221   template<typename T, typename U, std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<T>::value, 
T>::type>
   226     for (std::size_t i = 0; i < 
N; ++i) {
   227       out[i] = lhs - rhs[i];
   238   template<
typename T, 
typename U, std::
size_t N>
   243     for (std::size_t i = 0; i < 
N; ++i) {
   244       out[i] = lhs[i] * rhs[i];
   254   template<
typename T, 
typename U, std::
size_t N>
   257     for (std::size_t i = 0; i < 
N; ++i) {
   268   template<typename T, typename U, std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<U>::value, 
U>::type>
   273     for (std::size_t i = 0; i < 
N; ++i) {
   274       out[i] = lhs[i] * rhs;
   284   template<
typename T, 
typename U, std::
size_t N>
   287     for (std::size_t i = 0; i < 
N; ++i) {
   298   template<typename T, typename U, std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<T>::value, 
T>::type>
   303     for (std::size_t i = 0; i < 
N; ++i) {
   304       out[i] = lhs * rhs[i];
   314   template<
typename T, 
typename U, std::
size_t N>
   319     for (std::size_t i = 0; i < 
N; ++i) {
   320       out[i] = lhs[i] / rhs[i];
   330   template<
typename T, 
typename U, std::
size_t N>
   333     for (std::size_t i = 0; i < 
N; ++i) {
   344   template<typename T, typename U, std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<U>::value, 
U>::type>
   349     for (std::size_t i = 0; i < 
N; ++i) {
   350       out[i] = lhs[i] / rhs;
   360   template<
typename T, 
typename U, std::
size_t N>
   363     for (std::size_t i = 0; i < 
N; ++i) {
   374   template<typename T, typename U, std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<T>::value, 
T>::type>
   379     for (std::size_t i = 0; i < 
N; ++i) {
   380       out[i] = lhs / rhs[i];
   390   template<std::
size_t N>
   395     for (std::size_t i = 0; i < 
N; ++i) {
   396       out[i] = lhs[i] || rhs[i];
   406   template<std::
size_t N>
   411     for (std::size_t i = 0; i < 
N; ++i) {
   412       out[i] = lhs[i] && rhs[i];
   430   template<
typename T, std::
size_t N>
   435     for (std::size_t i = 0; i < 
N; ++i) {
   436       out += lhs[i] * rhs[i];
   446   template<
typename T, std::
size_t N>
   451     for (std::size_t i = 0; i < 
N; ++i) {
   452       out[i] = std::min(lhs[i], rhs[i]);
   462   template<
typename T, std::
size_t N>
   467     for (std::size_t i = 0; i < 
N; ++i) {
   468       out[i] = std::max(lhs[i], rhs[i]);
   478   template<
typename T, std::
size_t N>
   483     for (std::size_t i = 0; i < 
N; ++i) {
   484       out[i] = std::abs(val[i]);
   494   template<
typename T, std::
size_t N>
   499     for (std::size_t i = 0; i < 
N; ++i) {
   510   template<
typename T, std::
size_t N>
   515     for (std::size_t i = 0; i < 
N; ++i) {
   516       out[i] = (lhs[i] == rhs[i]);
   526   template<
typename T, std::
size_t N>
   531     for (std::size_t i = 0; i < 
N; ++i) {
   532       out[i] = (lhs[i] < rhs[i]);
   542   template<
typename T, std::
size_t N>
   547     for (std::size_t i = 0; i < 
N; ++i) {
   548       out[i] = (lhs[i] > rhs[i]);
   558   template<
typename T, std::
size_t N>
   563     for (std::size_t i = 0; i < 
N; ++i) {
   564       out[i] = (cond[i] ? lhs[i] : rhs[i]);
   577   template<
typename T, std::
size_t N>
   582     for (std::size_t i = 0; i < 
N; ++i) {
   583       out[i] = 
clamp(val[i], lo[i], hi[i]);
   595   template<
typename T, std::
size_t N>
   600     for (std::size_t i = 0; i < 
N; ++i) {
   601       out[i] = 
clamp(val[i], lo, hi);
   611   template<
typename T, 
typename U, std::
size_t N>
   616     for (std::size_t i = 0; i < 
N; ++i) {
   617       out[i] = 
lerp(lhs[i], rhs[i], t);
   640   template<
typename T, std::
size_t N>
   645     for (std::size_t i = 0; i < 
N; ++i) {
   646       out += std::abs(vec[i]);
   666   template<
typename T, std::
size_t N>
   671     for (std::size_t i = 0; i < 
N; ++i) {
   694   template<
typename T, std::
size_t N>
   697     return std::sqrt(squareLength(vec));
   700 #ifndef DOXYGEN_SHOULD_SKIP_THIS   706     return std::hypot(vec.x, vec.y);
   712     return std::hypot(vec.x, vec.y);
   732   template<
typename T, std::
size_t N>
   735     T out = std::abs(vec[0]);
   737     for (std::size_t i = 1; i < 
N; ++i) {
   738       out = std::max(out, std::abs(vec[i]));
   761   template<
typename T, std::
size_t N>
   764     return manhattanLength(vec) + squareLength(vec);
   780   template<
typename T, std::
size_t N>
   783     return manhattanLength(lhs - rhs);
   799   template<
typename T, std::
size_t N>
   802     return squareLength(lhs - rhs);
   818   template<
typename T, std::
size_t N>
   821     return euclideanLength(lhs - rhs);
   837   template<
typename T, std::
size_t N>
   840     return chebyshevLength(lhs - rhs);
   856   template<
typename T, std::
size_t N>
   859     return naturalLength(lhs - rhs);
   877   template<
typename T, std::
size_t N>
   880     T length = euclideanLength(vec);
   894     return { vec.
x, 
T(0) };
   907     return { 
T(0), vec.
y };
   920     return { length, 
T(0) };
   933     return { 
T(0), length };
   946     return { std::cos(angle), std::sin(angle) };
   959     return std::atan2(vec.
y, vec.
x);
   976     return { -vec.
y, vec.
x };
   995     return dot(a, c) * b - dot(a, b) * c;
  1012   template<
typename T>
  1015     return - dot(c, b) * a + dot(c, a) * b;
  1035   template<
typename T>
  1038     return lhs.
x * rhs.
y - lhs.
y * rhs.
x;
  1050   template<
typename T>
  1054       lhs.
y * rhs.
z - lhs.
z * rhs.
y,
  1055       lhs.
z * rhs.
x - lhs.
x * rhs.
z,
  1056       lhs.
x * rhs.
y - lhs.
y * rhs.
x  1069   template<
typename Archive, 
typename T, std::
size_t N>
  1072     for (std::size_t i = 0; i < 
N; ++i) {
  1079 #ifndef DOXYGEN_SHOULD_SKIP_THIS  1084 #endif // GF_VECTOR_OPS_H constexpr Vector< bool, N > greaterThan(Vector< T, N > lhs, Vector< T, N > rhs)
Component-wise comparison operator. 
Definition: VectorOps.h:544
constexpr Vector< T, N > max(Vector< T, N > lhs, Vector< T, N > rhs)
Component-wise maximum. 
Definition: VectorOps.h:464
T euclideanLength(Vector< T, N > vec)
Euclidean length of a vector. 
Definition: VectorOps.h:696
T x
First coordinate in the (x,y) representation. 
Definition: Vector.h:509
constexpr Vector< std::common_type_t< T, U >, N > operator/(T lhs, Vector< U, N > rhs)
Left scalar division. 
Definition: VectorOps.h:376
constexpr T dot(Vector< T, N > lhs, Vector< T, N > rhs)
Scalar product. 
Definition: VectorOps.h:432
constexpr T lerp(T lhs, T rhs, U t)
Linear interpolation function. 
Definition: Math.h:242
constexpr Vector< T, 2 > projx(Vector< T, 2 > vec)
Project the vector on the x axis. 
Definition: VectorOps.h:893
constexpr Vector< T, N > select(Vector< bool, N > cond, Vector< T, N > lhs, Vector< T, N > rhs)
Component-wise selection operator. 
Definition: VectorOps.h:560
constexpr Vector< std::common_type_t< T, U >, N > operator*(Vector< T, N > lhs, Vector< U, N > rhs)
Component-wise multiplication. 
Definition: VectorOps.h:240
constexpr Vector< T, 3 > cross(Vector< T, 3 > lhs, Vector< T, 3 > rhs)
Cross product for 3D vectors. 
Definition: VectorOps.h:1052
constexpr Vector< std::common_type_t< T, U >, N > operator-(T lhs, Vector< U, N > rhs)
Left scalar substraction. 
Definition: VectorOps.h:223
constexpr Vector< std::common_type_t< T, U >, N > operator/(Vector< T, N > lhs, U rhs)
Right scalar division. 
Definition: VectorOps.h:346
constexpr Vector< T, N > & operator+=(Vector< T, N > &lhs, Vector< U, N > rhs)
Component-wise addition and assignment. 
Definition: VectorOps.h:101
constexpr Vector< std::common_type_t< T, U >, N > operator/(Vector< T, N > lhs, Vector< U, N > rhs)
Component-wise division. 
Definition: VectorOps.h:316
constexpr Vector< std::common_type_t< T, U >, N > operator+(Vector< T, N > lhs, Vector< U, N > rhs)
Component-wise addition. 
Definition: VectorOps.h:85
constexpr bool operator!=(Vector< T, N > lhs, Vector< T, N > rhs)
Inequality operator between two vectors. 
Definition: VectorOps.h:59
constexpr Vector< T, N > & operator*=(Vector< T, N > &lhs, U rhs)
Right scalar multiplication and assignment. 
Definition: VectorOps.h:286
constexpr Vector< T, 2 > vectorTripleProduct(Vector< T, 2 > a, Vector< T, 2 > b, Vector< T, 2 > c)
Regular vector triple product. 
Definition: VectorOps.h:994
Vector< T, N > normalize(Vector< T, N > vec)
Normalize a vector. 
Definition: VectorOps.h:879
Archive & operator|(Archive &ar, Vector< T, N > &vec)
Serialize and deserialize a vector. 
Definition: VectorOps.h:1071
constexpr Vector< T, N > & operator-=(Vector< T, N > &lhs, Vector< U, N > rhs)
Component-wise substraction and assignment. 
Definition: VectorOps.h:178
constexpr Vector< T, 2 > inverseVectorTripleProduct(Vector< T, 2 > a, Vector< T, 2 > b, Vector< T, 2 > c)
Inverse vector triple product. 
Definition: VectorOps.h:1014
T y
Second coordinate in the (x,y) representation. 
Definition: Vector.h:520
T x
First coordinate in the (x,y,z) representation. 
Definition: Vector.h:786
constexpr Vector< T, N > lerp(Vector< T, N > lhs, Vector< T, N > rhs, U t)
Component-wise lerp function. 
Definition: VectorOps.h:613
constexpr Vector< T, N > & operator+=(Vector< T, N > &lhs, U rhs)
Right scalar addition and assignment. 
Definition: VectorOps.h:131
constexpr Vector< std::common_type_t< T, U >, N > operator+(T lhs, Vector< U, N > rhs)
Left scalar addition. 
Definition: VectorOps.h:145
constexpr T square(T val)
Square function. 
Definition: Math.h:275
float angle(Vector< T, 2 > vec)
Angle of a vector relative to the x-axis. 
Definition: VectorOps.h:958
constexpr Vector< T, 2 > dirx(T length)
Create a vector in the x direction. 
Definition: VectorOps.h:919
constexpr T clamp(T val, T lo, T hi)
Clamping function. 
Definition: Math.h:260
constexpr Vector< std::common_type_t< T, U >, N > operator-(Vector< T, N > lhs, Vector< U, N > rhs)
Component-wise substraction. 
Definition: VectorOps.h:162
constexpr Vector< T, N > & operator/=(Vector< T, N > &lhs, U rhs)
Right scalar division and assignment. 
Definition: VectorOps.h:362
T squareDistance(Vector< T, N > lhs, Vector< T, N > rhs)
Square Euclidean distance between two vectors. 
Definition: VectorOps.h:801
constexpr bool operator==(Vector< T, N > lhs, Vector< T, N > rhs)
Equality operator between two vectors. 
Definition: VectorOps.h:43
constexpr Vector< bool, N > lessThan(Vector< T, N > lhs, Vector< T, N > rhs)
Component-wise comparison operator. 
Definition: VectorOps.h:528
constexpr Vector< T, N > & operator*=(Vector< T, N > &lhs, Vector< U, N > rhs)
Component-wise multiplication and assignment. 
Definition: VectorOps.h:256
constexpr Vector< bool, N > equals(Vector< T, N > lhs, Vector< T, N > rhs)
Component-wise equality operator. 
Definition: VectorOps.h:512
constexpr Vector< std::common_type_t< T, U >, N > operator-(Vector< T, N > lhs, U rhs)
Right scalar substraction. 
Definition: VectorOps.h:193
The namespace for gf classes. 
Definition: Action.h:35
constexpr Vector< T, 2 > diry(T length)
Create a vector in the y direction. 
Definition: VectorOps.h:932
constexpr Vector< T, N > operator-(Vector< T, N > val)
Component-wise unary minus. 
Definition: VectorOps.h:69
Vector< T, 2 > unit(T angle)
Unit vector in a specified direction. 
Definition: VectorOps.h:945
float angle(Direction direction)
Get an angle from a direction. 
constexpr Vector< T, N > min(Vector< T, N > lhs, Vector< T, N > rhs)
Component-wise minimum. 
Definition: VectorOps.h:448
constexpr Vector< T, N > & operator/=(Vector< T, N > &lhs, Vector< U, N > rhs)
Component-wise division and assignment. 
Definition: VectorOps.h:332
constexpr Vector< T, 2 > projy(Vector< T, 2 > vec)
Project the vector on the y axis. 
Definition: VectorOps.h:906
constexpr Vector< std::common_type_t< T, U >, N > operator*(Vector< T, N > lhs, U rhs)
Right scalar multiplication. 
Definition: VectorOps.h:270
constexpr Vector< T, N > clamp(Vector< T, N > val, T lo, T hi)
Component-wise clamp function. 
Definition: VectorOps.h:597
T manhattanDistance(Vector< T, N > lhs, Vector< T, N > rhs)
Manhattan distance between two vectors. 
Definition: VectorOps.h:782
constexpr Vector< bool, N > operator||(Vector< bool, N > lhs, Vector< bool, N > rhs)
Component-wise logical or operator. 
Definition: VectorOps.h:392
A 2D vector. 
Definition: Vector.h:316
T y
Second coordinate in the (x,y,z) representation. 
Definition: Vector.h:794
T chebyshevLength(Vector< T, N > vec)
Chebyshev length of a vector. 
Definition: VectorOps.h:734
T euclideanDistance(Vector< T, N > lhs, Vector< T, N > rhs)
Euclidean distance between two vectors. 
Definition: VectorOps.h:820
constexpr int sign(T val)
Sign function. 
Definition: Math.h:295
T manhattanLength(Vector< T, N > vec)
Manhattan length of a vector. 
Definition: VectorOps.h:642
constexpr Vector< T, N > clamp(Vector< T, N > val, Vector< T, N > lo, Vector< T, N > hi)
Component-wise clamp function. 
Definition: VectorOps.h:579
Vector< T, N > abs(Vector< T, N > val)
Component-wise absolute value. 
Definition: VectorOps.h:480
A 3D vector. 
Definition: Vector.h:565
General purpose math vector. 
Definition: Vector.h:61
constexpr Vector< std::common_type_t< T, U >, N > operator*(T lhs, Vector< U, N > rhs)
Left scalar multiplication. 
Definition: VectorOps.h:300
T z
Third coordinate in the (x,y,z) representation. 
Definition: Vector.h:802
constexpr Vector< T, 2 > perp(Vector< T, 2 > vec)
Perpendicular vector. 
Definition: VectorOps.h:975
constexpr Vector< int, N > sign(Vector< T, N > val)
Component-wise sign value. 
Definition: VectorOps.h:496
T naturalDistance(Vector< T, N > lhs, Vector< T, N > rhs)
Natural distance between two vectors. 
Definition: VectorOps.h:858
T naturalLength(Vector< T, N > vec)
Natural length of a vector. 
Definition: VectorOps.h:763
constexpr Vector< T, N > & operator-=(Vector< T, N > &lhs, U rhs)
Right scalar substraction and assignment. 
Definition: VectorOps.h:209
T squareLength(Vector< T, N > vec)
Square Euclidean length of a vector. 
Definition: VectorOps.h:668
constexpr Vector< std::common_type_t< T, U >, N > operator+(Vector< T, N > lhs, U rhs)
Right scalar addition. 
Definition: VectorOps.h:115
constexpr T cross(Vector< T, 2 > lhs, Vector< T, 2 > rhs)
Cross product for 2D vectors. 
Definition: VectorOps.h:1037
T chebyshevDistance(Vector< T, N > lhs, Vector< T, N > rhs)
Chebyshev distance between two vectors. 
Definition: VectorOps.h:839