80 lines
2.1 KiB
C++
80 lines
2.1 KiB
C++
//==================================================================================================
|
|
/*
|
|
ROTGEN - Runtime Overlay for Eigen
|
|
Copyright : CODE RECKONS
|
|
SPDX-License-Identifier: BSL-1.0
|
|
*/
|
|
//==================================================================================================
|
|
#pragma once
|
|
|
|
#include <rotgen/config.hpp>
|
|
|
|
#include <type_traits>
|
|
|
|
namespace rotgen
|
|
{
|
|
template<typename Scalar, int Options = AutoAlign> class quaternion;
|
|
|
|
//-------------------------------------------------------------------------------------------
|
|
// Convert entity/eigen types to a proper ref so we can write less function
|
|
// overloads
|
|
|
|
template<typename T> struct generalize;
|
|
|
|
template<typename T>
|
|
requires(std::is_arithmetic_v<std::remove_cvref_t<T>>)
|
|
struct generalize<T>
|
|
{
|
|
using type = std::remove_cvref_t<T>;
|
|
};
|
|
|
|
template<typename T> using generalize_t = typename generalize<T>::type;
|
|
|
|
template<concepts::entity T> struct generalize<T>
|
|
{
|
|
static constexpr bool is_const =
|
|
std::is_const_v<std::remove_reference_t<T>>;
|
|
using base = matrix<typename std::remove_cvref_t<T>::value_type,
|
|
std::remove_cvref_t<T>::RowsAtCompileTime,
|
|
std::remove_cvref_t<T>::ColsAtCompileTime,
|
|
std::remove_cvref_t<T>::storage_order>;
|
|
using type = std::conditional_t<is_const, ref<base const>, ref<base>>;
|
|
};
|
|
|
|
template<typename T, int O, typename S> struct generalize<ref<T, O, S>>
|
|
{
|
|
using type = ref<T, O, S>;
|
|
};
|
|
|
|
template<typename T, int O, typename S> struct generalize<ref<T, O, S> const>
|
|
{
|
|
using type = ref<T, O, S>;
|
|
};
|
|
|
|
template<typename T> struct generalize<quaternion<T>>
|
|
{
|
|
using type = quaternion<T>;
|
|
};
|
|
|
|
template<typename T> struct generalize<quaternion<T> const>
|
|
{
|
|
using type = quaternion<T>;
|
|
};
|
|
|
|
template<concepts::entity T> typename T::parent& base_of(T& a)
|
|
{
|
|
return a.base();
|
|
}
|
|
|
|
template<concepts::entity T> typename T::parent const& base_of(T const& a)
|
|
{
|
|
return a.base();
|
|
}
|
|
|
|
template<typename T>
|
|
T base_of(T a)
|
|
requires(std::is_arithmetic_v<T>)
|
|
{
|
|
return a;
|
|
}
|
|
}
|