fennec
Loading...
Searching...
No Matches
vector_base.h
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
19
20#ifndef FENNEC_MATH_VECTOR_BASE_H
21#define FENNEC_MATH_VECTOR_BASE_H
22
23#include <fennec/math/detail/_fwd.h>
24
25#include <fennec/math/swizzle.h>
26#include <fennec/math/vector_storage.h>
27
29
30namespace fennec::detail
31{
32
33//
34// \brief helper class for generating vectors
35// \tparam scalar base scalar type
36// \tparam size size of the vector type
37template<typename scalar, size_t size>
38struct vector_base_type_helper
39{
40 //
41 // \var SizeV
42 // \brief size of the vector type
43 inline static constexpr size_t SizeV = size;
44
45
46 //
47 // \brief Base scalar type
48 using ScalarT = scalar;
49
50 //
51 // \brief Base vector type
52 using VectorT = vec<ScalarT, SizeV>;
53
54 //
55 // \brief Backing array holding the elements
56 using DataT = array<ScalarT, SizeV>;
57
58 //
59 // \brief Helper for generating a swizzle from a set of indices
60 // \tparam IndicesV Indices of the vector to pull from
61 template<size_t...IndicesV> struct SwizzleGen
62 {
63 // \brief generated swizzle type
64 using type = swizzle<VectorT, DataT, ScalarT, IndicesV...>;
65 };
66
67 // Specialization for single component swizzles to decay into a scalar
68 template<size_t IndexV> struct SwizzleGen<IndexV>
69 {
70 // \brief decayed scalar type
71 using type = ScalarT;
72 };
73
74 //
75 // \brief backing storage type
76 using StorageT = vector_storage<SizeV, SwizzleGen, DataT>;
77};
78
79//
80// \brief helper for getting the storage type of the vector constructed with the provided size and scalar type
81template<typename ScalarT, size_t SizeV>
82using vector_base_type = typename vector_base_type_helper<ScalarT, SizeV>::StorageT;
83
84}
85
86#endif // FENNEC_MATH_VECTOR_BASE_H
A header containing the definition for a static/stack allocated array.
Swizzling