Go to the documentation of this file. 1 #ifndef EAGINE_MATH_TVEC_HPP
9 #define EAGINE_MATH_TVEC_HPP
11 #include "../all_are_same.hpp"
12 #include "../memory/flatten_fwd.hpp"
20 template <
typename T,
int N,
bool V>
21 struct tvec : vector<T, N, V> {
30 constexpr
tvec(T v) noexcept
38 tvec(
const T (&d)[N]) noexcept
44 typename = std::enable_if_t<
45 (
sizeof...(P) == N) && all_are_convertible_to<T, P...>::value>>
46 constexpr
tvec(P&&... p) noexcept
47 :
base{base::make(std::forward<P>(p)...)} {}
54 typename = std::enable_if_t<!std::is_same_v<P, T> || !(M == N)>>
59 template <
typename P,
int M,
bool W>
69 typename = std::enable_if_t<
70 (
sizeof...(R) > 1) && (M +
sizeof...(R) == N) &&
71 all_are_convertible_to<T, R...>::value>>
76 template <
typename P,
int M,
bool W>
85 template <
typename T,
int N,
bool V>
86 struct is_known_vector_type<math::tvec<T, N, V>> : std::is_scalar<T> {};
88 template <
typename T,
int N,
bool V>
89 struct canonical_compound_type<math::
tvec<T, N, V>>
90 : type_identity<std::remove_cv_t<T[N]>> {};
92 template <
typename T,
int N,
bool V>
93 struct compound_view_maker<math::
tvec<T, N, V>> {
94 auto operator()(
const math::vector<T, N, V>& v)
const noexcept {
95 return vect::view<T, N, V>::apply(v._v);
99 template <
typename T,
int N,
bool V>
100 struct flatten_traits<math::
tvec<T, N, V>, T> {
102 template <
typename Ps,
typename Ss>
103 static constexpr
auto required_size(
104 memory::basic_span<
const math::tvec<T, N, V>, Ps, Ss> src) noexcept
106 return src.size() * N;
109 template <
typename Pd,
typename Sd>
111 const math::tvec<T, N, V>& src,
112 memory::basic_span<T, Pd, Sd> dst) noexcept {
113 EAGINE_ASSERT(N <= dst.size());
114 _do_apply(src._v, dst, std::make_index_sequence<std::size_t(N)>{});
119 template <
typename Pd,
typename Sd, std::size_t... I>
120 static void _do_apply(
121 vect::data_t<T, N, V> src,
122 memory::basic_span<T, Pd, Sd> dst,
123 std::index_sequence<I...>) noexcept {
124 ((dst[I] = src[I]), ...);
130 #endif // EAGINE_MATH_TVEC_HPP
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
constexpr tvec(const vector< P, M, W > &v, T d) noexcept
Construction from vector of different dimensionality.
Definition: tvec.hpp:60
static constexpr auto from(const vector< P, M, W > &v, T d=T(0)) noexcept
Creates vector instance from vector of another dimension.
Definition: vector.hpp:111
Common code is placed in this namespace.
Definition: eagine.hpp:21
constexpr tvec(const base &v) noexcept
Construction from base vector.
Definition: tvec.hpp:34
tvec(const T(&d)[N]) noexcept
Construction from native array.
Definition: tvec.hpp:38
static auto fill(T v) noexcept
Creates a zero vector instance with all elements set to v.
Definition: vector.hpp:61
constexpr tvec(const vector< P, M, W > &v) noexcept
Construction from vector of different dimensionality.
Definition: tvec.hpp:55
math::tvec< T, N, V > tvec
Template alias for math::tvec.
Definition: vector.hpp:24
constexpr tvec() noexcept
Default constructor. Constructs a zero vector.
Definition: tvec.hpp:26
constexpr tvec(const vector< P, M, W > &v, const vector< T, N - M, W > &w) noexcept
Construction from a pair of vectors of different dimensionality.
Definition: tvec.hpp:77
constexpr tvec(T v) noexcept
Constructor initializing all coordinates to v.
Definition: tvec.hpp:30
static constexpr auto skip(basic_span< T, P, S > s, L l) noexcept -> basic_span< T, P, S >
Skips a specified count of elements from the front of a span.
Definition: span_algo.hpp:60
constexpr tvec(const vector< P, M, W > &v, R &&... r) noexcept
Construction from vector of different dimensionality.
Definition: tvec.hpp:72
static auto zero() noexcept
Creates a new zero vector instance.
Definition: vector.hpp:56
constexpr tvec(P &&... p) noexcept
Construction from coordinates.
Definition: tvec.hpp:46