Initial Commit
This commit is contained in:
98
include/fennec/math/vector_base.h
Normal file
98
include/fennec/math/vector_base.h
Normal file
@@ -0,0 +1,98 @@
|
||||
// =====================================================================================================================
|
||||
// fennec, a free and open source game engine
|
||||
// Copyright © 2025 Medusa Slockbower
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
|
||||
#ifndef VECTOR_BASE_H
|
||||
#define VECTOR_BASE_H
|
||||
|
||||
#include <fennec/math/detail/__fwd.h>
|
||||
|
||||
#include <fennec/math/swizzle.h>
|
||||
#include <fennec/math/vector_storage.h>
|
||||
|
||||
#include <fennec/containers/array.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
///
|
||||
/// \struct vector_base_type_helper
|
||||
/// \brief helper class for generating vectors
|
||||
/// \tparam scalar base scalar type
|
||||
/// \tparam size size of the vector type
|
||||
template<typename scalar, size_t size>
|
||||
struct vector_base_type_helper
|
||||
{
|
||||
///
|
||||
/// \var SizeV
|
||||
/// \brief size of the vector type
|
||||
inline static constexpr size_t SizeV = size;
|
||||
|
||||
|
||||
///
|
||||
/// \typedef ScalarT
|
||||
/// \brief Base scalar type
|
||||
using ScalarT = scalar;
|
||||
|
||||
///
|
||||
/// \typedef VectorT
|
||||
/// \brief Base vector type
|
||||
using VectorT = vec<ScalarT, SizeV>;
|
||||
|
||||
///
|
||||
/// \typedef DataT
|
||||
/// \brief Backing array holding the elements
|
||||
using DataT = array<ScalarT, SizeV>;
|
||||
|
||||
///
|
||||
/// \struct SwizzleGen
|
||||
/// \brief Helper for generating a swizzle from a set of indices
|
||||
/// \tparam IndicesV Indices of the vector to pull from
|
||||
template<size_t...IndicesV> struct SwizzleGen
|
||||
{
|
||||
/// \brief generated swizzle type
|
||||
using type = swizzle<VectorT, DataT, ScalarT, IndicesV...>;
|
||||
};
|
||||
|
||||
///
|
||||
/// \struct SwizzleGen<IndexV>
|
||||
/// \brief Partial Specialization for single component swizzles to decay into a scalar
|
||||
/// \tparam IndexV
|
||||
template<size_t IndexV> struct SwizzleGen<IndexV>
|
||||
{
|
||||
/// \brief decayed scalar type
|
||||
using type = ScalarT;
|
||||
};
|
||||
|
||||
///
|
||||
/// \typedef StorageT
|
||||
/// \brief backing storage type
|
||||
using StorageT = vector_storage<SizeV, SwizzleGen, DataT>;
|
||||
};
|
||||
|
||||
template<typename ScalarT, size_t SizeV>
|
||||
using vector_base_type = typename vector_base_type_helper<ScalarT, SizeV>::StorageT;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //VECTOR_BASE_H
|
||||
Reference in New Issue
Block a user