VecMath.hpp   VecMath.hpp 
skipping to change at line 50 skipping to change at line 50
typedef Vector2<int> Vec2i; typedef Vector2<int> Vec2i;
//! @typedef Vec3d //! @typedef Vec3d
//! A 3d vector of doubles compatible with openGL. //! A 3d vector of doubles compatible with openGL.
typedef Vector3<double> Vec3d; typedef Vector3<double> Vec3d;
//! @typedef Vec3f //! @typedef Vec3f
//! A 3d vector of floats compatible with openGL. //! A 3d vector of floats compatible with openGL.
typedef Vector3<float> Vec3f; typedef Vector3<float> Vec3f;
//! @typedef Vec3i
//! A 3d vector of ints compatible with openGL.
typedef Vector3<int> Vec3i;
//! @typedef Vec4d //! @typedef Vec4d
//! A 4d vector of doubles compatible with openGL. //! A 4d vector of doubles compatible with openGL.
typedef Vector4<double> Vec4d; typedef Vector4<double> Vec4d;
//! @typedef Vec4f //! @typedef Vec4f
//! A 4d vector of floats compatible with openGL. //! A 4d vector of floats compatible with openGL.
typedef Vector4<float> Vec4f; typedef Vector4<float> Vec4f;
//! @typedef Vec4i //! @typedef Vec4i
//! A 4d vector of ints compatible with openGL. //! A 4d vector of ints compatible with openGL.
skipping to change at line 84 skipping to change at line 88
//! @typedef Mat3f //! @typedef Mat3f
//! A 3x3 matrix of floats compatible with openGL. //! A 3x3 matrix of floats compatible with openGL.
typedef Matrix3<float> Mat3f; typedef Matrix3<float> Mat3f;
//! @class Vector2 //! @class Vector2
//! A templatized 2d vector compatible with openGL. //! A templatized 2d vector compatible with openGL.
//! Use Vec2d or Vec2f typdef for vectors of double and float respectively. //! Use Vec2d or Vec2f typdef for vectors of double and float respectively.
template<class T> class Vector2 template<class T> class Vector2
{ {
public: public:
//! The vector is not initialized!
inline Vector2(); inline Vector2();
//! Sets all components of the vector to the same value
inline Vector2(T); inline Vector2(T);
//! Explicit conversion constructor from an array (copies values)
//! @warning Does not check array size, make sure it has at least 2
elements
inline explicit Vector2(const T*);
//! Explicit conversion constructor from another Vec2 of any type.
//! Uses default primitive type conversion
template <class T2> inline explicit Vector2(const Vector2<T2>&);
inline Vector2(T, T); inline Vector2(T, T);
inline Vector2& operator=(const T*); //! Assignment from array
//! @warning Does not check array size, make sure it has at least 2
elements
inline Vector2<T>& operator=(const T*);
inline void set(T, T); inline void set(T, T);
inline bool operator==(const Vector2<T>&) const; inline bool operator==(const Vector2<T>&) const;
inline bool operator!=(const Vector2<T>&) const; inline bool operator!=(const Vector2<T>&) const;
inline const T& operator[](int x) const; inline const T& operator[](int x) const;
inline T& operator[](int); inline T& operator[](int);
inline operator const T*() const; inline operator const T*() const;
inline operator T*(); inline operator T*();
inline void operator+=(const Vector2<T>&); inline Vector2<T>& operator+=(const Vector2<T>&);
inline void operator-=(const Vector2<T>&); inline Vector2<T>& operator-=(const Vector2<T>&);
inline void operator*=(T); //! Scalar multiplication
inline void operator/=(T); inline Vector2<T>& operator*=(T);
//! Component-wise multiplication
inline Vector2 operator-(const Vector2<T>&) const; inline Vector2<T>& operator*=(const Vector2<T>&);
inline Vector2 operator+(const Vector2<T>&) const; //! Scalar division
inline Vector2<T>& operator/=(T);
inline Vector2 operator-() const; //! Component-wise division
inline Vector2 operator+() const; inline Vector2<T>& operator/=(const Vector2<T>&);
inline Vector2 operator*(T) const; inline Vector2<T> operator-(const Vector2<T>&) const;
inline Vector2 operator/(T) const; inline Vector2<T> operator+(const Vector2<T>&) const;
inline Vector2<T> operator-() const;
inline Vector2<T> operator+() const;
//! Scalar multiplication
inline Vector2<T> operator*(T) const;
//! Component-wise multiplication
inline Vector2<T> operator*(const Vector2<T>&) const;
//! Scalar division
inline Vector2<T> operator/(T) const;
//! Component-wise division
inline Vector2<T> operator/(const Vector2<T>&) const;
//! Component-wise minimum determination
inline Vector2<T> min(const Vector2<T>&) const;
//! Component-wise maximum determination
inline Vector2<T> max(const Vector2<T>&) const;
//! Component-wise clamping to the specified upper and lower bounds
inline Vector2<T> clamp(const Vector2<T>& low, const Vector2<T>& hig
h) const;
inline T dot(const Vector2<T>&) const; inline T dot(const Vector2<T>&) const;
inline T length() const; inline T length() const;
inline T lengthSquared() const; inline T lengthSquared() const;
inline void normalize(); inline void normalize();
T v[2]; T v[2];
QString toString() const {return QString("[%1, %2]").arg(v[0]).arg(v
[1]);}
}; };
//! @class Vector3 //! @class Vector3
//! A templatized 3d vector compatible with openGL. //! A templatized 3d vector compatible with openGL.
//! Use Vec3d or Vec3f typdef for vectors of double and float respectively. //! Use Vec3d or Vec3f typdef for vectors of double and float respectively.
template<class T> class Vector3 template<class T> class Vector3
{ {
public: public:
//! The vector is not initialized!
inline Vector3(); inline Vector3();
//inline Vector3(const Vector3&); //! Sets all components of the vector to the same value
//template <class T2> inline Vector3(const Vector3<T2>&);
inline Vector3(T, T, T);
inline Vector3(T); inline Vector3(T);
//! Explicit conversion constructor from an array (copies values)
//! @warning Does not check array size, make sure it has at least 3
elements
inline explicit Vector3(const T*);
inline Vector3(T, T, T);
//inline Vector3& operator=(const Vector3&); //inline Vector3& operator=(const Vector3&);
//! Assignment from array
//! @warning Does not check array size, make sure it has at least 2
elements
inline Vector3& operator=(const T*); inline Vector3& operator=(const T*);
//template <class T2> inline Vector3& operator=(const Vector3<T2>&); //template <class T2> inline Vector3& operator=(const Vector3<T2>&);
inline void set(T, T, T); inline void set(T, T, T);
inline bool operator==(const Vector3<T>&) const; inline bool operator==(const Vector3<T>&) const;
inline bool operator!=(const Vector3<T>&) const; inline bool operator!=(const Vector3<T>&) const;
//! allows for a fuzzy comparison using some epsilon value //! allows for a fuzzy comparison using some epsilon value
inline bool fuzzyEquals(const Vector3<T>&, T epsilon = std::numeric_ limits<T>::epsilon()) const; inline bool fuzzyEquals(const Vector3<T>&, T epsilon = std::numeric_ limits<T>::epsilon()) const;
inline T& operator[](int); inline T& operator[](int);
skipping to change at line 200 skipping to change at line 241
QString toString() const {return QString("[%1, %2, %3]").arg(v[0]).a rg(v[1]).arg(v[2]);} QString toString() const {return QString("[%1, %2, %3]").arg(v[0]).a rg(v[1]).arg(v[2]);}
QString toStringLonLat() const {return QString("[") + QString::numbe r(longitude()*180./M_PI, 'g', 12) + "," + QString::number(latitude()*180./M _PI, 'g', 12)+"]";} QString toStringLonLat() const {return QString("[") + QString::numbe r(longitude()*180./M_PI, 'g', 12) + "," + QString::number(latitude()*180./M _PI, 'g', 12)+"]";}
}; };
//! @class Vector4 //! @class Vector4
//! A templatized 4d vector compatible with openGL. //! A templatized 4d vector compatible with openGL.
//! Use Vec4d or Vec4f typdef for vectors of double and float respectively. //! Use Vec4d or Vec4f typdef for vectors of double and float respectively.
template<class T> class Vector4 template<class T> class Vector4
{ {
public: public:
//! The vector is not initialized!
inline Vector4(); inline Vector4();
//! Explicit conversion constructor from an array
//! @warning Does not check array size, make sure it has at least 4
elements
inline explicit Vector4(const T*);
//! Creates an Vector4 with xyz set to the given Vector3, and w set
to 1.0
inline Vector4(const Vector3<T>&); inline Vector4(const Vector3<T>&);
//! Creates an Vector4 with xyz set to the given values, and w set t o 1.0
inline Vector4(T, T, T); inline Vector4(T, T, T);
inline Vector4(T, T, T, T); inline Vector4(T, T, T, T);
inline Vector4& operator=(const Vector3<T>&); inline Vector4& operator=(const Vector3<T>&);
inline Vector4& operator=(const T*); inline Vector4& operator=(const T*);
inline void set(T, T, T, T); inline void set(T, T, T, T);
inline bool operator==(const Vector4<T>&) const; inline bool operator==(const Vector4<T>&) const;
inline bool operator!=(const Vector4<T>&) const; inline bool operator!=(const Vector4<T>&) const;
skipping to change at line 396 skipping to change at line 443
////////////////////////// Vector2 class methods ////////////////////////// ///// ////////////////////////// Vector2 class methods ////////////////////////// /////
template<class T> Vector2<T>::Vector2() {} template<class T> Vector2<T>::Vector2() {}
template<class T> Vector2<T>::Vector2(T x) template<class T> Vector2<T>::Vector2(T x)
{ {
v[0]=x; v[1]=x; v[0]=x; v[1]=x;
} }
template<class T> Vector2<T>::Vector2(const T* x)
{
v[0]=x[0]; v[1]=x[1];
}
template <class T> template <class T2> Vector2<T>::Vector2(const Vector2<T2
>& other)
{
v[0]=other[0]; v[1]=other[1];
}
template<class T> Vector2<T>::Vector2(T x, T y) template<class T> Vector2<T>::Vector2(T x, T y)
{ {
v[0]=x; v[1]=y; v[0]=x; v[1]=y;
} }
template<class T> Vector2<T>& Vector2<T>::operator=(const T* a) template<class T> Vector2<T>& Vector2<T>::operator=(const T* a)
{ {
v[0]=a[0]; v[1]=a[1]; v[0]=a[0]; v[1]=a[1];
return *this; return *this;
} }
skipping to change at line 442 skipping to change at line 499
template<class T> Vector2<T>::operator const T*() const template<class T> Vector2<T>::operator const T*() const
{ {
return v; return v;
} }
template<class T> Vector2<T>::operator T*() template<class T> Vector2<T>::operator T*()
{ {
return v; return v;
} }
template<class T> void Vector2<T>::operator+=(const Vector2<T>& a) template<class T> Vector2<T>& Vector2<T>::operator+=(const Vector2<T>& a)
{ {
v[0] += a.v[0]; v[1] += a.v[1]; v[0] += a.v[0]; v[1] += a.v[1];
return *this;
} }
template<class T> void Vector2<T>::operator-=(const Vector2<T>& a) template<class T> Vector2<T>& Vector2<T>::operator-=(const Vector2<T>& a)
{ {
v[0] -= a.v[0]; v[1] -= a.v[1]; v[0] -= a.v[0]; v[1] -= a.v[1];
return *this;
} }
template<class T> void Vector2<T>::operator*=(T s) template<class T> Vector2<T>& Vector2<T>::operator*=(T s)
{ {
v[0] *= s; v[1] *= s; v[0] *= s; v[1] *= s;
return *this;
}
template<class T> Vector2<T>& Vector2<T>::operator*=(const Vector2<T>& b)
{
v[0] *= b.v[0]; v[1] *= b.v[1];
return *this;
} }
template<class T> void Vector2<T>::operator/=(T s) template<class T> Vector2<T>& Vector2<T>::operator/=(T s)
{ {
v[0] /= s; v[1] /= s; v[0] /= s; v[1] /= s;
return *this;
}
template<class T> Vector2<T>& Vector2<T>::operator/=(const Vector2<T>& b)
{
v[0] /= b.v[0]; v[1] /= b.v[1];
return *this;
} }
template<class T> Vector2<T> Vector2<T>::operator-() const template<class T> Vector2<T> Vector2<T>::operator-() const
{ {
return Vector2<T>(-v[0], -v[1]); return Vector2<T>(-v[0], -v[1]);
} }
template<class T> Vector2<T> Vector2<T>::operator+() const template<class T> Vector2<T> Vector2<T>::operator+() const
{ {
return *this; return *this;
skipping to change at line 487 skipping to change at line 560
template<class T> Vector2<T> Vector2<T>::operator-(const Vector2<T>& b) con st template<class T> Vector2<T> Vector2<T>::operator-(const Vector2<T>& b) con st
{ {
return Vector2<T>(v[0] - b.v[0], v[1] - b.v[1]); return Vector2<T>(v[0] - b.v[0], v[1] - b.v[1]);
} }
template<class T> Vector2<T> Vector2<T>::operator*(T s) const template<class T> Vector2<T> Vector2<T>::operator*(T s) const
{ {
return Vector2<T>(s * v[0], s * v[1]); return Vector2<T>(s * v[0], s * v[1]);
} }
template<class T> Vector2<T> Vector2<T>::operator*(const Vector2<T>& b) con
st
{
return Vector2<T>(v[0] * b.v[0], v[1] * b.v[1]);
}
template<class T> Vector2<T> Vector2<T>::operator/(T s) const template<class T> Vector2<T> Vector2<T>::operator/(T s) const
{ {
return Vector2<T>(v[0]/s, v[1]/s); return Vector2<T>(v[0]/s, v[1]/s);
} }
template<class T> Vector2<T> Vector2<T>::operator/(const Vector2<T>& b) con
st
{
return Vector2<T>(v[0]/b.v[0], v[1]/b.v[1]);
}
template<class T> Vector2<T> Vector2<T>::min(const Vector2<T>& b) const
{
return Vector2<T>(std::min(v[0],b.v[0]), std::min(v[1],b.v[1]));
}
template<class T> Vector2<T> Vector2<T>::max(const Vector2<T>& b) const
{
return Vector2<T>(std::max(v[0],b.v[0]), std::max(v[1],b.v[1]));
}
template<class T> Vector2<T> Vector2<T>::clamp(const Vector2<T>& low, const
Vector2<T>& high) const
{
return this->max(low).min(high);
}
template<class T> T Vector2<T>::dot(const Vector2<T>& b) const template<class T> T Vector2<T>::dot(const Vector2<T>& b) const
{ {
return v[0] * b.v[0] + v[1] * b.v[1]; return v[0] * b.v[0] + v[1] * b.v[1];
} }
template<class T> T Vector2<T>::length() const template<class T> T Vector2<T>::length() const
{ {
return (T) std::sqrt(v[0] * v[0] + v[1] * v[1]); return (T) std::sqrt(v[0] * v[0] + v[1] * v[1]);
} }
skipping to change at line 538 skipping to change at line 636
//template<class T> template<class T2> Vector3<T>::Vector3(const Vector3<T2 >& a) //template<class T> template<class T2> Vector3<T>::Vector3(const Vector3<T2 >& a)
//{ //{
// v[0]=a.v[0]; v[1]=a.v[1]; v[2]=a.v[2]; // v[0]=a.v[0]; v[1]=a.v[1]; v[2]=a.v[2];
//} //}
template<class T> Vector3<T>::Vector3(T x) template<class T> Vector3<T>::Vector3(T x)
{ {
v[0]=x; v[1]=x; v[2]=x; v[0]=x; v[1]=x; v[2]=x;
} }
template<class T> Vector3<T>::Vector3(const T* x)
{
v[0]=x[0]; v[1]=x[1]; v[2]=x[2];
}
template<class T> Vector3<T>::Vector3(T x, T y, T z) template<class T> Vector3<T>::Vector3(T x, T y, T z)
{ {
v[0]=x; v[1]=y; v[2]=z; v[0]=x; v[1]=y; v[2]=z;
} }
//template<class T> Vector3<T>& Vector3<T>::operator=(const Vector3& a) //template<class T> Vector3<T>& Vector3<T>::operator=(const Vector3& a)
//{ //{
// v[0]=a.v[0]; v[1]=a.v[1]; v[2]=a.v[2]; // v[0]=a.v[0]; v[1]=a.v[1]; v[2]=a.v[2];
// return *this; // return *this;
//} //}
skipping to change at line 740 skipping to change at line 843
// Return longitude in rad // Return longitude in rad
template<class T> T Vector3<T>::longitude() const template<class T> T Vector3<T>::longitude() const
{ {
return std::atan2(v[1],v[0]); return std::atan2(v[1],v[0]);
} }
////////////////////////// Vector4 class methods ////////////////////////// ///// ////////////////////////// Vector4 class methods ////////////////////////// /////
template<class T> Vector4<T>::Vector4() {} template<class T> Vector4<T>::Vector4() {}
template<class T> Vector4<T>::Vector4(const T* x)
{
v[0]=x[0]; v[1]=x[1]; v[2]=x[2]; v[3]=x[3];
}
template<class T> Vector4<T>::Vector4(const Vector3<T>& a) template<class T> Vector4<T>::Vector4(const Vector3<T>& a)
{ {
v[0]=a.v[0]; v[1]=a.v[1]; v[2]=a.v[2]; v[3]=1; v[0]=a.v[0]; v[1]=a.v[1]; v[2]=a.v[2]; v[3]=1;
} }
template<class T> Vector4<T>::Vector4(T x, T y, T z) template<class T> Vector4<T>::Vector4(T x, T y, T z)
{ {
v[0]=x; v[1]=y; v[2]=z; v[3]=1; v[0]=x; v[1]=y; v[2]=z; v[3]=1;
} }
skipping to change at line 1562 skipping to change at line 1670
{ {
return Vector4<T>(s*v[0],s*v[1],s*v[2],s*v[3]); return Vector4<T>(s*v[0],s*v[1],s*v[2],s*v[3]);
} }
//Make Qt handle the classes as primitive type. This optimizes performance with Qt's container classes //Make Qt handle the classes as primitive type. This optimizes performance with Qt's container classes
Q_DECLARE_TYPEINFO(Vec2d, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(Vec2d, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(Vec2f, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(Vec2f, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(Vec2i, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(Vec2i, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(Vec3d, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(Vec3d, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(Vec3f, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(Vec3f, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(Vec3i, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(Vec4d, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(Vec4d, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(Vec4f, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(Vec4f, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(Vec4i, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(Vec4i, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(Mat4d, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(Mat4d, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(Mat4f, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(Mat4f, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(Mat3d, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(Mat3d, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(Mat3f, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(Mat3f, Q_PRIMITIVE_TYPE);
//Declare meta-type information so that Vec/Mat classes can be used in QVar iant //Declare meta-type information so that Vec/Mat classes can be used in QVar iant
//They are registered (qRegisterMetaType) in StelCore::registerMathMetaType s, called in constructor //They are registered (qRegisterMetaType) in StelCore::registerMathMetaType s, called in constructor
Q_DECLARE_METATYPE(Vec2d) Q_DECLARE_METATYPE(Vec2d)
Q_DECLARE_METATYPE(Vec2f) Q_DECLARE_METATYPE(Vec2f)
Q_DECLARE_METATYPE(Vec2i) Q_DECLARE_METATYPE(Vec2i)
Q_DECLARE_METATYPE(Vec3d) Q_DECLARE_METATYPE(Vec3d)
Q_DECLARE_METATYPE(Vec3f) Q_DECLARE_METATYPE(Vec3f)
Q_DECLARE_METATYPE(Vec3i)
Q_DECLARE_METATYPE(Vec4d) Q_DECLARE_METATYPE(Vec4d)
Q_DECLARE_METATYPE(Vec4f) Q_DECLARE_METATYPE(Vec4f)
Q_DECLARE_METATYPE(Vec4i) Q_DECLARE_METATYPE(Vec4i)
Q_DECLARE_METATYPE(Mat4d) Q_DECLARE_METATYPE(Mat4d)
Q_DECLARE_METATYPE(Mat4f) Q_DECLARE_METATYPE(Mat4f)
Q_DECLARE_METATYPE(Mat3d) Q_DECLARE_METATYPE(Mat3d)
Q_DECLARE_METATYPE(Mat3f) Q_DECLARE_METATYPE(Mat3f)
template <class T>
QDebug operator<<(QDebug debug, const Vector2<T> &c)
{
QDebugStateSaver saver(debug);
debug.nospace() << '[' << c[0] << ", " << c[1] << ']';
return debug;
}
template <class T>
QDebug operator<<(QDebug debug, const Vector3<T> &c)
{
QDebugStateSaver saver(debug);
debug.nospace() << '[' << c[0] << ", " << c[1] << ", " << c[2] << ']';
return debug;
}
template <class T>
QDebug operator<<(QDebug debug, const Vector4<T> &c)
{
QDebugStateSaver saver(debug);
debug.nospace() << '[' << c[0] << ", " << c[1] << ", " << c[2] << ", "
<< c[3] << ']';
return debug;
}
//! Provide Qt 3x3 matrix-vector multiplication, which does not exist for s ome reason //! Provide Qt 3x3 matrix-vector multiplication, which does not exist for s ome reason
inline QVector3D operator*(const QMatrix3x3& mat, const QVector3D& vec) inline QVector3D operator*(const QMatrix3x3& mat, const QVector3D& vec)
{ {
float x,y,z; float x,y,z;
x = vec.x() * mat(0,0) + x = vec.x() * mat(0,0) +
vec.y() * mat(0,1) + vec.y() * mat(0,1) +
vec.z() * mat(0,2); vec.z() * mat(0,2);
y = vec.x() * mat(1,0) + y = vec.x() * mat(1,0) +
vec.y() * mat(1,1) + vec.y() * mat(1,1) +
vec.z() * mat(1,2); vec.z() * mat(1,2);
 End of changes. 30 change blocks. 
21 lines changed or deleted 171 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/