2017-11-22 17:03:00 +11:00
|
|
|
/*
|
2018-08-04 15:14:06 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2017-11-22 17:03:00 +11:00
|
|
|
*
|
2019-05-17 10:55:49 +10:00
|
|
|
* Copyright 2012-2019 Danny Robson <danny@nerdcruft.net>
|
2017-11-22 17:03:00 +11:00
|
|
|
*/
|
|
|
|
|
2019-05-17 10:55:49 +10:00
|
|
|
#pragma once
|
2017-11-22 17:03:00 +11:00
|
|
|
|
|
|
|
#include "fwd.hpp"
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <type_traits>
|
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
namespace cruft {
|
2017-11-22 17:03:00 +11:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// operation traits
|
|
|
|
template <typename, typename>
|
|
|
|
struct result { };
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
2018-01-10 17:19:39 +11:00
|
|
|
#define RESULT_T(ArgA,ArgB,ResultT) \
|
|
|
|
template < \
|
|
|
|
std::size_t S, \
|
|
|
|
typename ValueA,\
|
|
|
|
typename ValueB\
|
|
|
|
> struct result<\
|
|
|
|
ArgA<S,ValueA>,\
|
|
|
|
ArgB<S,ValueB>\
|
|
|
|
> {\
|
|
|
|
using type = ResultT<S,std::common_type_t<ValueA,ValueB>>; \
|
|
|
|
};
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
template <
|
|
|
|
std::size_t S,
|
|
|
|
typename ValueA,
|
|
|
|
typename ValueB
|
|
|
|
> struct result<
|
|
|
|
srgba<S,ValueA>,
|
|
|
|
srgba<S,ValueB>
|
|
|
|
> {
|
|
|
|
using type = srgba<S,std::common_type_t<ValueA,ValueB>>;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <std::size_t S, typename T> struct result<srgba<S,T>, vector<S,T>> { using type = srgba<S,T>; };
|
|
|
|
template <std::size_t S, typename T> struct result<vector<S,T>,srgba<S,T>> { using type = srgba<S,T>; };
|
2017-11-22 17:03:00 +11:00
|
|
|
template <std::size_t S, typename T> struct result<extent<S,T>,extent<S,T>> { using type = extent<S,T>; };
|
|
|
|
template <std::size_t S, typename T> struct result<extent<S,T>,vector<S,T>> { using type = extent<S,T>; };
|
2018-01-10 17:19:39 +11:00
|
|
|
template <std::size_t S, typename T> struct result<point<S,T>, extent<S,T>> { using type = point <S,T>; };
|
|
|
|
template <std::size_t S, typename T> struct result<point<S,T>, vector<S,T>> { using type = point <S,T>; };
|
2017-11-22 17:03:00 +11:00
|
|
|
template <std::size_t S, typename T> struct result<vector<S,T>,point<S,T>> { using type = point <S,T>; };
|
|
|
|
template <std::size_t S, typename T> struct result<vector<S,T>,vector<S,T>> { using type = vector<S,T>; };
|
2018-01-10 17:19:39 +11:00
|
|
|
#endif
|
|
|
|
|
|
|
|
RESULT_T(extent,extent,extent)
|
|
|
|
RESULT_T(extent,vector,extent)
|
|
|
|
RESULT_T(point,extent,point)
|
|
|
|
RESULT_T(point,vector,point)
|
|
|
|
RESULT_T(srgba,vector,srgba)
|
|
|
|
RESULT_T(srgba,srgba,srgba)
|
2018-05-03 17:31:41 +10:00
|
|
|
RESULT_T(vector,extent,extent)
|
2018-01-10 17:19:39 +11:00
|
|
|
RESULT_T(vector,point,point)
|
|
|
|
RESULT_T(vector,srgba,srgba)
|
|
|
|
RESULT_T(vector,vector,vector)
|
|
|
|
|
2017-11-22 17:03:00 +11:00
|
|
|
|
|
|
|
template <
|
|
|
|
typename A, typename B
|
|
|
|
>
|
|
|
|
using result_t = typename result<A,B>::type;
|
|
|
|
|
|
|
|
|
2018-01-10 17:19:39 +11:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename A, typename B, typename = std::void_t<>>
|
|
|
|
struct has_result : public std::false_type {};
|
|
|
|
|
|
|
|
|
|
|
|
template <typename CoordA, typename CoordB>
|
|
|
|
struct has_result<
|
|
|
|
CoordA,
|
|
|
|
CoordB,
|
|
|
|
std::void_t<
|
|
|
|
result_t<CoordA,CoordB>
|
|
|
|
>
|
|
|
|
> : public std::true_type {};
|
|
|
|
|
|
|
|
|
|
|
|
template <typename A, typename B>
|
|
|
|
constexpr auto has_result_v = has_result<A,B>::value;
|
|
|
|
|
|
|
|
|
2017-11-22 17:03:00 +11:00
|
|
|
//---------------------------------------------------------------------
|
|
|
|
template <typename>
|
|
|
|
struct has_norm : public std::false_type { };
|
|
|
|
|
|
|
|
template <std::size_t S, typename T> struct has_norm<vector<S,T>> : public std::true_type { };
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
constexpr auto has_norm_v = has_norm<T>::value;
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
struct has_scalar_op : public std::false_type { };
|
|
|
|
|
|
|
|
template <std::size_t S, typename T> struct has_scalar_op<srgba<S,T>> : public std::true_type { };
|
|
|
|
template <std::size_t S, typename T> struct has_scalar_op<extent<S,T>> : public std::true_type { };
|
|
|
|
template <std::size_t S, typename T> struct has_scalar_op<point<S,T>> : public std::true_type { };
|
|
|
|
template <std::size_t S, typename T> struct has_scalar_op<vector<S,T>> : public std::true_type { };
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
constexpr auto has_scalar_op_v = has_scalar_op<T>::value;
|
|
|
|
|
|
|
|
template <class> struct is_coord : std::false_type { };
|
|
|
|
|
|
|
|
template <typename T> struct is_coord<const T> : is_coord<T> {};
|
|
|
|
template <typename T> struct is_coord<T&> : is_coord<T> {};
|
|
|
|
|
2024-10-16 12:19:48 +11:00
|
|
|
template <std::size_t S, typename T> struct is_coord<point<S,T>> : std::true_type { };
|
|
|
|
template <std::size_t S, typename T> struct is_coord<extent<S,T>> : std::true_type { };
|
|
|
|
template <std::size_t S, typename T> struct is_coord<vector<S,T>> : std::true_type { };
|
|
|
|
template <std::size_t S, typename T> struct is_coord<srgba<S,T>> : std::true_type { };
|
2017-11-22 17:03:00 +11:00
|
|
|
|
|
|
|
template <class K>
|
|
|
|
constexpr bool
|
|
|
|
is_coord_v = is_coord<K>::value;
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename T> struct has_redim : std::false_type {};
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
template <std::size_t S, typename T> struct has_redim< point<S,T>> : public std::true_type {};
|
|
|
|
template <std::size_t S, typename T> struct has_redim<vector<S,T>> : public std::true_type {};
|
|
|
|
template <std::size_t S, typename T> struct has_redim<extent<S,T>> : public std::true_type {};
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
template <typename T> constexpr auto has_redim_v = has_redim<T>::value;
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename> struct redim_type {};
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
template <std::size_t S, typename T> struct redim_type<point<S,T>>
|
2021-04-19 14:52:22 +10:00
|
|
|
{ template <std::size_t S_> using type = point<S_,T>; };
|
2017-11-22 17:03:00 +11:00
|
|
|
|
|
|
|
template <std::size_t S, typename T> struct redim_type<vector<S,T>>
|
2021-04-19 14:52:22 +10:00
|
|
|
{ template <std::size_t S_> using type = vector<S_,T>; };
|
2017-11-22 17:03:00 +11:00
|
|
|
|
|
|
|
template <std::size_t S, typename T> struct redim_type<extent<S,T>>
|
2021-04-19 14:52:22 +10:00
|
|
|
{ template <std::size_t S_> using type = extent<S_,T>; };
|
2017-11-22 17:03:00 +11:00
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
template <
|
|
|
|
typename Self,
|
|
|
|
std::size_t S
|
|
|
|
>
|
|
|
|
using redim_t = typename redim_type<Self>::template type<S>;
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename> struct revalue_type {};
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
template <std::size_t S, typename T>
|
|
|
|
struct revalue_type<point<S,T>> {
|
|
|
|
template <typename _T> using type = point<S,_T>;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <std::size_t S, typename T>
|
|
|
|
struct revalue_type<vector<S,T>> {
|
|
|
|
template <typename _T> using type = vector<S,_T>;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <std::size_t S, typename T>
|
|
|
|
struct revalue_type<extent<S,T>> {
|
|
|
|
template <typename _T> using type = extent<S,_T>;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
template <typename Self, typename T>
|
|
|
|
using revalue_t = typename revalue_type<Self>::template type<T>;
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename,typename=void> struct arity {};
|
|
|
|
|
|
|
|
|
2019-05-17 10:55:49 +10:00
|
|
|
//-------------------------------------------------------------------------
|
2017-11-22 17:03:00 +11:00
|
|
|
template <typename T>
|
|
|
|
struct arity<T,std::enable_if_t<std::is_arithmetic_v<T>,void>
|
|
|
|
> :std::integral_constant<std::size_t, 1>
|
|
|
|
{ };
|
|
|
|
|
|
|
|
|
2019-05-17 10:55:49 +10:00
|
|
|
//-------------------------------------------------------------------------
|
2017-11-22 17:03:00 +11:00
|
|
|
template <typename T>
|
|
|
|
struct arity<
|
|
|
|
T,std::enable_if_t<is_coord_v<T>,void>
|
|
|
|
> :std::integral_constant<std::size_t,T::elements>
|
|
|
|
{ };
|
|
|
|
|
|
|
|
|
2019-05-17 10:55:49 +10:00
|
|
|
//-------------------------------------------------------------------------
|
2017-11-22 17:03:00 +11:00
|
|
|
template <typename T>
|
|
|
|
constexpr auto arity_v = arity<T>::value;
|
2019-05-17 10:55:49 +10:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename, typename = void> struct value_trait {};
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
template <size_t S, typename T>
|
|
|
|
struct value_trait<cruft::point<S,T>>
|
|
|
|
{ using value_type = T; };
|
|
|
|
|
2019-05-21 17:44:18 +10:00
|
|
|
template <size_t S, typename T>
|
|
|
|
struct value_trait<cruft::vector<S,T>>
|
|
|
|
{ using value_type = T; };
|
|
|
|
|
2020-03-16 14:13:02 +11:00
|
|
|
template <typename ValueT>
|
|
|
|
requires requires {
|
|
|
|
typename ValueT::value_type;
|
|
|
|
}
|
|
|
|
struct value_trait<ValueT> {
|
|
|
|
using value_type = typename ValueT::value_type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename ValueT>
|
|
|
|
requires std::is_arithmetic_v<ValueT>
|
|
|
|
struct value_trait<ValueT> {
|
|
|
|
using value_type = ValueT;
|
|
|
|
};
|
2019-05-17 10:55:49 +10:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
template <typename OuterT>
|
|
|
|
using value_trait_t = typename value_trait<OuterT>::value_type;
|
2017-11-22 17:03:00 +11:00
|
|
|
}
|
|
|
|
|
2019-05-17 10:55:49 +10:00
|
|
|
|
|
|
|
#include "../types/description.hpp"
|
|
|
|
|
|
|
|
namespace cruft::types {
|
|
|
|
template <typename CoordT>
|
|
|
|
struct arity_trait<
|
|
|
|
CoordT,
|
|
|
|
std::enable_if_t<
|
|
|
|
::cruft::is_coord_v<CoordT>
|
|
|
|
>
|
|
|
|
> : public ::cruft::arity<CoordT> { };
|
|
|
|
}
|