coord: move base coord class into main namespace

This commit is contained in:
Danny Robson 2015-03-06 01:15:52 +11:00
parent 439bb19679
commit 99ba406b4d
5 changed files with 72 additions and 70 deletions

View File

@ -20,7 +20,7 @@
#ifndef __UTIL_COLOUR_HPP
#define __UTIL_COLOUR_HPP
#include "detail/coord.hpp"
#include "coord.hpp"
#include "json/tree.hpp"
@ -29,8 +29,8 @@
namespace util {
/// An RGBA colour POD type.
template <typename T>
struct colour : public detail::coord<4,T,detail::rgba> {
using detail::coord<4,T,detail::rgba>::coord;
struct colour : public coord<4,T,detail::rgba> {
using coord<4,T,detail::rgba>::coord;
static const colour WHITE;
static const colour BLACK;

View File

@ -20,8 +20,8 @@
#ifndef __UTIL_COORD_HPP
#define __UTIL_COORD_HPP
#include "../preprocessor.hpp"
#include "../platform.hpp"
#include "platform.hpp"
#include "preprocessor.hpp"
#include <algorithm>
#include <iterator>
@ -30,10 +30,6 @@
#include <cstdlib>
namespace util {
template <size_t,typename> class point;
template <size_t,typename> class extent;
template <size_t,typename> class vector;
namespace detail {
///////////////////////////////////////////////////////////////////////
// tags for accessor names
@ -207,58 +203,64 @@ namespace util {
coord_base<4,T,tags...> ({ v0, v1, v2, v3 })
{ ; }
};
/////////////////////////////////////////////////////////////////////////
template <size_t S, typename T, typename ...tags>
struct coord : public coord_init<S,T,tags...> {
static_assert (S > 0, "coord dimensions must be strictly positive");
typedef T value_type;
static constexpr size_t dimension = S;
static constexpr size_t elements = S;
size_t size (void) const { return S; }
// constructors
using coord_init<S,T,tags...>::coord_init;
coord () = default;
explicit coord (T v)
{ std::fill (std::begin (this->data), std::end (this->data), v); }
coord (const coord<S,T,tags...> &rhs) = default;
coord& operator= (const coord<S,T,tags...> &rhs) = default;
// element accessors
T& operator[] (size_t i) { return this->data[i]; }
T operator[] (size_t i) const { return this->data[i]; }
const T* begin (void) const { return std::begin (this->data); }
const T* end (void) const { return std::end (this->data); }
T* begin (void) { return std::begin (this->data); }
T* end (void) { return std::end (this->data); }
};
///////////////////////////////////////////////////////////////////////
template <
size_t S,
typename T,
template <size_t,typename> class A,
template <size_t,typename> class B
>
struct coord_traits { };
template <size_t S, typename T> struct coord_traits<S,T,extent,extent> { typedef extent<S,T> result; };
template <size_t S, typename T> struct coord_traits<S,T,extent,vector> { typedef extent<S,T> result; };
template <size_t S, typename T> struct coord_traits<S,T,point,extent> { typedef point<S,T> result; };
template <size_t S, typename T> struct coord_traits<S,T,point,vector> { typedef point<S,T> result; };
template <size_t S, typename T> struct coord_traits<S,T,vector,vector> { typedef vector<S,T> result; };
}
/////////////////////////////////////////////////////////////////////////
template <size_t S, typename T, typename ...tags>
struct coord : public detail::coord_init<S,T,tags...> {
static_assert (S > 0, "coord dimensions must be strictly positive");
typedef T value_type;
static constexpr size_t dimension = S;
static constexpr size_t elements = S;
size_t size (void) const { return S; }
// constructors
using detail::coord_init<S,T,tags...>::coord_init;
coord () = default;
explicit coord (T v)
{ std::fill (std::begin (this->data), std::end (this->data), v); }
coord (const coord<S,T,tags...> &rhs) = default;
coord& operator= (const coord<S,T,tags...> &rhs) = default;
// element accessors
T& operator[] (size_t i) { return this->data[i]; }
T operator[] (size_t i) const { return this->data[i]; }
const T* begin (void) const { return std::begin (this->data); }
const T* end (void) const { return std::end (this->data); }
T* begin (void) { return std::begin (this->data); }
T* end (void) { return std::end (this->data); }
};
///////////////////////////////////////////////////////////////////////
// operation traits
template <size_t,typename> class point;
template <size_t,typename> class extent;
template <size_t,typename> class vector;
template <
size_t S,
typename T,
template <size_t,typename> class A,
template <size_t,typename> class B
>
struct coord_traits { };
template <size_t S, typename T> struct coord_traits<S,T,extent,extent> { typedef extent<S,T> result; };
template <size_t S, typename T> struct coord_traits<S,T,extent,vector> { typedef extent<S,T> result; };
template <size_t S, typename T> struct coord_traits<S,T,point,extent> { typedef point<S,T> result; };
template <size_t S, typename T> struct coord_traits<S,T,point,vector> { typedef point<S,T> result; };
template <size_t S, typename T> struct coord_traits<S,T,vector,vector> { typedef vector<S,T> result; };
///////////////////////////////////////////////////////////////////////////
// vector operators
#define ELEMENT_OP(OP) \
@ -268,10 +270,10 @@ namespace util {
template <size_t,typename> class A, \
template <size_t,typename> class B \
> \
typename detail::coord_traits<S,T,A,B>::result \
typename coord_traits<S,T,A,B>::result \
operator OP (A<S,T> a, B<S,T> b) \
{ \
typename detail::coord_traits<S,T,A,B>::result out; \
typename coord_traits<S,T,A,B>::result out; \
for (size_t i = 0; i < S; ++i) \
out[i] = a[i] OP b[i]; \
return out; \
@ -283,7 +285,7 @@ namespace util {
template <size_t,typename> class A, \
template <size_t,typename> class B \
> \
typename detail::coord_traits<S,T,A,B>::result& \
typename coord_traits<S,T,A,B>::result& \
operator PASTE(OP,=) (A<S,T>& a, B<S,T> b) \
{ \
for (size_t i = 0; i < S; ++i) \

View File

@ -20,7 +20,7 @@
#ifndef __UTIL_EXTENT_HPP
#define __UTIL_EXTENT_HPP
#include "detail/coord.hpp"
#include "coord.hpp"
#include "vector.hpp"
#include <iostream>
@ -30,9 +30,9 @@ namespace util {
* A pure two-dimensional size, without positioning
*/
template <size_t S, typename T>
struct extent : public detail::coord<S,T,detail::whd>
struct extent : public coord<S,T,detail::whd>
{
using detail::coord<S,T,detail::whd>::coord;
using coord<S,T,detail::whd>::coord;
extent () = default;
extent (vector<S,T>);

View File

@ -22,7 +22,7 @@
#include "extent.hpp"
#include "vector.hpp"
#include "detail/coord.hpp"
#include "coord.hpp"
#include <array>
#include <initializer_list>
@ -32,9 +32,9 @@
namespace util {
/// An n-dimensional position in space.
template <size_t S, typename T>
struct point : public detail::coord<S,T,detail::xyzw>
struct point : public coord<S,T,detail::xyzw>
{
using detail::coord<S,T,detail::xyzw>::coord;
using coord<S,T,detail::xyzw>::coord;
// point operators
template <typename U> typename std::common_type<T,U>::type distance (const point<S,U> &) const;

View File

@ -21,7 +21,7 @@
#define __UTIL_VECTOR_HPP
#include "json/tree.hpp"
#include "detail/coord.hpp"
#include "coord.hpp"
#include <array>
#include <iostream>
@ -29,8 +29,8 @@
namespace util {
template <size_t S, typename T>
struct vector : public detail::coord<S,T,detail::xyzw,detail::stpq> {
using detail::coord<S,T,detail::xyzw,detail::stpq>::coord;
struct vector : public coord<S,T,detail::xyzw,detail::stpq> {
using coord<S,T,detail::xyzw,detail::stpq>::coord;
bool is_zero (void) const;