fennec
Loading...
Searching...
No Matches
swizzle.h
Go to the documentation of this file.
1// =====================================================================================================================
2// fennec, a free and open source game engine
3// Copyright © 2025 Medusa Slockbower
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17// =====================================================================================================================
18
30
31#ifndef FENNEC_MATH_SWIZZLE_H
32#define FENNEC_MATH_SWIZZLE_H
33
43
45
46#include <fennec/math/swizzle_storage.h>
47
48namespace fennec
49{
50
59template<typename VectorT, typename DataT, typename ScalarT, size_t...IndicesV>
60struct swizzle : public detail::swizzle_storage<DataT, ScalarT, IndicesV...>
61{
62public:
63
66 using scalar_t = ScalarT;
67
71 inline static constexpr size_t dimension = sizeof...(IndicesV);
72 inline static constexpr size_t num_components = sizeof...(IndicesV);
73 inline static constexpr size_t size = sizeof...(IndicesV);
74 inline static constexpr size_t N = sizeof...(IndicesV);
76
80 constexpr VectorT decay() const {
81 VectorT res;
82 return decay_impl(res, make_index_metasequence<size>{});
83 }
84
88 constexpr explicit operator VectorT() const {
89 return decay();
90 }
91
92 swizzle() = default;
93
94private:
95 template<size_t...VecIndicesV>
96 constexpr VectorT& decay_impl(VectorT& vec, index_metasequence<VecIndicesV...>) {
97 return ((vec[VecIndicesV] = this->data[IndicesV]), ..., vec);
98 }
99};
100
101}
102
103#endif // FENNEC_MATH_SWIZZLE_H
Metasequences
metaprogramming integral metasequence
Definition metasequences.h:162
generate a fennec::index_metasequence
Definition metasequences.h:223
Structure for Handling Vector Swizzling.
Definition swizzle.h:61
static constexpr size_t size
size of the swizzle
Definition swizzle.h:73
static constexpr size_t num_components
number of components
Definition swizzle.h:72
static constexpr size_t N
size of the swizzle
Definition swizzle.h:74
constexpr VectorT decay() const
Decay the Swizzle into a Vector.
Definition swizzle.h:80
ScalarT scalar_t
alias for the scalar type
Definition swizzle.h:66
static constexpr size_t dimension
dimension of the swizzle
Definition swizzle.h:71
decltype(detail::_gen_vector< vector, ScalarT >(make_index_metasequence< SizeV >{})) vec
Main vector template.
Definition vector.h:124