21 #ifndef GF_VECTOR_OPS_H    22 #define GF_VECTOR_OPS_H    26 #include <type_traits>    32 #ifndef DOXYGEN_SHOULD_SKIP_THIS    40   template<
typename T, std::
size_t N>
    43     for (std::size_t i = 0; i < 
N; ++i) {
    44       if (lhs[i] != rhs[i]) {
    56   template<
typename T, std::
size_t N>
    66   template<
typename T, std::
size_t N>
    71     for (std::size_t i = 0; i < 
N; ++i) {
    82   template<
typename T, 
typename U, std::
size_t N>
    87     for (std::size_t i = 0; i < 
N; ++i) {
    88       out[i] = lhs[i] + rhs[i];
    98   template<
typename T, 
typename U, std::
size_t N>
   101     for (std::size_t i = 0; i < 
N; ++i) {
   112   template<typename T, typename U, std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<U>::value, 
U>::type>
   117     for (std::size_t i = 0; i < 
N; ++i) {
   118       out[i] = lhs[i] + rhs;
   128   template<
typename T, 
typename U, std::
size_t N>
   131     for (std::size_t i = 0; i < 
N; ++i) {
   142   template<typename T, typename U, std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<T>::value, 
T>::type>
   147     for (std::size_t i = 0; i < 
N; ++i) {
   148       out[i] = lhs + rhs[i];
   159   template<
typename T, 
typename U, std::
size_t N>
   164     for (std::size_t i = 0; i < 
N; ++i) {
   165       out[i] = lhs[i] - rhs[i];
   175   template<
typename T, 
typename U, std::
size_t N>
   178     for (std::size_t i = 0; i < 
N; ++i) {
   190   template<typename T, typename U, std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<U>::value, 
U>::type>
   195     for (std::size_t i = 0; i < 
N; ++i) {
   196       out[i] = lhs[i] - rhs;
   206   template<
typename T, 
typename U, std::
size_t N>
   209     for (std::size_t i = 0; i < 
N; ++i) {
   220   template<typename T, typename U, std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<T>::value, 
T>::type>
   225     for (std::size_t i = 0; i < 
N; ++i) {
   226       out[i] = lhs - rhs[i];
   237   template<
typename T, 
typename U, std::
size_t N>
   242     for (std::size_t i = 0; i < 
N; ++i) {
   243       out[i] = lhs[i] * rhs[i];
   253   template<
typename T, 
typename U, std::
size_t N>
   256     for (std::size_t i = 0; i < 
N; ++i) {
   267   template<typename T, typename U, std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<U>::value, 
U>::type>
   272     for (std::size_t i = 0; i < 
N; ++i) {
   273       out[i] = lhs[i] * rhs;
   283   template<
typename T, 
typename U, std::
size_t N>
   286     for (std::size_t i = 0; i < 
N; ++i) {
   297   template<typename T, typename U, std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<T>::value, 
T>::type>
   302     for (std::size_t i = 0; i < 
N; ++i) {
   303       out[i] = lhs * rhs[i];
   313   template<
typename T, 
typename U, std::
size_t N>
   318     for (std::size_t i = 0; i < 
N; ++i) {
   319       out[i] = lhs[i] / rhs[i];
   329   template<
typename T, 
typename U, std::
size_t N>
   332     for (std::size_t i = 0; i < 
N; ++i) {
   343   template<typename T, typename U, std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<U>::value, 
U>::type>
   348     for (std::size_t i = 0; i < 
N; ++i) {
   349       out[i] = lhs[i] / rhs;
   359   template<
typename T, 
typename U, std::
size_t N>
   362     for (std::size_t i = 0; i < 
N; ++i) {
   373   template<typename T, typename U, std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<T>::value, 
T>::type>
   378     for (std::size_t i = 0; i < 
N; ++i) {
   379       out[i] = lhs / rhs[i];
   389   template<std::
size_t N>
   394     for (std::size_t i = 0; i < 
N; ++i) {
   395       out[i] = lhs[i] || rhs[i];
   405   template<std::
size_t N>
   410     for (std::size_t i = 0; i < 
N; ++i) {
   411       out[i] = lhs[i] && rhs[i];
   429   template<
typename T, std::
size_t N>
   434     for (std::size_t i = 0; i < 
N; ++i) {
   435       out += lhs[i] * rhs[i];
   445   template<
typename T, std::
size_t N>
   450     for (std::size_t i = 0; i < 
N; ++i) {
   451       out[i] = std::min(lhs[i], rhs[i]);
   461   template<
typename T, std::
size_t N>
   466     for (std::size_t i = 0; i < 
N; ++i) {
   467       out[i] = std::max(lhs[i], rhs[i]);
   477   template<
typename T, std::
size_t N>
   482     for (std::size_t i = 0; i < 
N; ++i) {
   483       out[i] = std::abs(val[i]);
   493   template<
typename T, std::
size_t N>
   498     for (std::size_t i = 0; i < 
N; ++i) {
   509   template<
typename T, std::
size_t N>
   514     for (std::size_t i = 0; i < 
N; ++i) {
   515       out[i] = (lhs[i] == rhs[i]);
   525   template<
typename T, std::
size_t N>
   530     for (std::size_t i = 0; i < 
N; ++i) {
   531       out[i] = (lhs[i] < rhs[i]);
   541   template<
typename T, std::
size_t N>
   546     for (std::size_t i = 0; i < 
N; ++i) {
   547       out[i] = (lhs[i] > rhs[i]);
   557   template<
typename T, std::
size_t N>
   562     for (std::size_t i = 0; i < 
N; ++i) {
   563       out[i] = (cond[i] ? lhs[i] : rhs[i]);
   576   template<
typename T, std::
size_t N>
   581     for (std::size_t i = 0; i < 
N; ++i) {
   582       out[i] = 
clamp(val[i], lo[i], hi[i]);
   594   template<
typename T, std::
size_t N>
   599     for (std::size_t i = 0; i < 
N; ++i) {
   600       out[i] = 
clamp(val[i], lo, hi);
   610   template<
typename T, 
typename U, std::
size_t N>
   615     for (std::size_t i = 0; i < 
N; ++i) {
   616       out[i] = 
lerp(lhs[i], rhs[i], t);
   639   template<
typename T, std::
size_t N>
   644     for (std::size_t i = 0; i < 
N; ++i) {
   645       out += std::abs(vec[i]);
   665   template<
typename T, std::
size_t N>
   670     for (std::size_t i = 0; i < 
N; ++i) {
   693   template<
typename T, std::
size_t N>
   696     return std::sqrt(squareLength(vec));
   699 #ifndef DOXYGEN_SHOULD_SKIP_THIS   705     return std::hypot(vec.x, vec.y);
   711     return std::hypot(vec.x, vec.y);
   731   template<
typename T, std::
size_t N>
   734     T out = std::abs(vec[0]);
   736     for (std::size_t i = 1; i < 
N; ++i) {
   737       out = std::max(out, std::abs(vec[i]));
   760   template<
typename T, std::
size_t N>
   763     return manhattanLength(vec) + squareLength(vec);
   779   template<
typename T, std::
size_t N>
   782     return manhattanLength(lhs - rhs);
   798   template<
typename T, std::
size_t N>
   801     return squareLength(lhs - rhs);
   817   template<
typename T, std::
size_t N>
   820     return euclideanLength(lhs - rhs);
   836   template<
typename T, std::
size_t N>
   839     return chebyshevLength(lhs - rhs);
   855   template<
typename T, std::
size_t N>
   858     return naturalLength(lhs - rhs);
   876   template<
typename T, std::
size_t N>
   879     T length = euclideanLength(vec);
   893     return { std::cos(angle), std::sin(angle) };
   906     return std::atan2(vec.
y, vec.
x);
   923     return { -vec.
y, vec.
x };
   942     return dot(a, c) * b - dot(a, b) * c;
   962     return - dot(c, b) * a + dot(c, a) * b;
   985     return lhs.
x * rhs.
y - lhs.
y * rhs.
x;
  1001       lhs.
y * rhs.
z - lhs.
z * rhs.
y,
  1002       lhs.
z * rhs.
x - lhs.
x * rhs.
z,
  1003       lhs.
x * rhs.
y - lhs.
y * rhs.
x  1007 #ifndef DOXYGEN_SHOULD_SKIP_THIS  1012 #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:543
 
constexpr Vector< T, N > max(Vector< T, N > lhs, Vector< T, N > rhs)
Component-wise maximum. 
Definition: VectorOps.h:463
 
T euclideanLength(Vector< T, N > vec)
Euclidean length of a vector. 
Definition: VectorOps.h:695
 
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:375
 
constexpr T dot(Vector< T, N > lhs, Vector< T, N > rhs)
Scalar product. 
Definition: VectorOps.h:431
 
constexpr T lerp(T lhs, T rhs, U t)
Linear interpolation function. 
Definition: Math.h:242
 
constexpr Vector< T, N > select(Vector< bool, N > cond, Vector< T, N > lhs, Vector< T, N > rhs)
Component-wise selection operator. 
Definition: VectorOps.h:559
 
constexpr Vector< std::common_type_t< T, U >, N > operator*(Vector< T, N > lhs, Vector< U, N > rhs)
Component-wise multiplication. 
Definition: VectorOps.h:239
 
constexpr Vector< T, 3 > cross(Vector< T, 3 > lhs, Vector< T, 3 > rhs)
Cross product for 3D vectors. 
Definition: VectorOps.h:999
 
constexpr Vector< std::common_type_t< T, U >, N > operator-(T lhs, Vector< U, N > rhs)
Left scalar substraction. 
Definition: VectorOps.h:222
 
constexpr Vector< std::common_type_t< T, U >, N > operator/(Vector< T, N > lhs, U rhs)
Right scalar division. 
Definition: VectorOps.h:345
 
constexpr Vector< T, N > & operator+=(Vector< T, N > &lhs, Vector< U, N > rhs)
Component-wise addition and assignment. 
Definition: VectorOps.h:100
 
constexpr Vector< std::common_type_t< T, U >, N > operator/(Vector< T, N > lhs, Vector< U, N > rhs)
Component-wise division. 
Definition: VectorOps.h:315
 
constexpr Vector< std::common_type_t< T, U >, N > operator+(Vector< T, N > lhs, Vector< U, N > rhs)
Component-wise addition. 
Definition: VectorOps.h:84
 
constexpr bool operator!=(Vector< T, N > lhs, Vector< T, N > rhs)
Inequality operator between two vectors. 
Definition: VectorOps.h:58
 
constexpr Vector< T, N > & operator*=(Vector< T, N > &lhs, U rhs)
Right scalar multiplication and assignment. 
Definition: VectorOps.h:285
 
constexpr Vector< T, 2 > vectorTripleProduct(Vector< T, 2 > a, Vector< T, 2 > b, Vector< T, 2 > c)
Regular vector triple product. 
Definition: VectorOps.h:941
 
Vector< T, N > normalize(Vector< T, N > vec)
Normalize a vector. 
Definition: VectorOps.h:878
 
constexpr Vector< T, N > & operator-=(Vector< T, N > &lhs, Vector< U, N > rhs)
Component-wise substraction and assignment. 
Definition: VectorOps.h:177
 
constexpr Vector< T, 2 > inverseVectorTripleProduct(Vector< T, 2 > a, Vector< T, 2 > b, Vector< T, 2 > c)
Inverse vector triple product. 
Definition: VectorOps.h:961
 
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:612
 
constexpr Vector< T, N > & operator+=(Vector< T, N > &lhs, U rhs)
Right scalar addition and assignment. 
Definition: VectorOps.h:130
 
constexpr Vector< std::common_type_t< T, U >, N > operator+(T lhs, Vector< U, N > rhs)
Left scalar addition. 
Definition: VectorOps.h:144
 
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:905
 
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:161
 
constexpr Vector< T, N > & operator/=(Vector< T, N > &lhs, U rhs)
Right scalar division and assignment. 
Definition: VectorOps.h:361
 
T squareDistance(Vector< T, N > lhs, Vector< T, N > rhs)
Square Euclidean distance between two vectors. 
Definition: VectorOps.h:800
 
constexpr bool operator==(Vector< T, N > lhs, Vector< T, N > rhs)
Equality operator between two vectors. 
Definition: VectorOps.h:42
 
constexpr Vector< bool, N > lessThan(Vector< T, N > lhs, Vector< T, N > rhs)
Component-wise comparison operator. 
Definition: VectorOps.h:527
 
constexpr Vector< T, N > & operator*=(Vector< T, N > &lhs, Vector< U, N > rhs)
Component-wise multiplication and assignment. 
Definition: VectorOps.h:255
 
constexpr Vector< bool, N > equals(Vector< T, N > lhs, Vector< T, N > rhs)
Component-wise equality operator. 
Definition: VectorOps.h:511
 
constexpr Vector< std::common_type_t< T, U >, N > operator-(Vector< T, N > lhs, U rhs)
Right scalar substraction. 
Definition: VectorOps.h:192
 
The namespace for gf classes. 
Definition: Action.h:34
 
constexpr Vector< T, N > operator-(Vector< T, N > val)
Component-wise unary minus. 
Definition: VectorOps.h:68
 
Vector< T, 2 > unit(T angle)
Unit vector in a specified direction. 
Definition: VectorOps.h:892
 
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:447
 
constexpr Vector< T, N > & operator/=(Vector< T, N > &lhs, Vector< U, N > rhs)
Component-wise division and assignment. 
Definition: VectorOps.h:331
 
constexpr Vector< std::common_type_t< T, U >, N > operator*(Vector< T, N > lhs, U rhs)
Right scalar multiplication. 
Definition: VectorOps.h:269
 
constexpr Vector< T, N > clamp(Vector< T, N > val, T lo, T hi)
Component-wise clamp function. 
Definition: VectorOps.h:596
 
T manhattanDistance(Vector< T, N > lhs, Vector< T, N > rhs)
Manhattan distance between two vectors. 
Definition: VectorOps.h:781
 
constexpr Vector< bool, N > operator||(Vector< bool, N > lhs, Vector< bool, N > rhs)
Component-wise logical or operator. 
Definition: VectorOps.h:391
 
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:733
 
T euclideanDistance(Vector< T, N > lhs, Vector< T, N > rhs)
Euclidean distance between two vectors. 
Definition: VectorOps.h:819
 
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:641
 
constexpr Vector< T, N > clamp(Vector< T, N > val, Vector< T, N > lo, Vector< T, N > hi)
Component-wise clamp function. 
Definition: VectorOps.h:578
 
Vector< T, N > abs(Vector< T, N > val)
Component-wise absolute value. 
Definition: VectorOps.h:479
 
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:299
 
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:922
 
constexpr Vector< int, N > sign(Vector< T, N > val)
Component-wise sign value. 
Definition: VectorOps.h:495
 
T naturalDistance(Vector< T, N > lhs, Vector< T, N > rhs)
Natural distance between two vectors. 
Definition: VectorOps.h:857
 
T naturalLength(Vector< T, N > vec)
Natural length of a vector. 
Definition: VectorOps.h:762
 
constexpr Vector< T, N > & operator-=(Vector< T, N > &lhs, U rhs)
Right scalar substraction and assignment. 
Definition: VectorOps.h:208
 
T squareLength(Vector< T, N > vec)
Square Euclidean length of a vector. 
Definition: VectorOps.h:667
 
constexpr Vector< std::common_type_t< T, U >, N > operator+(Vector< T, N > lhs, U rhs)
Right scalar addition. 
Definition: VectorOps.h:114
 
constexpr T cross(Vector< T, 2 > lhs, Vector< T, 2 > rhs)
Cross product for 2D vectors. 
Definition: VectorOps.h:984
 
T chebyshevDistance(Vector< T, N > lhs, Vector< T, N > rhs)
Chebyshev distance between two vectors. 
Definition: VectorOps.h:838