Add operators for scalar types and fix wrong operator<=
This commit is contained in:
parent
a7181f7a9b
commit
b2095603d1
3 changed files with 71 additions and 5 deletions
|
@ -165,6 +165,10 @@ namespace vwr {
|
|||
template <typename V2> VecBase& operator-= ( const VecBase<V2>& parOther );
|
||||
template <typename V2> VecBase& operator*= ( const VecBase<V2>& parOther );
|
||||
template <typename V2> VecBase& operator/= ( const VecBase<V2>& parOther );
|
||||
template <typename T> VecBase& operator+= ( const T& parOther );
|
||||
template <typename T> VecBase& operator-= ( const T& parOther );
|
||||
template <typename T> VecBase& operator*= ( const T& parOther );
|
||||
template <typename T> VecBase& operator/= ( const T& parOther );
|
||||
|
||||
private:
|
||||
vector_type m_wrapped;
|
||||
|
@ -409,6 +413,15 @@ namespace vwr {
|
|||
Vec<typename std::common_type<V1, V2>::type> operator* ( const Vec<V1>& parLeft, const Vec<V2>& parRight );
|
||||
template <typename V1, typename V2>
|
||||
Vec<typename std::common_type<V1, V2>::type> operator/ ( const Vec<V1>& parLeft, const Vec<V2>& parRight );
|
||||
|
||||
template <typename V1, typename T2>
|
||||
Vec<V1> operator+ ( Vec<V1> parLeft, const T2& parRight );
|
||||
template <typename V1, typename T2>
|
||||
Vec<V1> operator- ( Vec<V1> parLeft, const T2& parRight );
|
||||
template <typename V1, typename T2>
|
||||
Vec<V1> operator* ( Vec<V1> parLeft, const T2& parRight );
|
||||
template <typename V1, typename T2>
|
||||
Vec<V1> operator/ ( Vec<V1> parLeft, const T2& parRight );
|
||||
} //namespace vwr
|
||||
|
||||
#include "vectorwrapper/vectorwrapper.inl"
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace vwr {
|
|||
VecGetter<V>::get_at(m_wrapped, 1) = parY;
|
||||
|
||||
const scalar_type args[sizeof...(Args)] = {parArgs...};
|
||||
for (int z = 0; z < sizeof...(Args); ++z) {
|
||||
for (std::size_t z = 0; z < sizeof...(Args); ++z) {
|
||||
VecGetter<V>::get_at(m_wrapped, z + 2) = args[z];
|
||||
}
|
||||
}
|
||||
|
@ -132,6 +132,39 @@ namespace vwr {
|
|||
return *this;
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
template <typename T>
|
||||
VecBase<V>& VecBase<V>::operator+= (const T& parOther) {
|
||||
for (int z = 0; z < VectorWrapperInfo<V>::dimensions; ++z) {
|
||||
(*this)[z] += parOther;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
template <typename V>
|
||||
template <typename T>
|
||||
VecBase<V>& VecBase<V>::operator-= (const T& parOther) {
|
||||
for (int z = 0; z < VectorWrapperInfo<V>::dimensions; ++z) {
|
||||
(*this)[z] -= parOther;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
template <typename V>
|
||||
template <typename T>
|
||||
VecBase<V>& VecBase<V>::operator*= (const T& parOther) {
|
||||
for (int z = 0; z < VectorWrapperInfo<V>::dimensions; ++z) {
|
||||
(*this)[z] *= parOther;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
template <typename V>
|
||||
template <typename T>
|
||||
VecBase<V>& VecBase<V>::operator/= (const T& parOther) {
|
||||
for (int z = 0; z < VectorWrapperInfo<V>::dimensions; ++z) {
|
||||
(*this)[z] /= parOther;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename VectorWrapperInfo<T>::scalar_type& VecGetter<T, true>::get_at (T& parVec, std::size_t parIndex) {
|
||||
assert(parIndex < VectorWrapperInfo<T>::dimensions);
|
||||
|
@ -335,11 +368,11 @@ namespace vwr {
|
|||
|
||||
template <typename V1, typename T>
|
||||
inline bool operator> (const Vec<V1>& parLeft, const T& parRight) {
|
||||
return not (parLeft < parRight) and not (parLeft == parRight);
|
||||
return (parRight < parLeft);
|
||||
}
|
||||
template <typename V1, typename T>
|
||||
inline bool operator<= (const Vec<V1>& parLeft, const T& parRight) {
|
||||
return (parLeft < parRight) or (parLeft == parRight);
|
||||
return not (parRight < parLeft);
|
||||
}
|
||||
template <typename V1, typename T>
|
||||
inline bool operator>= (const Vec<V1>& parLeft, const T& parRight) {
|
||||
|
@ -386,4 +419,25 @@ namespace vwr {
|
|||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
template <typename V1, typename T2>
|
||||
inline Vec<V1> operator+ (Vec<V1> parLeft, const T2& parRight) {
|
||||
parLeft += parRight;
|
||||
return parLeft;
|
||||
}
|
||||
template <typename V1, typename T2>
|
||||
inline Vec<V1> operator- (Vec<V1> parLeft, const T2& parRight) {
|
||||
parLeft -= parRight;
|
||||
return parLeft;
|
||||
}
|
||||
template <typename V1, typename T2>
|
||||
inline Vec<V1> operator* (Vec<V1> parLeft, const T2& parRight) {
|
||||
parLeft *= parRight;
|
||||
return parLeft;
|
||||
}
|
||||
template <typename V1, typename T2>
|
||||
inline Vec<V1> operator/ (Vec<V1> parLeft, const T2& parRight) {
|
||||
parLeft /= parRight;
|
||||
return parLeft;
|
||||
}
|
||||
} //namespace vwr
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include "doorkeeper/primitivetypes.hpp"
|
||||
|
||||
|
||||
TEST(misc, vector) {
|
||||
typedef dk::Vector<2> coords2;
|
||||
typedef dk::Vector<8> coords8;
|
||||
|
@ -34,7 +33,7 @@ TEST(misc, vector) {
|
|||
{
|
||||
const coords8 small(1, 2, 3, 4, 5, 6, 7, 8);
|
||||
const coords8 big(small * 100);
|
||||
for (int z = 0; z < coords8::Dimension; ++z) {
|
||||
for (int z = 0; z < coords8::dimensions; ++z) {
|
||||
EXPECT_EQ(big[z], (z + 1) * 100);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue