coord: pass client class to coord base
allows common typesafe implementation of cast and redim
This commit is contained in:
parent
9f6c17d6cf
commit
5428c93b9a
@ -29,8 +29,8 @@
|
||||
namespace util {
|
||||
/// An RGBA colour POD type.
|
||||
template <typename T>
|
||||
struct colour : public coord::base<4,T,coord::rgba> {
|
||||
using coord::base<4,T,coord::rgba>::base;
|
||||
struct colour : public coord::base<4,T,colour,coord::rgba> {
|
||||
using coord::base<4,T,util::colour,coord::rgba>::base;
|
||||
|
||||
static const colour WHITE;
|
||||
static const colour BLACK;
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
namespace util { namespace coord {
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
template <size_t S, typename T, typename ...tags>
|
||||
template <size_t S, typename T, template <size_t, typename> class KLASS, typename ...tags>
|
||||
struct base : public init <S,T,tags...> {
|
||||
static_assert (S > 0, "coord dimensions must be strictly positive");
|
||||
|
||||
@ -44,8 +44,8 @@ namespace util { namespace coord {
|
||||
explicit base (T v)
|
||||
{ std::fill (std::begin (this->data), std::end (this->data), v); }
|
||||
|
||||
base (const base<S,T,tags...> &rhs) = default;
|
||||
base& operator= (const base<S,T,tags...> &rhs) = default;
|
||||
base (const base<S,T,KLASS,tags...> &rhs) = default;
|
||||
base& operator= (const base<S,T,KLASS,tags...> &rhs) = default;
|
||||
|
||||
// element accessors
|
||||
T& operator[] (size_t i) { return this->data[i]; }
|
||||
@ -57,6 +57,7 @@ namespace util { namespace coord {
|
||||
T* begin (void) { return std::begin (this->data); }
|
||||
T* end (void) { return std::end (this->data); }
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// conversions
|
||||
template <template <size_t, typename> class K>
|
||||
K<S,T> as (void) const
|
||||
|
@ -30,9 +30,9 @@ namespace util {
|
||||
* A pure two-dimensional size, without positioning
|
||||
*/
|
||||
template <size_t S, typename T>
|
||||
struct extent : public coord::base<S,T,coord::whd>
|
||||
struct extent : public coord::base<S,T,extent,coord::whd>
|
||||
{
|
||||
using coord::base<S,T,coord::whd>::base;
|
||||
using coord::base<S,T,util::extent,coord::whd>::base;
|
||||
|
||||
extent () = default;
|
||||
extent (vector<S,T>);
|
||||
|
@ -32,9 +32,9 @@
|
||||
namespace util {
|
||||
/// An n-dimensional position in space.
|
||||
template <size_t S, typename T>
|
||||
struct point : public coord::base<S,T,coord::xyzw>
|
||||
struct point : public coord::base<S,T,point,coord::xyzw>
|
||||
{
|
||||
using coord::base<S,T,coord::xyzw>::base;
|
||||
using coord::base<S,T,util::point,coord::xyzw>::base;
|
||||
|
||||
// point operators
|
||||
template <typename U> typename std::common_type<T,U>::type distance (const point<S,U> &) const;
|
||||
|
@ -29,8 +29,9 @@
|
||||
|
||||
namespace util {
|
||||
template <size_t S, typename T>
|
||||
struct vector : public coord::base<S,T,coord::xyzw,coord::stpq> {
|
||||
using coord::base<S,T,coord::xyzw,coord::stpq>::base;
|
||||
struct vector : public coord::base<S,T,vector,coord::xyzw,coord::stpq>
|
||||
{
|
||||
using coord::base<S,T,util::vector,coord::xyzw,coord::stpq>::base;
|
||||
|
||||
bool is_zero (void) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user