28 #include <initializer_list> 29 #include <type_traits> 31 #include "Portability.h" 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>
404 : x(static_cast<T>(other.x))
405 , y(static_cast<T>(other.y))
407 static_assert(std::is_convertible<U,T>::value,
"Non-convertible types");
422 const T *data[] = { &x, &y };
438 T *data[] = { &x, &y };
501 constexpr
void zero() noexcept {
564 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");
690 const T *data[] = { &x, &y, &z };
706 T *data[] = { &x, &y, &z };
770 constexpr
void zero() noexcept {
844 template <
typename T>
914 constexpr
Vector(
T first,
T second,
T third,
T fourth) noexcept
941 : x(static_cast<T>(other.x))
942 , y(static_cast<T>(other.y))
943 , z(static_cast<T>(other.z))
944 , w(static_cast<T>(other.w))
946 static_assert(std::is_convertible<U,T>::value,
"Non-convertible types");
961 const T *data[] = { &x, &y, &z, &w };
977 T *data[] = { &x, &y, &z, &w };
1042 x = y = z = w =
T{};
1320 template<
typename T, std::
size_t N>
1329 template<
typename T>
1338 template<
typename T>
1341 #ifndef DOXYGEN_SHOULD_SKIP_THIS 1346 #endif // GAME_VECTOR_H
constexpr Vector(T first, T second, T third) noexcept
Constructor that takes 3 components.
Definition: Vector.h:631
T x
First coordinate in the (x,y) representation.
Definition: Vector.h:509
T g
Second coordinate in the (r,g,b) representation.
Definition: Vector.h:795
constexpr Vector< T, 3 > xyz() const
Swizzle to get the first three coordinates as a 3D vector.
Definition: Vector.h:1055
const T * cbegin() const
Iterator.on the first element (const version).
Definition: Vector.h:1024
const T * cend() const
Iterator on the element after the last one (const version).
Definition: Vector.h:1034
constexpr Vector(ZeroType) noexcept
Constructor that zero the vector out.
Definition: Vector.h:577
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:437
constexpr T & operator[](std::size_t i)
Access to the -th coordinate.
Definition: Vector.h:705
const T * end() const
Iterator on the element after the last one (const version).
Definition: Vector.h:744
Distance< T, 2 > Distance2
A distance function for 2D vectors.
Definition: Vector.h:1330
constexpr Vector2f transform(const Matrix3f &mat, Vector2f point)
Apply an affine transformation to a 2D point.
Definition: Transform.h:331
T z
Third coordinate in the (x,y,z,w) representation.
Definition: Vector.h:1087
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:763
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:960
constexpr Vector< T, 2 > xy() const
Swizzle to get the first two coordinates as a 2D vector.
Definition: Vector.h:1048
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:1096
T * begin()
Iterator.to the first element.
Definition: Vector.h:716
constexpr T operator[](std::size_t i) const
Access to the -th coordinate.
Definition: Vector.h:421
T v
Second coordinate in the (u,v) representation.
Definition: Vector.h:521
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
const T * begin() const
Iterator.to the first element (const version).
Definition: Vector.h:466
T width
First coordinate in the size representation.
Definition: Vector.h:512
const T * end() const
Iterator on the element after the last one (const version).
Definition: Vector.h:1015
T s
First coordinate in the (s,t) representation.
Definition: Vector.h:511
constexpr Vector(const T *array)
Constructor that takes an array.
Definition: Vector.h:616
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:857
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:494
T height
Second coordinate in the size representation.
Definition: Vector.h:523
T * end()
Iterator to the element after the last one.
Definition: Vector.h:725
constexpr Vector(T val) noexcept
Constructor that fills the vector with a value.
Definition: Vector.h:595
const T * end() const
Iterator on the element after the last one (const version).
Definition: Vector.h:476
constexpr void zero() noexcept
Zero out the vector.
Definition: Vector.h:501
Distance< T, 3 > Distance3
A distance function for 3D vectors.
Definition: Vector.h:1339
The namespace for gf classes.
Definition: Action.h:34
T g
Second coordinate in the (r,g,b,a) representation.
Definition: Vector.h:1080
T x
First coordinate in the (x,y,z,w) representation.
Definition: Vector.h:1071
constexpr Vector(Vector< T, 2 > xy, T third)
Constructor that takes a 2D vector and a z component.
Definition: Vector.h:645
constexpr void zero() noexcept
Zero out the vector.
Definition: Vector.h:1041
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:787
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:484
constexpr Vector(const T *array)
Constructor that takes an array.
Definition: Vector.h:897
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:1088
T col
First coordinate in the indices representation.
Definition: Vector.h:513
const T * cbegin() const
Iterator.on the first element (const version).
Definition: Vector.h:753
const T * begin() const
Iterator.to the first element (const version).
Definition: Vector.h:1005
T * end()
Iterator to the element after the last one.
Definition: Vector.h:996
A 2D vector.
Definition: Vector.h:316
T y
Second coordinate in the (x,y,z) representation.
Definition: Vector.h:794
constexpr Vector(T val) noexcept
Constructor that fills the vector with a value.
Definition: Vector.h:346
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:770
T y
Second coordinate in the (x,y,z,w) representation.
Definition: Vector.h:1079
T u
First coordinate in the (u,v) representation.
Definition: Vector.h:510
T b
Third coordinate in the (r,g,b) representation.
Definition: Vector.h:803
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:689
constexpr Vector< T, 3 > rgb() const
Swizzle to get the first three coordinates as a RGB color.
Definition: Vector.h:1062
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:448
A 3D vector.
Definition: Vector.h:565
T r
First coordinate in the (r,g,b,a) representation.
Definition: Vector.h:1072
General purpose math vector.
Definition: Vector.h:61
T w
Fourth coordinate in the (x,y,z,w) representation.
Definition: Vector.h:1095
const T * begin() const
Iterator.to the first element (const version).
Definition: Vector.h:734
T z
Third coordinate in the (x,y,z) representation.
Definition: Vector.h:802
Vector(const Vector< U, 2 > &other) noexcept
Converting copy constructor.
Definition: Vector.h:403
T(*)(Vector< T, N >, Vector< T, N >) Distance
A distance function.
Definition: Vector.h:1321
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:940
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:914
T t
Second coordinate in the (s,t) representation.
Definition: Vector.h:522
constexpr Vector< T, 2 > xy() const
Swizzle to get the first two coordinates as a 2D vector.
Definition: Vector.h:777
T * begin()
Iterator.to the first element.
Definition: Vector.h:987
T row
Second coordinate in the indices representation.
Definition: Vector.h:524
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:875
constexpr T & operator[](std::size_t i)
Access to the -th coordinate.
Definition: Vector.h:976
T * end()
Iterator to the element after the last one.
Definition: Vector.h:457
constexpr Vector(T first, T second) noexcept
Constructor that takes 2 components.
Definition: Vector.h:379
Semantic type to represent "zero".
Definition: Types.h:69