28 #include <initializer_list> 
   29 #include <type_traits> 
   35 #ifndef DOXYGEN_SHOULD_SKIP_THIS 
   60   template<
typename T, std::size_t N>
 
   62     #ifndef DOXYGEN_SHOULD_SKIP_THIS 
   63     static_assert(
N > 0, 
"N must be strictly positive");
 
   89       std::fill_n(
data, N, val);
 
  107       std::copy_n(array, N, 
data);
 
  125       std::copy_n(list.begin(), std::min(list.size(), N), 
data);
 
  148       std::transform(
data, 
data + N, other.data, [](U val) { 
return static_cast<T>(val); });
 
  242   template <
typename T>
 
  266       std::fill_n(data, 2, val);
 
  284       std::copy_n(array, 2, data);
 
  418   template <
typename T>
 
  442       std::fill_n(data, 3, val);
 
  460       std::copy_n(array, 3, data);
 
  483     : data{ xy.x, xy.y, z }
 
  599   template <
typename T>
 
  623       std::fill_n(data, 4, val);
 
  641       std::copy_n(array, 4, data);
 
  871   extern template struct Vector<
float, 2>;
 
  872   extern template struct Vector<
float, 3>;
 
  873   extern template struct Vector<
float, 4>;
 
  875   extern template struct Vector<
double, 2>;
 
  876   extern template struct Vector<
double, 3>;
 
  877   extern template struct Vector<
double, 4>;
 
  879   extern template struct Vector<
int, 2>;
 
  880   extern template struct Vector<
int, 3>;
 
  881   extern template struct Vector<
int, 4>;
 
  883   extern template struct Vector<
unsigned, 2>;
 
  884   extern template struct Vector<
unsigned, 3>;
 
  885   extern template struct Vector<
unsigned, 4>;
 
  887   extern template struct Vector<std::size_t, 2>;
 
  888   extern template struct Vector<std::size_t, 3>;
 
  889   extern template struct Vector<std::size_t, 4>;
 
  891   extern template struct Vector<
bool, 2>;
 
  892   extern template struct Vector<
bool, 3>;
 
  893   extern template struct Vector<
bool, 4>;
 
  895   extern template struct Vector<uint8_t, 3>;
 
  896   extern template struct Vector<uint8_t, 4>;
 
  903   template<
