crap/include/vectors.hpp

120 lines
2.5 KiB
C++
Raw Normal View History

2015-12-10 07:25:23 -08:00
typedef Eigen::Vector2d _v2df;
typedef Eigen::Vector2f _v2sf;
typedef Eigen::Vector4f _v4sf;
template<typename T, typename Base>
struct Vector : public Aligned {
T v;
2015-12-10 07:25:23 -08:00
Vector()
{}
2015-12-10 07:25:23 -08:00
Vector(const Base &d)
{ v.setConstant(d); }
2015-12-10 07:25:23 -08:00
Vector(const Base &d0, const Base &d1)
{ v[0] = d0; v[1] = d1; }
2015-12-10 07:25:23 -08:00
Vector(const Base &d0, const Base &d1, const Base &d2, const Base &d3)
{ v[0] = d0; v[1] = d1; v[2] = d2; v[3] = d3; }
2015-06-06 17:25:18 -07:00
2015-12-10 07:25:23 -08:00
template<typename Derived>
Vector(const Eigen::ArrayBase<Derived> &v2)
//{ v = v2.cast<Base>(); } // FIXME
{ v = v2; }
2015-06-06 17:25:18 -07:00
2015-12-10 07:25:23 -08:00
template<typename Derived>
Vector(const Eigen::MatrixBase<Derived> &v2)
{ v = v2; }
2015-12-10 07:25:23 -08:00
friend inline Vector
operator-(const Vector &a)
{ return -a.v.array(); }
2015-12-10 07:25:23 -08:00
friend inline Vector
operator+(const Vector &a, const Vector &b)
{ return a.v.array() + b.v.array(); }
2015-12-10 07:25:23 -08:00
friend inline Vector
operator-(const Vector &a, const Vector &b)
{ return a.v.array() - b.v.array(); }
2015-06-06 17:25:18 -07:00
2015-12-10 07:25:23 -08:00
friend inline Vector
operator*(const Vector &a, const Vector &b)
{ return a.v.array() * b.v.array(); }
2015-06-06 17:25:18 -07:00
2015-12-10 07:25:23 -08:00
friend inline Vector
operator/(const Vector &a, const Vector &b)
{ return a.v.array() / b.v.array(); }
friend inline Vector
sqrt(const Vector &a)
{ return a.v.cwiseSqrt(); }
inline Vector &
operator+=(const Vector &a)
{ v.array() += a.v.array(); return *this; }
inline Vector &
operator-=(const Vector &a)
{ v.array() -= a.v.array(); return *this; }
inline Vector &
operator*=(const Vector &a)
{ v.array() *= a.v.array(); return *this; }
inline Vector &
operator/=(const Vector &a)
{ v.array() /= a.v.array(); return *this; }
/* unimplemented for now
friend inline Vector
operator&(const Vector &a, const Vector &b)
{}
friend inline Vector
operator|(const Vector &a, const Vector &b)
{}
friend inline Vector
operator^(const Vector &a, const Vector &b)
{}
friend inline Vector
andnot(const Vector &a, const Vector &b)
{}
*/
2015-12-10 07:25:23 -08:00
/*
friend inline Vector
operator<(const Vector &a, const Vector &b)
{ return a.v.array() < b.v.array(); }
2015-12-10 07:25:23 -08:00
friend inline Vector
operator>(const Vector &a, const Vector &b)
{ return a.v.array() > b.v.array(); }
2015-12-10 07:25:23 -08:00
friend inline Vector
operator==(const Vector &a, const Vector &b)
{ return a.v.array() == b.v.array(); }
*/
2015-12-10 07:25:23 -08:00
friend inline Vector
max(const Vector &a, const Vector &b)
{ return a.v.cwiseMax(b.v); }
2015-06-10 23:53:13 -07:00
2015-12-10 07:25:23 -08:00
inline Base &
2015-06-10 23:53:13 -07:00
operator[](int index) {
2015-12-10 07:25:23 -08:00
return v[index];
2015-06-10 23:53:13 -07:00
}
2015-12-10 07:25:23 -08:00
inline const Base &
2015-06-10 23:53:13 -07:00
operator[](int index) const {
2015-12-10 07:25:23 -08:00
return v[index];
2015-06-10 23:53:13 -07:00
}
};
2015-12-10 07:25:23 -08:00
typedef Vector<_v2df,double> v2df;
typedef Vector<_v2sf,float> v2sf;
typedef Vector<_v4sf,float> v4sf;