2014-02-09 22:07:57 +00:00
|
|
|
#ifndef idid0528646832E04CF08E9785B66CFE0BD1
|
|
|
|
#define idid0528646832E04CF08E9785B66CFE0BD1
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <ciso646>
|
|
|
|
#include <type_traits>
|
|
|
|
|
|
|
|
namespace cloonel {
|
|
|
|
template <typename T, uint32_t S>
|
|
|
|
class Vector {
|
|
|
|
template <typename U, uint32_t R> friend class Vector;
|
|
|
|
public:
|
|
|
|
Vector ( void ) = default;
|
|
|
|
explicit Vector ( T parValue );
|
2014-02-10 00:19:45 +00:00
|
|
|
template <typename U> explicit Vector ( const Vector<U, S>& parOther );
|
2014-02-09 22:07:57 +00:00
|
|
|
template <typename = std::enable_if<S == 2> > Vector ( T parX, T parY ) : m_mem {parX, parY} {}
|
|
|
|
template <typename = std::enable_if<S == 3> > Vector ( T parX, T parY, T parZ ) : m_mem {parX, parY, parZ} {}
|
|
|
|
template <typename = std::enable_if<S == 4> > Vector ( T parX, T parY, T parZ, T parW ) : m_mem {parX, parY, parZ, parW} {}
|
|
|
|
|
|
|
|
~Vector ( void ) noexcept = default;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
Dimension = S
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename = std::enable_if< 4 >= S> > T& x ( void ) { return m_mem[0]; }
|
|
|
|
template <typename = std::enable_if< 4 >= S> > const T& x ( void ) const { return m_mem[0]; }
|
|
|
|
template <typename = std::enable_if<S >= 2 and 4 >= S> > T& y ( void ) { return m_mem[1]; }
|
|
|
|
template <typename = std::enable_if<S >= 2 and 4 >= S> > const T& y ( void ) const { return m_mem[1]; }
|
|
|
|
template <typename = std::enable_if<S >= 3 and 4 >= S> > T& z ( void ) { return m_mem[2]; }
|
|
|
|
template <typename = std::enable_if<S >= 3 and 4 >= S> > const T& z ( void ) const { return m_mem[2]; }
|
|
|
|
template <typename = std::enable_if<S >= 4 and 4 >= S> > T& w ( void ) { return m_mem[3]; }
|
|
|
|
template <typename = std::enable_if<S >= 4 and 4 >= S> > const T& w ( void ) const { return m_mem[3]; }
|
|
|
|
|
|
|
|
template <typename U> const Vector& operator+= ( const Vector<U, S>& parOther );
|
|
|
|
template <typename U> const Vector& operator-= ( const Vector<U, S>& parOther );
|
|
|
|
template <typename U> const Vector& operator*= ( const Vector<U, S>& parOther );
|
|
|
|
template <typename U> const Vector& operator/= ( const Vector<U, S>& parOther );
|
2014-02-10 00:19:45 +00:00
|
|
|
template <typename U> const Vector& operator+= ( U parOther );
|
|
|
|
template <typename U> const Vector& operator-= ( U parOther );
|
|
|
|
template <typename U> const Vector& operator*= ( U parOther );
|
|
|
|
template <typename U> const Vector& operator/= ( U parOther );
|
|
|
|
|
|
|
|
T& operator[] ( uint32_t parIndex ) { return m_mem[parIndex]; }
|
|
|
|
const T& operator[] ( uint32_t parIndex ) const { return m_mem[parIndex]; }
|
|
|
|
|
2014-02-09 22:07:57 +00:00
|
|
|
private:
|
|
|
|
T m_mem[S];
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T, typename U, uint32_t S>
|
2014-02-22 12:12:50 +00:00
|
|
|
Vector<typename std::common_type<T, U>::type, S> operator+ ( Vector<T, S> parA, const Vector<U, S>& parB ) __attribute__((pure));
|
2014-02-09 22:07:57 +00:00
|
|
|
template <typename T, typename U, uint32_t S>
|
2014-02-22 12:12:50 +00:00
|
|
|
Vector<typename std::common_type<T, U>::type, S> operator- ( Vector<T, S> parA, const Vector<U, S>& parB ) __attribute__((pure));
|
2014-02-09 22:07:57 +00:00
|
|
|
template <typename T, typename U, uint32_t S>
|
2014-02-22 12:12:50 +00:00
|
|
|
Vector<typename std::common_type<T, U>::type, S> operator* ( Vector<T, S> parA, const Vector<U, S>& parB ) __attribute__((pure));
|
2014-02-09 22:07:57 +00:00
|
|
|
template <typename T, typename U, uint32_t S>
|
2014-02-22 12:12:50 +00:00
|
|
|
Vector<typename std::common_type<T, U>::type, S> operator/ ( Vector<T, S> parA, const Vector<U, S>& parB ) __attribute__((pure));
|
2014-02-10 00:19:45 +00:00
|
|
|
template <typename T, typename U, uint32_t S>
|
|
|
|
Vector<typename std::common_type<T, U>::type, S> operator+ ( U parA, const Vector<U, S>& parB ) __attribute__((pure));
|
|
|
|
template <typename T, typename U, uint32_t S>
|
|
|
|
Vector<typename std::common_type<T, U>::type, S> operator- ( U parA, const Vector<U, S>& parB ) __attribute__((pure));
|
|
|
|
template <typename T, typename U, uint32_t S>
|
|
|
|
Vector<typename std::common_type<T, U>::type, S> operator* ( U parA, const Vector<U, S>& parB ) __attribute__((pure));
|
|
|
|
template <typename T, typename U, uint32_t S>
|
|
|
|
Vector<typename std::common_type<T, U>::type, S> operator/ ( U parA, const Vector<U, S>& parB ) __attribute__((pure));
|
|
|
|
template <typename T, typename U, uint32_t S>
|
|
|
|
Vector<typename std::common_type<T, U>::type, S> operator+ ( const Vector<T, S>& parA, U parB ) __attribute__((pure));
|
|
|
|
template <typename T, typename U, uint32_t S>
|
|
|
|
Vector<typename std::common_type<T, U>::type, S> operator- ( const Vector<T, S>& parA, U parB ) __attribute__((pure));
|
|
|
|
template <typename T, typename U, uint32_t S>
|
|
|
|
Vector<typename std::common_type<T, U>::type, S> operator* ( const Vector<T, S>& parA, U parB ) __attribute__((pure));
|
|
|
|
template <typename T, typename U, uint32_t S>
|
|
|
|
Vector<typename std::common_type<T, U>::type, S> operator/ ( const Vector<T, S>& parA, U parB ) __attribute__((pure));
|
2014-02-09 22:07:57 +00:00
|
|
|
|
|
|
|
typedef Vector<float, 2> float2;
|
|
|
|
typedef Vector<uint16_t, 2> ushort2;
|
2014-02-10 00:20:16 +00:00
|
|
|
typedef Vector<int32_t, 2> int2;
|
2014-02-09 22:07:57 +00:00
|
|
|
} //namespace cloonel
|
|
|
|
#include "vector.inl"
|
|
|
|
#endif
|