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>
402 : x(static_cast<T>(other.x))
403 , y(static_cast<T>(other.y))
405 static_assert(std::is_convertible<U,T>::value,
"Non-convertible types");
420 const T *data[] = { &x, &y };
436 T *data[] = { &x, &y };
499 constexpr
void zero() noexcept {
562 template <
typename T>
665 : x(static_cast<T>(other.x))
666 , y(static_cast<T>(other.y))
667 , z(static_cast<T>(other.z))
669 static_assert(std::is_convertible<U,T>::value,
"Non-convertible types");
684 const T *data[] = { &x, &y, &z };
700 T *data[] = { &x, &y, &z };
764 constexpr
void zero() noexcept {
837 template <
typename T>
905 constexpr
Vector(
T first,
T second,
T third,
T fourth) noexcept
931 : x(static_cast<T>(other.x))
932 , y(static_cast<T>(other.y))
933 , z(static_cast<T>(other.z))
934 , w(static_cast<T>(other.w))
936 static_assert(std::is_convertible<U,T>::value,
"Non-convertible types");
951 const T *data[] = { &x, &y, &z, &w };
967 T *data[] = { &x, &y, &z, &w };
1032 x = y = z = w =
T{};
1240 template<
typename T>
1249 template<
typename T>
1345 template<
typename T, std::
size_t N>
1354 template<
typename T>
1363 template<
typename T>
1371 template<
typename T, std::
size_t N>
1374 std::swap_ranges(lhs.begin(), lhs.end(), rhs.begin());
1384 template<
typename ... Types>
1386 auto vec(Types... values) ->
Vector<std::common_type_t<Types...>,
sizeof...(Types)> {
1387 static_assert(
sizeof...(Types) > 0,
"Vectors must have at least one coordinate");
1388 return {
static_cast<std::common_type_t<Types...
>>(values)... };
1391 #ifndef DOXYGEN_SHOULD_SKIP_THIS 1396 #endif // GAME_VECTOR_H
constexpr Vector(T first, T second, T third) noexcept
Constructor that takes 3 components.
Definition: Vector.h:627
T x
First coordinate in the (x,y) representation.
Definition: Vector.h:507
T g
Second coordinate in the (r,g,b) representation.
Definition: Vector.h:789
constexpr Vector< T, 3 > xyz() const
Swizzle to get the first three coordinates as a 3D vector.
Definition: Vector.h:1045
const T * cbegin() const
Iterator.on the first element (const version).
Definition: Vector.h:1014
const T * cend() const
Iterator on the element after the last one (const version).
Definition: Vector.h:1024
constexpr Vector(ZeroType) noexcept
Constructor that zero the vector out.
Definition: Vector.h:575
Vector(const Vector< U, 3 > &other) noexcept
Converting copy constructor.
Definition: Vector.h:664
constexpr T & operator[](std::size_t i)
Access to the -th coordinate.
Definition: Vector.h:435
constexpr T & operator[](std::size_t i)
Access to the -th coordinate.
Definition: Vector.h:699
const T * end() const
Iterator on the element after the last one (const version).
Definition: Vector.h:738
Distance< T, 2 > Distance2
A distance function for 2D vectors.
Definition: Vector.h:1355
constexpr Vector2f transform(const Matrix3f &mat, Vector2f point)
Apply an affine transformation to a 2D point.
Definition: Transform.h:323
T z
Third coordinate in the (x,y,z,w) representation.
Definition: Vector.h:1077
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:757
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:950
constexpr Vector< T, 2 > xy() const
Swizzle to get the first two coordinates as a 2D vector.
Definition: Vector.h:1038
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:1086
T * begin()
Iterator.to the first element.
Definition: Vector.h:710
constexpr T operator[](std::size_t i) const
Access to the -th coordinate.
Definition: Vector.h:419
T v
Second coordinate in the (u,v) representation.
Definition: Vector.h:519
T y
Second coordinate in the (x,y) representation.
Definition: Vector.h:518
T x
First coordinate in the (x,y,z) representation.
Definition: Vector.h:780
const T * begin() const
Iterator.to the first element (const version).
Definition: Vector.h:464
T width
First coordinate in the size representation.
Definition: Vector.h:510
const T * end() const
Iterator on the element after the last one (const version).
Definition: Vector.h:1005
T s
First coordinate in the (s,t) representation.
Definition: Vector.h:509
constexpr Vector(const T *array)
Constructor that takes an array.
Definition: Vector.h:613
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:850
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:492
T height
Second coordinate in the size representation.
Definition: Vector.h:521
T * end()
Iterator to the element after the last one.
Definition: Vector.h:719
constexpr Vector(T val) noexcept
Constructor that fills the vector with a value.
Definition: Vector.h:593
const T * end() const
Iterator on the element after the last one (const version).
Definition: Vector.h:474
constexpr void zero() noexcept
Zero out the vector.
Definition: Vector.h:499
Distance< T, 3 > Distance3
A distance function for 3D vectors.
Definition: Vector.h:1364
The namespace for gf classes.
Definition: Action.h:35
T g
Second coordinate in the (r,g,b,a) representation.
Definition: Vector.h:1070
T x
First coordinate in the (x,y,z,w) representation.
Definition: Vector.h:1061
constexpr Vector(Vector< T, 2 > xy, T third)
Constructor that takes a 2D vector and a z component.
Definition: Vector.h:640
constexpr auto vec(Types... values) -> Vector< std::common_type_t< Types... >, sizeof...(Types)>
Universal vector factory.
Definition: Vector.h:1386
constexpr void zero() noexcept
Zero out the vector.
Definition: Vector.h:1031
A 4D vector.
Definition: Vector.h:838
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:781
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:482
constexpr Vector(const T *array)
Constructor that takes an array.
Definition: Vector.h:889
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:1078
void swap(Vector< T, N > &lhs, Vector< T, N > &rhs) noexcept
Swap two vectors.
Definition: Vector.h:1373
T col
First coordinate in the indices representation.
Definition: Vector.h:511
const T * cbegin() const
Iterator.on the first element (const version).
Definition: Vector.h:747
const T * begin() const
Iterator.to the first element (const version).
Definition: Vector.h:995
T * end()
Iterator to the element after the last one.
Definition: Vector.h:986
A 2D vector.
Definition: Vector.h:316
T y
Second coordinate in the (x,y,z) representation.
Definition: Vector.h:788
constexpr ArrayRef< T > array(const T *data, std::size_t size)
Create a constant reference to an array.
Definition: ArrayRef.h:203
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:764
T y
Second coordinate in the (x,y,z,w) representation.
Definition: Vector.h:1069
T u
First coordinate in the (u,v) representation.
Definition: Vector.h:508
T b
Third coordinate in the (r,g,b) representation.
Definition: Vector.h:797
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:683
constexpr Vector< T, 3 > rgb() const
Swizzle to get the first three coordinates as a RGB color.
Definition: Vector.h:1052
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:446
A 3D vector.
Definition: Vector.h:563
T r
First coordinate in the (r,g,b,a) representation.
Definition: Vector.h:1062
General purpose math vector.
Definition: Vector.h:61
T w
Fourth coordinate in the (x,y,z,w) representation.
Definition: Vector.h:1085
const T * begin() const
Iterator.to the first element (const version).
Definition: Vector.h:728
T z
Third coordinate in the (x,y,z) representation.
Definition: Vector.h:796
Vector(const Vector< U, 2 > &other) noexcept
Converting copy constructor.
Definition: Vector.h:401
T(*)(Vector< T, N >, Vector< T, N >) Distance
A distance function.
Definition: Vector.h:1346
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:930
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:905
T t
Second coordinate in the (s,t) representation.
Definition: Vector.h:520
constexpr Vector< T, 2 > xy() const
Swizzle to get the first two coordinates as a 2D vector.
Definition: Vector.h:771
T * begin()
Iterator.to the first element.
Definition: Vector.h:977
T row
Second coordinate in the indices representation.
Definition: Vector.h:522
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:868
constexpr T & operator[](std::size_t i)
Access to the -th coordinate.
Definition: Vector.h:966
T * end()
Iterator to the element after the last one.
Definition: Vector.h:455
constexpr Vector(T first, T second) noexcept
Constructor that takes 2 components.
Definition: Vector.h:378
Semantic type to represent "zero".
Definition: Types.h:69