28#include <initializer_list>
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");
156 std::transform(data, data +
N, other.data, [](
U val) { return static_cast<T>(val); });
257 constexpr void zero() noexcept {
258 for (std::size_t i = 0; i <
N; ++i) {
315 template <
typename T>
347 explicit constexpr Vector(T val) noexcept
366 explicit constexpr Vector(
const T *array)
378 constexpr Vector(T first, T second) noexcept
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>
600 explicit constexpr Vector(T val) noexcept
620 explicit constexpr Vector(
const T *array)
634 constexpr Vector(T first, T second, T third) noexcept
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>
882 explicit constexpr Vector(T val) noexcept
903 explicit constexpr Vector(
const T *array)
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
constexpr Vector2f transform(const Matrix3f &mat, Vector2f point)
Apply an affine transformation to a 2D point.
Definition: Transform.h:326
Distance< T, 2 > Distance2
A distance function for 2D vectors.
Definition: Vector.h:1376
Distance< T, 3 > Distance3
A distance function for 3D vectors.
Definition: Vector.h:1385
T(*)(Vector< T, N >, Vector< T, N >) Distance
A distance function.
Definition: Vector.h:1367
The namespace for gf classes.
A 2D vector.
Definition: Vector.h:316
const T * cbegin() const
Iterator.on the first element (const version).
Definition: Vector.h:489
constexpr T operator[](std::size_t i) const
Access to the -th coordinate.
Definition: Vector.h:426
T * end()
Iterator to the element after the last one.
Definition: Vector.h:462
T row
Second coordinate in the indices representation.
Definition: Vector.h:529
Vector()=default
Default constructor.
T * begin()
Iterator.to the first element.
Definition: Vector.h:453
T height
Second coordinate in the size representation.
Definition: Vector.h:528
constexpr Vector(const T *array)
Constructor that takes an array.
Definition: Vector.h:366
T s
First coordinate in the (s,t) representation.
Definition: Vector.h:516
const T * begin() const
Iterator.to the first element (const version).
Definition: Vector.h:471
T v
Second coordinate in the (u,v) representation.
Definition: Vector.h:526
constexpr Vector(T val) noexcept
Constructor that fills the vector with a value.
Definition: Vector.h:347
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:481
constexpr Vector(ZeroType) noexcept
Constructor that zero the vector out.
Definition: Vector.h:328
constexpr Vector(T first, T second) noexcept
Constructor that takes 2 components.
Definition: Vector.h:378
const T * cend() const
Iterator on the element after the last one (const version).
Definition: Vector.h:499
T t
Second coordinate in the (s,t) representation.
Definition: Vector.h:527
T y
Second coordinate in the (x,y) representation.
Definition: Vector.h:525
Vector & operator=(const Vector &other)=default
Default copy assignment.
Vector(const Vector< U, 2 > &other) noexcept
Converting copy constructor.
Definition: Vector.h:400
constexpr T & operator[](std::size_t i)
Access to the -th coordinate.
Definition: Vector.h:442
constexpr void zero() noexcept
Zero out the vector.
Definition: Vector.h:506
T col
First coordinate in the indices representation.
Definition: Vector.h:518
Vector(const Vector &other)=default
Default copy constructor.
T x
First coordinate in the (x,y) representation.
Definition: Vector.h:514
T u
First coordinate in the (u,v) representation.
Definition: Vector.h:515
A 3D vector.
Definition: Vector.h:570
const T * cbegin() const
Iterator.on the first element (const version).
Definition: Vector.h:761
T b
Third coordinate in the (r,g,b) representation.
Definition: Vector.h:811
constexpr Vector(const T *array)
Constructor that takes an array.
Definition: Vector.h:620
const T * cend() const
Iterator on the element after the last one (const version).
Definition: Vector.h:771
constexpr T & operator[](std::size_t i)
Access to the -th coordinate.
Definition: Vector.h:713
constexpr Vector< T, 2 > xy() const
Swizzle to get the first two coordinates as a 2D vector.
Definition: Vector.h:785
const T * begin() const
Iterator.to the first element (const version).
Definition: Vector.h:742
T x
First coordinate in the (x,y,z) representation.
Definition: Vector.h:794
Vector & operator=(const Vector &other)=default
Default copy assignment.
T * end()
Iterator to the element after the last one.
Definition: Vector.h:733
Vector(const Vector &other)=default
Default copy constructor.
const T * end() const
Iterator on the element after the last one (const version).
Definition: Vector.h:752
T r
First coordinate in the (r,g,b) representation.
Definition: Vector.h:795
constexpr void zero() noexcept
Zero out the vector.
Definition: Vector.h:778
Vector()=default
Default constructor.
T * begin()
Iterator.to the first element.
Definition: Vector.h:724
T z
Third coordinate in the (x,y,z) representation.
Definition: Vector.h:810
Vector(const Vector< U, 3 > &other) noexcept
Converting copy constructor.
Definition: Vector.h:670
constexpr Vector(ZeroType) noexcept
Constructor that zero the vector out.
Definition: Vector.h:582
constexpr Vector(Vector< T, 2 > xy, T third)
Constructor that takes a 2D vector and a z component.
Definition: Vector.h:647
constexpr Vector(T val) noexcept
Constructor that fills the vector with a value.
Definition: Vector.h:600
T y
Second coordinate in the (x,y,z) representation.
Definition: Vector.h:802
constexpr T operator[](std::size_t i) const
Access to the -th coordinate.
Definition: Vector.h:697
constexpr Vector(T first, T second, T third) noexcept
Constructor that takes 3 components.
Definition: Vector.h:634
T g
Second coordinate in the (r,g,b) representation.
Definition: Vector.h:803
A 4D vector.
Definition: Vector.h:852
constexpr Vector(const T *array)
Constructor that takes an array.
Definition: Vector.h:903
constexpr Vector(T first, T second, T third, T fourth) noexcept
Constructor that takes 4 components.
Definition: Vector.h:919
Vector(const Vector &other)=default
Default copy constructor.
Vector(const Vector< U, 4 > &other) noexcept
Converting copy constructor.
Definition: Vector.h:943
T z
Third coordinate in the (x,y,z,w) representation.
Definition: Vector.h:1098
Vector()=default
Default constructor.
const T * cbegin() const
Iterator.on the first element (const version).
Definition: Vector.h:1035
T w
Fourth coordinate in the (x,y,z,w) representation.
Definition: Vector.h:1106
T b
Third coordinate in the (r,g,b,a) representation.
Definition: Vector.h:1099
T y
Second coordinate in the (x,y,z,w) representation.
Definition: Vector.h:1090
constexpr Vector(ZeroType) noexcept
Constructor that zero the vector out.
Definition: Vector.h:864
T a
Fourth coordinate in the (r,g,b,a) representation.
Definition: Vector.h:1107
constexpr Vector(T val) noexcept
Constructor that fills the vector with a value.
Definition: Vector.h:882
constexpr Vector< T, 2 > xy() const
Swizzle to get the first two coordinates as a 2D vector.
Definition: Vector.h:1059
T x
First coordinate in the (x,y,z,w) representation.
Definition: Vector.h:1082
const T * begin() const
Iterator.to the first element (const version).
Definition: Vector.h:1016
T * begin()
Iterator.to the first element.
Definition: Vector.h:998
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:1007
const T * cend() const
Iterator on the element after the last one (const version).
Definition: Vector.h:1045
constexpr Vector< T, 3 > xyz() const
Swizzle to get the first three coordinates as a 3D vector.
Definition: Vector.h:1066
constexpr void zero() noexcept
Zero out the vector.
Definition: Vector.h:1052
const T * end() const
Iterator on the element after the last one (const version).
Definition: Vector.h:1026
Vector & operator=(const Vector &other)=default
Default copy assignment.
T g
Second coordinate in the (r,g,b,a) representation.
Definition: Vector.h:1091
constexpr Vector< T, 3 > rgb() const
Swizzle to get the first three coordinates as a RGB color.
Definition: Vector.h:1073
T r
First coordinate in the (r,g,b,a) representation.
Definition: Vector.h:1083
constexpr T operator[](std::size_t i) const
Access to the -th coordinate.
Definition: Vector.h:971
General purpose math vector.
Definition: Vector.h:61
Vector(const T *array)
Constructor that takes an array.
Definition: Vector.h:113
Vector()=default
Default constructor.
Vector & operator=(const Vector &other)=default
Default copy assignment.
void swap(Vector< T, N > &lhs, Vector< T, N > &rhs) noexcept
Swap two vectors.
Definition: Vector.h:1394
const T * begin() const
Iterator.to the first element (const version).
Definition: Vector.h:221
constexpr T operator[](std::size_t i) const
Access to the -th coordinate.
Definition: Vector.h:178
T * begin()
Iterator.to the first element.
Definition: Vector.h:203
constexpr auto vec(Types... values) -> Vector< std::common_type_t< Types... >, sizeof...(Types)>
Universal vector factory.
Definition: Vector.h:1407
constexpr Vector(ZeroType) noexcept
Constructor that zero the vector out.
Definition: Vector.h:77
const T * end() const
Iterator on the element after the last one (const version).
Definition: Vector.h:231
Vector(std::initializer_list< T > list) noexcept
Constructor that takes an initializer list.
Definition: Vector.h:131
constexpr void zero() noexcept
Zero out the vector.
Definition: Vector.h:257
T * end()
Iterator to the element after the last one.
Definition: Vector.h:212
constexpr T & operator[](std::size_t i)
Access to the -th coordinate.
Definition: Vector.h:193
Vector(T val) noexcept
Constructor that fills the vector with a value.
Definition: Vector.h:95
Vector(const Vector< U, N > &other) noexcept
Converting copy constructor.
Definition: Vector.h:153
const T * cbegin() const
Iterator.on the first element (const version).
Definition: Vector.h:240
const T * cend() const
Iterator on the element after the last one (const version).
Definition: Vector.h:250
Vector(const Vector &other)=default
Default copy constructor.
Semantic type to represent "zero".
Definition: Types.h:85