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");
97 std::fill_n(data,
N, val);
115 std::copy_n(array,
N, data);
131 Vector(std::initializer_list<T> list) noexcept
133 std::copy_n(list.begin(), std::min(list.size(),
N), data);
155 static_assert(std::is_convertible<U,T>::value,
"Non-convertible types");
257 constexpr
void zero() noexcept {
258 for (std::size_t i = 0; i <
N; ++i) {
315 template <
typename T>
401 : x(static_cast<T>(other.x))
402 , y(static_cast<T>(other.y))
404 static_assert(std::is_convertible<U,T>::value,
"Non-convertible types");
427 const T *data[] = { &x, &y };
443 T *data[] = { &x, &y };
506 constexpr
void zero() noexcept {
569 template <
typename T>
671 : x(static_cast<T>(other.x))
672 , y(static_cast<T>(other.y))
673 , z(static_cast<T>(other.z))
675 static_assert(std::is_convertible<U,T>::value,
"Non-convertible types");
698 const T *data[] = { &x, &y, &z };
714 T *data[] = { &x, &y, &z };
778 constexpr
void zero() noexcept {
851 template <
typename T>
919 constexpr
Vector(
T first,
T second,
T third,
T fourth) noexcept
944 : x(static_cast<T>(other.x))
945 , y(static_cast<T>(other.y))
946 , z(static_cast<T>(other.z))
947 , w(static_cast<T>(other.w))
949 static_assert(std::is_convertible<U,T>::value,
"Non-convertible types");
972 const T *data[] = { &x, &y, &z, &w };
988 T *data[] = { &x, &y, &z, &w };
1053 x = y = z = w =
T{};
1261 template<
typename T>
1270 template<
typename T>
1366 template<
typename T, std::
size_t N>
1375 template<
typename T>
1384 template<
typename T>
1392 template<
typename T, std::
size_t N>
1395 std::swap_ranges(lhs.begin(), lhs.end(), rhs.begin());
1405 template<
typename ... Types>
1407 auto vec(Types... values) ->
Vector<std::common_type_t<Types...>,
sizeof...(Types)> {
1408 static_assert(
sizeof...(Types) > 0,
"Vectors must have at least one coordinate");
1409 return {
static_cast<std::common_type_t<Types...
>>(values)... };
1412 #ifndef DOXYGEN_SHOULD_SKIP_THIS 1417 #endif // GAME_VECTOR_H constexpr Vector(T first, T second, T third) noexcept
Constructor that takes 3 components.
Definition: Vector.h:634
T x
First coordinate in the (x,y) representation.
Definition: Vector.h:514
T g
Second coordinate in the (r,g,b) representation.
Definition: Vector.h:803
constexpr Vector< T, 3 > xyz() const
Swizzle to get the first three coordinates as a 3D vector.
Definition: Vector.h:1066
const T * cbegin() const
Iterator.on the first element (const version).
Definition: Vector.h:1035
const T * cend() const
Iterator on the element after the last one (const version).
Definition: Vector.h:1045
constexpr Vector(ZeroType) noexcept
Constructor that zero the vector out.
Definition: Vector.h:582
Vector(const Vector< U, 3 > &other) noexcept
Converting copy constructor.
Definition: Vector.h:670
constexpr T & operator[](std::size_t i)
Access to the -th coordinate.
Definition: Vector.h:442
constexpr T & operator[](std::size_t i)
Access to the -th coordinate.
Definition: Vector.h:713
const T * end() const
Iterator on the element after the last one (const version).
Definition: Vector.h:752
T z
Third coordinate in the (x,y,z,w) representation.
Definition: Vector.h:1098
T * end()
Iterator to the element after the last one.
Definition: Vector.h:212
constexpr T operator[](std::size_t i) const
Access to the -th coordinate.
Definition: Vector.h:178
const T * cend() const
Iterator on the element after the last one (const version).
Definition: Vector.h:771
constexpr Vector(ZeroType) noexcept
Constructor that zero the vector out.
Definition: Vector.h:328
constexpr T operator[](std::size_t i) const
Access to the -th coordinate.
Definition: Vector.h:971
constexpr Vector< T, 2 > xy() const
Swizzle to get the first two coordinates as a 2D vector.
Definition: Vector.h:1059
constexpr Vector(ZeroType) noexcept
Constructor that zero the vector out.
Definition: Vector.h:77
T * begin()
Iterator.to the first element.
Definition: Vector.h:203
T a
Fourth coordinate in the (r,g,b,a) representation.
Definition: Vector.h:1107
T * begin()
Iterator.to the first element.
Definition: Vector.h:724
constexpr T operator[](std::size_t i) const
Access to the -th coordinate.
Definition: Vector.h:426
T v
Second coordinate in the (u,v) representation.
Definition: Vector.h:526
T y
Second coordinate in the (x,y) representation.
Definition: Vector.h:525
T x
First coordinate in the (x,y,z) representation.
Definition: Vector.h:794
const T * begin() const
Iterator.to the first element (const version).
Definition: Vector.h:471
T width
First coordinate in the size representation.
Definition: Vector.h:517
const T * end() const
Iterator on the element after the last one (const version).
Definition: Vector.h:1026
T s
First coordinate in the (s,t) representation.
Definition: Vector.h:516
constexpr Vector(const T *array)
Constructor that takes an array.
Definition: Vector.h:620
Vector(const Vector< U, N > &other) noexcept
Converting copy constructor.
Definition: Vector.h:153
constexpr Vector(ZeroType) noexcept
Constructor that zero the vector out.
Definition: Vector.h:864
T data[N]
The internal representation of the vector.
Definition: Vector.h:270
const T * cend() const
Iterator on the element after the last one (const version).
Definition: Vector.h:499
T height
Second coordinate in the size representation.
Definition: Vector.h:528
T * end()
Iterator to the element after the last one.
Definition: Vector.h:733
constexpr Vector(T val) noexcept
Constructor that fills the vector with a value.
Definition: Vector.h:600
const T * end() const
Iterator on the element after the last one (const version).
Definition: Vector.h:481
constexpr void zero() noexcept
Zero out the vector.
Definition: Vector.h:506
T(*)(Vector< T, N >, Vector< T, N >) Distance
A distance function.
Definition: Vector.h:1367
constexpr Vector2f transform(const Matrix3f &mat, Vector2f point)
Apply an affine transformation to a 2D point.
Definition: Transform.h:326
The namespace for gf classes.
Definition: Action.h:35
T g
Second coordinate in the (r,g,b,a) representation.
Definition: Vector.h:1091
T x
First coordinate in the (x,y,z,w) representation.
Definition: Vector.h:1082
constexpr Vector(Vector< T, 2 > xy, T third)
Constructor that takes a 2D vector and a z component.
Definition: Vector.h:647
constexpr auto vec(Types... values) -> Vector< std::common_type_t< Types... >, sizeof...(Types)>
Universal vector factory.
Definition: Vector.h:1407
constexpr void zero() noexcept
Zero out the vector.
Definition: Vector.h:1052
A 4D vector.
Definition: Vector.h:852
Vector(const T *array)
Constructor that takes an array.
Definition: Vector.h:113
T r
First coordinate in the (r,g,b) representation.
Definition: Vector.h:795
Vector(T val) noexcept
Constructor that fills the vector with a value.
Definition: Vector.h:95
const T * cend() const
Iterator on the element after the last one (const version).
Definition: Vector.h:250
const T * cbegin() const
Iterator.on the first element (const version).
Definition: Vector.h:489
constexpr Vector(const T *array)
Constructor that takes an array.
Definition: Vector.h:903
constexpr void zero() noexcept
Zero out the vector.
Definition: Vector.h:257
T b
Third coordinate in the (r,g,b,a) representation.
Definition: Vector.h:1099
void swap(Vector< T, N > &lhs, Vector< T, N > &rhs) noexcept
Swap two vectors.
Definition: Vector.h:1394
T col
First coordinate in the indices representation.
Definition: Vector.h:518
const T * cbegin() const
Iterator.on the first element (const version).
Definition: Vector.h:761
const T * begin() const
Iterator.to the first element (const version).
Definition: Vector.h:1016
T * end()
Iterator to the element after the last one.
Definition: Vector.h:1007
A 2D vector.
Definition: Vector.h:316
T y
Second coordinate in the (x,y,z) representation.
Definition: Vector.h:802
constexpr Vector(T val) noexcept
Constructor that fills the vector with a value.
Definition: Vector.h:347
const T * end() const
Iterator on the element after the last one (const version).
Definition: Vector.h:231
constexpr void zero() noexcept
Zero out the vector.
Definition: Vector.h:778
T y
Second coordinate in the (x,y,z,w) representation.
Definition: Vector.h:1090
T u
First coordinate in the (u,v) representation.
Definition: Vector.h:515
T b
Third coordinate in the (r,g,b) representation.
Definition: Vector.h:811
constexpr T & operator[](std::size_t i)
Access to the -th coordinate.
Definition: Vector.h:193
constexpr T operator[](std::size_t i) const
Access to the -th coordinate.
Definition: Vector.h:697
constexpr Vector< T, 3 > rgb() const
Swizzle to get the first three coordinates as a RGB color.
Definition: Vector.h:1073
const T * cbegin() const
Iterator.on the first element (const version).
Definition: Vector.h:240
T * begin()
Iterator.to the first element.
Definition: Vector.h:453
A 3D vector.
Definition: Vector.h:570
T r
First coordinate in the (r,g,b,a) representation.
Definition: Vector.h:1083
General purpose math vector.
Definition: Vector.h:61
T w
Fourth coordinate in the (x,y,z,w) representation.
Definition: Vector.h:1106
const T * begin() const
Iterator.to the first element (const version).
Definition: Vector.h:742
T z
Third coordinate in the (x,y,z) representation.
Definition: Vector.h:810
Vector(const Vector< U, 2 > &other) noexcept
Converting copy constructor.
Definition: Vector.h:400
const T * begin() const
Iterator.to the first element (const version).
Definition: Vector.h:221
Vector(const Vector< U, 4 > &other) noexcept
Converting copy constructor.
Definition: Vector.h:943
constexpr Vector(const T *array)
Constructor that takes an array.
Definition: Vector.h:366
constexpr Vector(T first, T second, T third, T fourth) noexcept
Constructor that takes 4 components.
Definition: Vector.h:919
T t
Second coordinate in the (s,t) representation.
Definition: Vector.h:527
constexpr Vector< T, 2 > xy() const
Swizzle to get the first two coordinates as a 2D vector.
Definition: Vector.h:785
T * begin()
Iterator.to the first element.
Definition: Vector.h:998
T row
Second coordinate in the indices representation.
Definition: Vector.h:529
Vector(std::initializer_list< T > list) noexcept
Constructor that takes an initializer list.
Definition: Vector.h:131
constexpr Vector(T val) noexcept
Constructor that fills the vector with a value.
Definition: Vector.h:882
Distance< T, 3 > Distance3
A distance function for 3D vectors.
Definition: Vector.h:1385
Distance< T, 2 > Distance2
A distance function for 2D vectors.
Definition: Vector.h:1376
constexpr T & operator[](std::size_t i)
Access to the -th coordinate.
Definition: Vector.h:987
T * end()
Iterator to the element after the last one.
Definition: Vector.h:462
constexpr Vector(T first, T second) noexcept
Constructor that takes 2 components.
Definition: Vector.h:378
Semantic type to represent "zero".
Definition: Types.h:85