typename T, std::size_t N>
 
  906     for (std::size_t i = 0; i < N; ++i) {
 
  907       if (lhs.data[i] != rhs.data[i]) {
 
  919   template<
typename T, std::size_t N>
 
  922     return !(lhs == rhs);
 
  929   template<
typename T, std::size_t N>
 
  934     for (std::size_t i = 0; i < N; ++i) {
 
  935       out.data[i] = - val.data[i];
 
  945   template<
typename T, 
typename U, std::size_t N>
 
  948     Vector<
typename std::common_type<T,U>::type, N> out;
 
  950     for (std::size_t i = 0; i < N; ++i) {
 
  951       out.data[i] = lhs.data[i] + rhs.data[i];
 
  961   template<
typename T, 
typename U, std::size_t N>
 
  964     for (std::size_t i = 0; i < N; ++i) {
 
  965       lhs.data[i] += rhs.data[i];
 
  975   template<
typename T, 
typename U, std::size_t N, 
typename E = 
typename std::enable_if<std::is_arithmetic<U>::value, U>::type>
 
  978     Vector<
typename std::common_type<T,U>::type, N> out;
 
  980     for (std::size_t i = 0; i < N; ++i) {
 
  981       out.data[i] = lhs.data[i] + rhs;
 
  991   template<
typename T, 
typename U, std::size_t N, 
typename E = 
typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
 
  994     Vector<
typename std::common_type<T,U>::type, N> out;
 
  996     for (std::size_t i = 0; i < N; ++i) {
 
  997       out.data[i] = lhs + rhs.data[i];
 
 1008   template<
typename T, 
typename U, std::size_t N>
 
 1011     Vector<
typename std::common_type<T,U>::type, N> out;
 
 1013     for (std::size_t i = 0; i < N; ++i) {
 
 1014       out.data[i] = lhs.data[i] - rhs.data[i];
 
 1024   template<
typename T, 
typename U, std::size_t N>
 
 1027     for (std::size_t i = 0; i < N; ++i) {
 
 1028       lhs.data[i] -= rhs.data[i];
 
 1039   template<
typename T, 
typename U, std::size_t N, 
typename E = 
typename std::enable_if<std::is_arithmetic<U>::value, U>::type>
 
 1042     Vector<
typename std::common_type<T,U>::type, N> out;
 
 1044     for (std::size_t i = 0; i < N; ++i) {
 
 1045       out.data[i] = lhs.data[i] - rhs;
 
 1055   template<
typename T, 
typename U, std::size_t N, 
typename E = 
typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
 
 1058     Vector<
typename std::common_type<T,U>::type, N> out;
 
 1060     for (std::size_t i = 0; i < N; ++i) {
 
 1061       out.data[i] = lhs - rhs.data[i];
 
 1072   template<
typename T, 
typename U, std::size_t N>
 
 1075     Vector<
typename std::common_type<T,U>::type, N> out;
 
 1077     for (std::size_t i = 0; i < N; ++i) {
 
 1078       out.data[i] = lhs.data[i] * rhs.data[i];
 
 1088   template<
typename T, 
typename U, std::size_t N>
 
 1091     for (std::size_t i = 0; i < N; ++i) {
 
 1092       lhs.data[i] *= rhs.data[i];
 
 1102   template<
typename T, 
typename U, std::size_t N, 
typename E = 
typename std::enable_if<std::is_arithmetic<U>::value, U>::type>
 
 1105     Vector<
typename std::common_type<T,U>::type, N> out;
 
 1107     for (std::size_t i = 0; i < N; ++i) {
 
 1108       out.data[i] = lhs.data[i] * rhs;
 
 1118   template<
typename T, 
typename U, std::size_t N>
 
 1121     for (std::size_t i = 0; i < N; ++i) {
 
 1132   template<
typename T, 
typename U, std::size_t N, 
typename E = 
typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
 
 1135     Vector<
typename std::common_type<T,U>::type, N> out;
 
 1137     for (std::size_t i = 0; i < N; ++i) {
 
 1138       out.data[i] = lhs * rhs.data[i];
 
 1148   template<
typename T, 
typename U, std::size_t N>
 
 1151     Vector<
typename std::common_type<T,U>::type, N> out;
 
 1153     for (std::size_t i = 0; i < N; ++i) {
 
 1154       out.data[i] = lhs.data[i] / rhs.data[i];
 
 1164   template<
typename T, 
typename U, std::size_t N>
 
 1167     for (std::size_t i = 0; i < N; ++i) {
 
 1168       lhs.data[i] /= rhs.data[i];
 
 1178   template<
typename T, 
typename U, std::size_t N, 
typename E = 
typename std::enable_if<std::is_arithmetic<U>::value, U>::type>
 
 1181     Vector<
typename std::common_type<T,U>::type, N> out;
 
 1183     for (std::size_t i = 0; i < N; ++i) {
 
 1184       out.data[i] = lhs.data[i] / rhs;
 
 1194   template<
typename T, 
typename U, std::size_t N>
 
 1197     for (std::size_t i = 0; i < N; ++i) {
 
 1208   template<
typename T, 
typename U, std::size_t N, 
typename E = 
typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
 
 1211     Vector<
typename std::common_type<T,U>::type, N> out;
 
 1213     for (std::size_t i = 0; i < N; ++i) {
 
 1214       out.data[i] = lhs / rhs.data[i];
 
 1224   template<std::size_t N>
 
 1229     for (std::size_t i = 0; i < N; ++i) {
 
 1230       out.data[i] = lhs.data[i] || rhs.data[i];
 
 1240   template<std::size_t N>
 
 1245     for (std::size_t i = 0; i < N; ++i) {
 
 1246       out.data[i] = lhs.data[i] && rhs.data[i];
 
 1256   template<
typename T, std::size_t N>
 
 1261     for (std::size_t i = 0; i < N; ++i) {
 
 1262       out += lhs.data[i] * rhs.data[i];
 
 1272   template<
typename T, std::size_t N>
 
 1277     for (std::size_t i = 0; i < N; ++i) {
 
 1278       out.data[i] = std::min(lhs.data[i], rhs.data[i]);
 
 1288   template<
typename T, std::size_t N>
 
 1293     for (std::size_t i = 0; i < N; ++i) {
 
 1294       out.data[i] = std::max(lhs.data[i], rhs.data[i]);
 
 1304   template<
typename T, std::size_t N>
 
 1309     for (std::size_t i = 0; i < N; ++i) {
 
 1310       out.data[i] = std::abs(val.data[i]);
 
 1321   template<
typename T, std::size_t N>
 
 1326     for (std::size_t i = 0; i < N; ++i) {
 
 1327       out.data[i] = (lhs.data[i] == rhs.data[i]);
 
 1337   template<
typename T, std::size_t N>
 
 1342     for (std::size_t i = 0; i < N; ++i) {
 
 1343       out.data[i] = (lhs.data[i] < rhs.data[i]);
 
 1353   template<
typename T, std::size_t N>
 
 1358     for (std::size_t i = 0; i < N; ++i) {
 
 1359       out.data[i] = (lhs.data[i] > rhs.data[i]);
 
 1369   template<
typename T, std::size_t N>
 
 1374     for (std::size_t i = 0; i < N; ++i) {
 
 1375       out.data[i] = (cond.data[i] ? lhs.data[i] : rhs.data[i]);
 
 1388   template<
typename T, std::size_t N>
 
 1393     for (std::size_t i = 0; i < N; ++i) {
 
 1394       out.data[i] = clamp(val.data[i], lo.data[i], hi.data[i]);
 
 1406   template<
typename T, std::size_t N>
 
 1411     for (std::size_t i = 0; i < N; ++i) {
 
 1412       out.data[i] = clamp(val.data[i], lo, hi);
 
 1422   template<
typename T, 
typename U, std::size_t N>
 
 1425     return t * lhs + (1 - t) * rhs;
 
 1443   template<
typename T, std::size_t N>
 
 1448     for (std::size_t i = 0; i < N; ++i) {
 
 1449       out += std::abs(vec.data[i]);
 
 1468   template<
typename T, std::size_t N>
 
 1473     for (std::size_t i = 0; i < N; ++i) {
 
 1474       out += square(vec.data[i]);
 
 1495   template<
typename T, std::size_t N>
 
 1498     return std::sqrt(squareLength(vec));
 
 1516   template<
typename T, std::size_t N>
 
 1519     T out = std::abs(vec.data[0]);
 
 1521     for (std::size_t i = 1; i < N; ++i) {
 
 1522       out = std::max(out, std::abs(vec.data[i]));
 
 1542   template<
typename T, std::size_t N>
 
 1545     return manhattanLength(lhs - rhs);
 
 1561   template<
typename T, std::size_t N>
 
 1564     return squareLength(lhs - rhs);
 
 1580   template<
typename T, std::size_t N>
 
 1583     return euclideanLength(lhs - rhs);
 
 1599   template<
typename T, std::size_t N>
 
 1602     return chebyshevDistance(lhs - rhs);
 
 1616   template<
typename T, std::size_t N>
 
 1619     T length = euclideanLength(vec);
 
 1620     return vec / length;
 
 1630   template<
typename T>
 
 1633     return { std::cos(angle), std::sin(angle) };
 
 1643   template<
typename T>
 
 1646     return { -vec.y, vec.x };
 
 1657   template<
typename T>
 
 1661       lhs.y * rhs.z - lhs.z * rhs.y,
 
 1662       lhs.z * rhs.x - lhs.x * rhs.z,
 
 1663       lhs.x * rhs.y - lhs.y * rhs.x
 
 1667 #ifndef DOXYGEN_SHOULD_SKIP_THIS 
Vector< std::size_t, 3 > Vector3z
A std::size_t vector with 3 components. 
Definition: Vector.h:819
Vector(T *array)
Constructor that takes an array. 
Definition: Vector.h:458
Vector< unsigned, 2 > Vector2u
A unsigned vector with 2 components. 
Definition: Vector.h:795
T manhattanLength(const Vector< T, N > &vec)
Manhattan length of a vector. 
Definition: Vector.h:1445
Vector(T val)
Constructor that fills the vector with a value. 
Definition: Vector.h:441
T dot(const Vector< T, N > &lhs, const Vector< T, N > &rhs)
Scalar product. 
Definition: Vector.h:1258
T & operator[](std::size_t i)
Access to the -th coordinate. 
Definition: Vector.h:539
Vector< T, N > abs(const Vector< T, N > &val)
Component-wise absolute value. 
Definition: Vector.h:1306
Vector< typename std::common_type< T, U >::type, N > operator/(T lhs, const Vector< U, N > &rhs)
Left scalar division. 
Definition: Vector.h:1210
Vector< T, N > select(const Vector< bool, N > &cond, const Vector< T, N > &lhs, const Vector< T, N > &rhs)
Component-wise selection operator. 
Definition: Vector.h:1371
constexpr Vector< T, 2 > perp(const Vector< T, 2 > &vec)
Perpendicular vector. 
Definition: Vector.h:1645
Vector< float, 2 > Vector2f
A float vector with 2 components. 
Definition: Vector.h:741
bool operator==(const Vector< T, N > &lhs, const Vector< T, N > &rhs)
Equality operator between two vectors. 
Definition: Vector.h:905
Vector< typename std::common_type< T, U >::type, N > operator+(T lhs, const Vector< U, N > &rhs)
Left scalar addition. 
Definition: Vector.h:993
T squareLength(const Vector< T, N > &vec)
Square Euclidean length of a vector. 
Definition: Vector.h:1470
Vector< T, N > & operator/=(Vector< T, N > &lhs, const Vector< U, N > &rhs)
Component-wise division and assignment. 
Definition: Vector.h:1166
Vector< T, N > clamp(const Vector< T, N > &val, T lo, T hi)
Component-wise clamp function. 
Definition: Vector.h:1408
T euclideanLength(const Vector< T, N > &vec)
Euclidean length of a vector. 
Definition: Vector.h:1497
Vector< T, N > max(const Vector< T, N > &lhs, const Vector< T, N > &rhs)
Component-wise maximum. 
Definition: Vector.h:1290
Vector< int, 2 > Vector2i
A int vector with 2 components. 
Definition: Vector.h:777
Vector< bool, N > greaterThan(const Vector< T, N > &lhs, const Vector< T, N > &rhs)
Component-wise comparison operator. 
Definition: Vector.h:1355
Vector< T, N > & operator/=(Vector< T, N > &lhs, U rhs)
Right scalar division and assignment. 
Definition: Vector.h:1196
Vector< bool, N > equals(const Vector< T, N > &lhs, const Vector< T, N > &rhs)
Component-wise equality operator. 
Definition: Vector.h:1323
constexpr Vector(T x, T y)
Constructor that takes 2 components. 
Definition: Vector.h:293
Vector< typename std::common_type< T, U >::type, N > operator+(const Vector< T, N > &lhs, const Vector< U, N > &rhs)
Component-wise addition. 
Definition: Vector.h:947
friend class RenderTarget
Definition: Shader.h:387
Vector< unsigned, 4 > Vector4u
A unsigned vector with 4 components. 
Definition: Vector.h:807
Vector< typename std::common_type< T, U >::type, N > operator*(const Vector< T, N > &lhs, const Vector< U, N > &rhs)
Component-wise multiplication. 
Definition: Vector.h:1074
Vector< typename std::common_type< T, U >::type, N > operator/(const Vector< T, N > &lhs, U rhs)
Right scalar division. 
Definition: Vector.h:1180
Vector< T, N > & operator+=(Vector< T, N > &lhs, const Vector< U, N > &rhs)
Component-wise addition and assignment. 
Definition: Vector.h:963
Vector< bool, 2 > Vector2b
A bool vector with 2 components. 
Definition: Vector.h:831
Vector()=default
Default constructor. 
T chebyshevLength(const Vector< T, N > &vec)
Chebyshev length of a vector. 
Definition: Vector.h:1518
Vector< bool, N > operator&&(const Vector< bool, N > &lhs, const Vector< bool, N > &rhs)
Component-wise logical and operator. 
Definition: Vector.h:1242
T & operator[](std::size_t i)
Access to the -th coordinate. 
Definition: Vector.h:710
Vector< bool, N > lessThan(const Vector< T, N > &lhs, const Vector< T, N > &rhs)
Component-wise comparison operator. 
Definition: Vector.h:1339
Vector< bool, 3 > Vector3b
A bool vector with 3 components. 
Definition: Vector.h:837
constexpr Vector(T x, T y, T z)
Constructor that takes 3 components. 
Definition: Vector.h:470
T data[N]
The internal representation of the vector. 
Definition: Vector.h:196
Vector< int, 4 > Vector4i
A int vector with 4 components. 
Definition: Vector.h:789
Vector< T, N > operator-(const Vector< T, N > &val)
Component-wise unary minus. 
Definition: Vector.h:931
Vector< typename std::common_type< T, U >::type, N > operator-(T lhs, const Vector< U, N > &rhs)
Left scalar substraction. 
Definition: Vector.h:1057
Vector< bool, 4 > Vector4b
A bool vector with 4 components. 
Definition: Vector.h:843
Vector< typename std::common_type< T, U >::type, N > lerp(const Vector< T, N > &lhs, const Vector< T, N > &rhs, U t)
Component-wise lerp function. 
Definition: Vector.h:1424
Vector< double, 3 > Vector3d
A double vector with 3 components. 
Definition: Vector.h:765
constexpr Vector(T x, T y, T z, T w)
Constructor that takes 4 components. 
Definition: Vector.h:652
T chebyshevDistance(const Vector< T, N > &lhs, const Vector< T, N > &rhs)
Chebyshev distance between two vectors. 
Definition: Vector.h:1601
Vector< uint8_t, 3 > Color3u
A uint8_t color vector with 3 components. 
Definition: Vector.h:861
T squareDistance(const Vector< T, N > &lhs, const Vector< T, N > &rhs)
Square Euclidean distance between two vectors. 
Definition: Vector.h:1563
Vector< std::size_t, 4 > Vector4z
A std::size_t vector with 4 components. 
Definition: Vector.h:825
Vector< T, 2 > unit(T angle)
Unit vector in a specified direction. 
Definition: Vector.h:1632
Vector< unsigned, 3 > Vector3u
A unsigned vector with 3 components. 
Definition: Vector.h:801
T & operator[](std::size_t i)
Access to the -th coordinate. 
Definition: Vector.h:185
Vector< typename std::common_type< T, U >::type, N > operator/(const Vector< T, N > &lhs, const Vector< U, N > &rhs)
Component-wise division. 
Definition: Vector.h:1150
Vector< T, N > clamp(const Vector< T, N > &val, const Vector< T, N > &lo, const Vector< T, N > &hi)
Component-wise clamp function. 
Definition: Vector.h:1390
Vector< typename std::common_type< T, U >::type, N > operator-(const Vector< T, N > &lhs, const Vector< U, N > &rhs)
Component-wise substraction. 
Definition: Vector.h:1010
Vector & operator=(const Vector &other)=default
Default copy assignment. 
Vector(const Vector &other)=default
Default copy constructor. 
T operator[](std::size_t i) const 
Access to the -th coordinate. 
Definition: Vector.h:524
T euclideanDistance(const Vector< T, N > &lhs, const Vector< T, N > &rhs)
Euclidean distance between two vectors. 
Definition: Vector.h:1582
T operator[](std::size_t i) const 
Access to the -th coordinate. 
Definition: Vector.h:695
Vector< bool, N > operator||(const Vector< bool, N > &lhs, const Vector< bool, N > &rhs)
Component-wise logical or operator. 
Definition: Vector.h:1226
Vector()=default
Default constructor. 
T operator[](std::size_t i) const 
Access to the -th coordinate. 
Definition: Vector.h:334
Vector< uint8_t, 4 > Color4u
A uint8_t color vector with 4 components. 
Definition: Vector.h:867
T & operator[](std::size_t i)
Access to the -th coordinate. 
Definition: Vector.h:349
Vector< typename std::common_type< T, U >::type, N > operator-(const Vector< T, N > &lhs, U rhs)
Right scalar substraction. 
Definition: Vector.h:1041
Vector< int, 3 > Vector3i
A int vector with 3 components. 
Definition: Vector.h:783
Vector(T *array)
Constructor that takes an array. 
Definition: Vector.h:639
constexpr Vector(Vector< T, 2 > xy, T z)
Constructor that takes a 2D vector and a z component. 
Definition: Vector.h:482
bool operator!=(const Vector< T, N > &lhs, const Vector< T, N > &rhs)
Inequality operator between two vectors. 
Definition: Vector.h:921
Vector(T *array)
Constructor that takes an array. 
Definition: Vector.h:282
Vector< float, 3 > Color3f
A float color vector with 3 components. 
Definition: Vector.h:849
Vector< T, N > normalize(const Vector< T, N > &vec)
Normalize a vector. 
Definition: Vector.h:1618
Vector(const Vector &other)=default
Default copy constructor. 
Vector(const Vector< U, 3 > &other)
Converting copy constructor. 
Definition: Vector.h:505
Vector< T, N > min(const Vector< T, N > &lhs, const Vector< T, N > &rhs)
Component-wise minimum. 
Definition: Vector.h:1274
Vector< T, N > & operator*=(Vector< T, N > &lhs, const Vector< U, N > &rhs)
Component-wise multiplication and assignment. 
Definition: Vector.h:1090
Vector< typename std::common_type< T, U >::type, N > operator*(const Vector< T, N > &lhs, U rhs)
Right scalar multiplication. 
Definition: Vector.h:1104
Vector()=default
Default constructor. 
Vector(const Vector &other)=default
Default copy constructor. 
Vector< float, 4 > Color4f
A float color vector with 4 components. 
Definition: Vector.h:855
Vector< T, N > & operator*=(Vector< T, N > &lhs, U rhs)
Right scalar multiplication and assignment. 
Definition: Vector.h:1120
Vector< std::size_t, 2 > Vector2z
A std::size_t vector with 2 components. 
Definition: Vector.h:813
Vector(const Vector< U, 4 > &other)
Converting copy constructor. 
Definition: Vector.h:675
Vector< float, 4 > Vector4f
A float vector with 4 components. 
Definition: Vector.h:753
T manhattanDistance(const Vector< T, N > &lhs, const Vector< T, N > &rhs)
Manhattan distance between two vectors. 
Definition: Vector.h:1544
T operator[](std::size_t i) const 
Access to the -th coordinate. 
Definition: Vector.h:170
Vector(const Vector< U, N > &other)
Converting copy constructor. 
Definition: Vector.h:145
Vector(const Vector &other)=default
Default copy constructor. 
Vector< double, 2 > Vector2d
A double vector with 2 components. 
Definition: Vector.h:759
#define GF_API
Definition: Portability.h:35
General purpose math vector. 
Definition: Vector.h:61
Vector< double, 4 > Vector4d
A double vector with 4 components. 
Definition: Vector.h:771
Vector(T val)
Constructor that fills the vector with a value. 
Definition: Vector.h:87
Vector(std::initializer_list< T > list)
Constructor that takes an initializer list. 
Definition: Vector.h:123
Vector< float, 3 > Vector3f
A float vector with 3 components. 
Definition: Vector.h:747
constexpr Vector< T, 3 > cross(const Vector< T, 3 > &lhs, const Vector< T, 3 > &rhs)
Cross product. 
Definition: Vector.h:1659
Vector< typename std::common_type< T, U >::type, N > operator+(const Vector< T, N > &lhs, U rhs)
Right scalar addition. 
Definition: Vector.h:977
Vector< T, N > & operator-=(Vector< T, N > &lhs, const Vector< U, N > &rhs)
Component-wise substraction and assignment. 
Definition: Vector.h:1026
Vector(const Vector< U, 2 > &other)
Converting copy constructor. 
Definition: Vector.h:316
Vector< typename std::common_type< T, U >::type, N > operator*(T lhs, const Vector< U, N > &rhs)
Left scalar multiplication. 
Definition: Vector.h:1134
Vector(T val)
Constructor that fills the vector with a value. 
Definition: Vector.h:265
Vector()=default
Default constructor. 
Vector(T *array)
Constructor that takes an array. 
Definition: Vector.h:105
Vector(T val)
Constructor that fills the vector with a value. 
Definition: Vector.h:622