cctw  0.2.1
cctwvector3d.h
Go to the documentation of this file.
1 #ifndef CCTWVECTOR3D_H
2 #define CCTWVECTOR3D_H
3 
4 #include <QSettings>
5 #include <QString>
6 #include <QScriptable>
7 
8 template <typename T>
10 {
11 public:
12  CctwVector3D(T x, T y, T z);
13  template <typename T2> CctwVector3D(const CctwVector3D<T2> &v);
14  CctwVector3D();
15 
16 public:
17  T x() const { return m_Vector[0]; }
18  T y() const { return m_Vector[1]; }
19  T z() const { return m_Vector[2]; }
20  T& x() { return m_Vector[0]; }
21  T& y() { return m_Vector[1]; }
22  T& z() { return m_Vector[2]; }
23 
24  T& operator () (int i) { return m_Vector[i]; }
25  const T& operator() (int i) const { return m_Vector[i]; }
26 
31 
34 
35  CctwVector3D<T> operator + (const T val) const;
36  CctwVector3D<T> operator - (const T val) const;
37  CctwVector3D<T> operator * (const T val) const;
38  CctwVector3D<T> operator / (const T val) const;
39 
40  bool operator == (const CctwVector3D<T> &vec) const;
41  bool operator != (const CctwVector3D<T> &vec) const;
42  bool operator > (const CctwVector3D<T> &vec) const;
43  bool operator < (const CctwVector3D<T> &vec) const;
44  bool operator >= (const CctwVector3D<T> &vec) const;
45  bool operator <= (const CctwVector3D<T> &vec) const;
46 
47  T length() const;
48  T lengthSquared() const;
49  T volume() const;
50 
52  void normalize();
53 
54  static T dotProduct(const CctwVector3D<T>& v1, const CctwVector3D<T>& v2);
55  static CctwVector3D<T> crossProduct(const CctwVector3D<T> &v1, const CctwVector3D<T> &v2);
56  static CctwVector3D<T> normal(const CctwVector3D<T>& v1, const CctwVector3D<T>& v2);
57 
58  CctwVector3D<T> min(const CctwVector3D<T> &vec) const;
59  CctwVector3D<T> max(const CctwVector3D<T> &vec) const;
60 
61  void setSettingsValue(QSettings *settings, QString name);
62  static void customSaver(const QVariant &val, QSettings *settings, QString name);
63 
64  QString toString();
65 
66 protected:
67  T m_Vector[3];
68 };
69 
72 
73 Q_DECLARE_METATYPE(CctwIntVector3D)
74 Q_DECLARE_METATYPE(CctwDoubleVector3D)
75 
76 #endif // CCTWVECTOR3D_H
QString toString()
CctwVector3D< T > operator/(const CctwVector3D< T > &vec) const
bool operator!=(const CctwVector3D< T > &vec) const
static CctwVector3D< T > normal(const CctwVector3D< T > &v1, const CctwVector3D< T > &v2)
T x() const
Definition: cctwvector3d.h:17
bool operator==(const CctwVector3D< T > &vec) const
CctwVector3D< T > operator*(const CctwVector3D< T > &vec) const
CctwVector3D< T > operator-(const CctwVector3D< T > &vec) const
CctwVector3D< T > operator+(const CctwVector3D< T > &vec) const
bool operator>=(const CctwVector3D< T > &vec) const
T lengthSquared() const
T length() const
T z() const
Definition: cctwvector3d.h:19
CctwVector3D< int > CctwIntVector3D
Definition: cctwvector3d.h:70
static T dotProduct(const CctwVector3D< T > &v1, const CctwVector3D< T > &v2)
T & operator()(int i)
Definition: cctwvector3d.h:24
CctwVector3D< T > normalized() const
static CctwVector3D< T > crossProduct(const CctwVector3D< T > &v1, const CctwVector3D< T > &v2)
CctwVector3D< T > min(const CctwVector3D< T > &vec) const
void setSettingsValue(QSettings *settings, QString name)
T volume() const
CctwVector3D< T > operator-=(const CctwVector3D< T > &vec)
static void customSaver(const QVariant &val, QSettings *settings, QString name)
T y() const
Definition: cctwvector3d.h:18
CctwVector3D< double > CctwDoubleVector3D
Definition: cctwvector3d.h:71
CctwVector3D< T > operator+=(const CctwVector3D< T > &vec)
CctwVector3D< T > max(const CctwVector3D< T > &vec) const
bool operator>(const CctwVector3D< T > &vec) const