New operators and stuff in vector class.
This commit is contained in:
parent
091b498ff7
commit
e2e932358b
2 changed files with 130 additions and 1 deletions
|
@ -12,7 +12,7 @@ namespace cloonel {
|
||||||
public:
|
public:
|
||||||
Vector ( void ) = default;
|
Vector ( void ) = default;
|
||||||
explicit Vector ( T parValue );
|
explicit Vector ( T parValue );
|
||||||
template <typename U> Vector ( const Vector<U, S>& parOther );
|
template <typename U> explicit Vector ( const Vector<U, S>& parOther );
|
||||||
template <typename = std::enable_if<S == 2> > Vector ( T parX, T parY ) : m_mem {parX, parY} {}
|
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 == 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} {}
|
template <typename = std::enable_if<S == 4> > Vector ( T parX, T parY, T parZ, T parW ) : m_mem {parX, parY, parZ, parW} {}
|
||||||
|
@ -36,6 +36,17 @@ namespace cloonel {
|
||||||
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 );
|
||||||
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+= ( 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 );
|
||||||
|
|
||||||
|
template <typename U>
|
||||||
|
operator Vector<U, S> ( void );
|
||||||
|
|
||||||
|
T& operator[] ( uint32_t parIndex ) { return m_mem[parIndex]; }
|
||||||
|
const T& operator[] ( uint32_t parIndex ) const { return m_mem[parIndex]; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
T m_mem[S];
|
T m_mem[S];
|
||||||
};
|
};
|
||||||
|
@ -48,6 +59,22 @@ namespace cloonel {
|
||||||
Vector<typename std::common_type<T, U>::type, S> operator* ( const Vector<T, S>& parA, const Vector<U, S>& parB ) __attribute__((pure));
|
Vector<typename std::common_type<T, U>::type, S> operator* ( const Vector<T, S>& parA, const Vector<U, S>& parB ) __attribute__((pure));
|
||||||
template <typename T, typename U, uint32_t S>
|
template <typename T, typename U, uint32_t S>
|
||||||
Vector<typename std::common_type<T, U>::type, S> operator/ ( const Vector<T, S>& parA, const Vector<U, S>& parB ) __attribute__((pure));
|
Vector<typename std::common_type<T, U>::type, S> operator/ ( const Vector<T, S>& 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/ ( 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));
|
||||||
|
|
||||||
typedef Vector<float, 2> float2;
|
typedef Vector<float, 2> float2;
|
||||||
typedef Vector<uint16_t, 2> ushort2;
|
typedef Vector<uint16_t, 2> ushort2;
|
||||||
|
|
102
src/vector.inl
102
src/vector.inl
|
@ -52,6 +52,53 @@ namespace cloonel {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///-------------------------------------------------------------------------
|
||||||
|
///-------------------------------------------------------------------------
|
||||||
|
template <typename T, uint32_t S>
|
||||||
|
template <typename U>
|
||||||
|
const Vector<T, S>& Vector<T, S>::operator+= (U parOther) {
|
||||||
|
for (uint32_t z = 0; z < S; ++z) {
|
||||||
|
m_mem[z] += parOther;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
template <typename T, uint32_t S>
|
||||||
|
template <typename U>
|
||||||
|
const Vector<T, S>& Vector<T, S>::operator-= (U parOther) {
|
||||||
|
for (uint32_t z = 0; z < S; ++z) {
|
||||||
|
m_mem[z] -= parOther;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
template <typename T, uint32_t S>
|
||||||
|
template <typename U>
|
||||||
|
const Vector<T, S>& Vector<T, S>::operator*= (U parOther) {
|
||||||
|
for (uint32_t z = 0; z < S; ++z) {
|
||||||
|
m_mem[z] *= parOther;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
template <typename T, uint32_t S>
|
||||||
|
template <typename U>
|
||||||
|
const Vector<T, S>& Vector<T, S>::operator/= (U parOther) {
|
||||||
|
for (uint32_t z = 0; z < S; ++z) {
|
||||||
|
m_mem[z] /= parOther;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
///-------------------------------------------------------------------------
|
||||||
|
///-------------------------------------------------------------------------
|
||||||
|
template <typename T, uint32_t S>
|
||||||
|
template <typename U>
|
||||||
|
Vector<T, S>::operator Vector<U, S>() {
|
||||||
|
Vector<U, S> retVal;
|
||||||
|
for (uint32_t z = 0; z < S; ++z) {
|
||||||
|
retVal[z] = m_mem[z];
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
///-------------------------------------------------------------------------
|
///-------------------------------------------------------------------------
|
||||||
///-------------------------------------------------------------------------
|
///-------------------------------------------------------------------------
|
||||||
template <typename T, typename U, uint32_t S>
|
template <typename T, typename U, uint32_t S>
|
||||||
|
@ -86,4 +133,59 @@ namespace cloonel {
|
||||||
parA /= parB;
|
parA /= parB;
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///-------------------------------------------------------------------------
|
||||||
|
///-------------------------------------------------------------------------
|
||||||
|
template <typename T, typename U, uint32_t S>
|
||||||
|
Vector<typename std::common_type<T, U>::type, S> operator+ (T parA, const Vector<U, S>& parB) {
|
||||||
|
return parB + parA;
|
||||||
|
}
|
||||||
|
template <typename T, typename U, uint32_t S>
|
||||||
|
Vector<typename std::common_type<T, U>::type, S> operator- (T parA, const Vector<U, S>& parB) {
|
||||||
|
return Vector<T, S>(parA) - parB;
|
||||||
|
}
|
||||||
|
template <typename T, typename U, uint32_t S>
|
||||||
|
Vector<typename std::common_type<T, U>::type, S> operator* (T parA, const Vector<U, S>& parB) {
|
||||||
|
return parB * parA;
|
||||||
|
}
|
||||||
|
template <typename T, typename U, uint32_t S>
|
||||||
|
Vector<typename std::common_type<T, U>::type, S> operator/ (T parA, const Vector<U, S>& parB) {
|
||||||
|
return Vector<T, S>(parA) / parB;
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
typedef typename std::common_type<T, U>::type RetType;
|
||||||
|
Vector<RetType, S> retVal;
|
||||||
|
for (uint32_t z = 0; z < S; ++z) {
|
||||||
|
retVal[z] = parA[z] + parB;
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
typedef typename std::common_type<T, U>::type RetType;
|
||||||
|
Vector<RetType, S> retVal;
|
||||||
|
for (uint32_t z = 0; z < S; ++z) {
|
||||||
|
retVal[z] = parA[z] - parB;
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
typedef typename std::common_type<T, U>::type RetType;
|
||||||
|
Vector<RetType, S> retVal;
|
||||||
|
for (uint32_t z = 0; z < S; ++z) {
|
||||||
|
retVal[z] = parA[z] * parB;
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
typedef typename std::common_type<T, U>::type RetType;
|
||||||
|
Vector<RetType, S> retVal;
|
||||||
|
for (uint32_t z = 0; z < S; ++z) {
|
||||||
|
retVal[z] = parA[z] / parB;
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
} //namespace cloonel
|
} //namespace cloonel
|
||||||
|
|
Loading…
Reference in a new issue