Browse Source

specialized vector2d and vector3d instead of inheritance

develop
Robin Thoni 7 years ago
parent
commit
a6fe07eaf2

+ 17
- 15
UGameEngine/utils/vector2d.cpp View File

@@ -1,24 +1,30 @@
1 1
 #include "vector2d.h"
2 2
 
3
+VectorXD<2>::VectorXD()
4
+{
5
+    _scalars[0] = 0.0;
6
+    _scalars[1] = 0.0;
7
+}
3 8
 
4
-Vector2D::Vector2D(double x, double y)
5
-    : VectorXD<2>()
9
+VectorXD<2>::VectorXD(const double scalars[2])
6 10
 {
7
-    _scalars[0] = x;
8
-    _scalars[1] = y;
11
+    _scalars[0] = scalars[0];
12
+    _scalars[1] = scalars[1];
9 13
 }
10 14
 
11
-Vector2D::Vector2D(const Vector2D &other)
12
-    : VectorXD<2>(other)
15
+Vector2D::VectorXD(double x, double y)
13 16
 {
17
+    _scalars[0] = x;
18
+    _scalars[1] = y;
14 19
 }
15 20
 
16
-Vector2D::Vector2D(const VectorXD<2> &other)
17
-    : VectorXD<2>(other)
21
+Vector2D::VectorXD(const VectorXD<2> &other)
18 22
 {
23
+    _scalars[0] = other._scalars[0];
24
+    _scalars[1] = other._scalars[1];
19 25
 }
20 26
 
21
-Vector2D::~Vector2D()
27
+Vector2D::~VectorXD()
22 28
 {
23 29
 }
24 30
 
@@ -45,16 +51,12 @@ Vector2D& Vector2D::setY(double y)
45 51
 
46 52
 Vector2D &Vector2D::add(double x, double y)
47 53
 {
48
-    _scalars[0] += x;
49
-    _scalars[1] += y;
50
-    return *this;
54
+    return add(Vector2D(x, y));
51 55
 }
52 56
 
53 57
 Vector2D &Vector2D::sub(double x, double y)
54 58
 {
55
-    _scalars[0] -= x;
56
-    _scalars[1] -= y;
57
-    return *this;
59
+    return sub(Vector2D(x, y));
58 60
 }
59 61
 
60 62
 double Vector2D::dotProduct(double x, double y) const

+ 11
- 8
UGameEngine/utils/vector2d.h View File

@@ -3,13 +3,16 @@
3 3
 
4 4
 #include "vectorxd.h"
5 5
 
6
-class Vector2D : public VectorXD<2>
6
+typedef VectorXD<2> Vector2D;
7
+
8
+template<> class VectorXD<2> : public GenericVector<2, VectorXD<2> >
7 9
 {
8 10
 public:
9
-    explicit Vector2D(double x = 0.0, double y = 0.0);
10
-    Vector2D(const Vector2D& other);
11
-    Vector2D(const VectorXD<2>& other);
12
-    virtual ~Vector2D();
11
+    VectorXD<2>();
12
+    VectorXD<2>(const double scalars[2]);
13
+    VectorXD<2>(double x, double y);
14
+    VectorXD<2>(const VectorXD<2>& other);
15
+    virtual ~VectorXD<2>();
13 16
 
14 17
     double getX() const;
15 18
     Vector2D& setX(double x);
@@ -17,13 +20,13 @@ public:
17 20
     double getY() const;
18 21
     Vector2D& setY(double y);
19 22
 
20
-    using VectorXD<2>::add;
23
+    using GenericVector<2, VectorXD<2> >::add;
21 24
     Vector2D& add(double x, double y);
22 25
 
23
-    using VectorXD<2>::sub;
26
+    using GenericVector<2, VectorXD<2> >::sub;
24 27
     Vector2D& sub(double x, double y);
25 28
 
26
-    using VectorXD<2>::dotProduct;
29
+    using GenericVector<2, VectorXD<2> >::dotProduct;
27 30
     double dotProduct(double x, double y) const;
28 31
 };
29 32
 

+ 20
- 10
UGameEngine/utils/vector3d.cpp View File

@@ -1,25 +1,35 @@
1 1
 #include "vector3d.h"
2 2
 #include <math.h>
3 3
 
4
-Vector3D::Vector3D(double x, double y, double z)
5
-    : VectorXD<3>()
4
+Vector3D::VectorXD()
6 5
 {
7
-    _scalars[0] = x;
8
-    _scalars[1] = y;
9
-    _scalars[2] = z;
6
+    _scalars[0] = 0.0;
7
+    _scalars[1] = 0.0;
8
+    _scalars[2] = 0.0;
10 9
 }
11 10
 
12
-Vector3D::Vector3D(const Vector3D &other)
13
-    : VectorXD<3>(other)
11
+Vector3D::VectorXD(const double scalars[3])
14 12
 {
13
+    _scalars[0] = scalars[0];
14
+    _scalars[1] = scalars[1];
15
+    _scalars[2] = scalars[2];
16
+}
17
+
18
+Vector3D::VectorXD(double x, double y, double z)
19
+{
20
+    _scalars[0] = x;
21
+    _scalars[1] = y;
22
+    _scalars[2] = z;
15 23
 }
16 24
 
17
-Vector3D::Vector3D(const VectorXD<3> &other)
18
-    : VectorXD<3>(other)
25
+Vector3D::VectorXD(const Vector3D &other)
19 26
 {
27
+    _scalars[0] = other._scalars[0];
28
+    _scalars[1] = other._scalars[1];
29
+    _scalars[2] = other._scalars[2];
20 30
 }
21 31
 
22
-Vector3D::~Vector3D()
32
+Vector3D::~VectorXD()
23 33
 {
24 34
 }
25 35
 

+ 11
- 8
UGameEngine/utils/vector3d.h View File

@@ -3,13 +3,16 @@
3 3
 
4 4
 #include "vectorxd.h"
5 5
 
6
-class Vector3D: public VectorXD<3>
6
+typedef VectorXD<3> Vector3D;
7
+
8
+template<> class VectorXD<3>: public GenericVector<3, VectorXD<3> >
7 9
 {
8 10
 public:
9
-    explicit Vector3D(double x = 0.0, double y = 0.0, double z = 0.0);
10
-    Vector3D(const Vector3D& other);
11
-    Vector3D(const VectorXD<3>& other);
12
-    virtual ~Vector3D();
11
+    VectorXD<3>();
12
+    VectorXD<3>(const double scalars[3]);
13
+    VectorXD<3>(double x, double y, double z);
14
+    VectorXD<3>(const Vector3D& other);
15
+    virtual ~VectorXD<3>();
13 16
 
14 17
     double getX() const;
15 18
     Vector3D& setX(double x);
@@ -20,13 +23,13 @@ public:
20 23
     double getZ() const;
21 24
     Vector3D& setZ(double z);
22 25
 
23
-    using VectorXD<3>::add;
26
+    using GenericVector<3, VectorXD<3> >::add;
24 27
     Vector3D& add(double x, double y, double z);
25 28
 
26
-    using VectorXD<3>::sub;
29
+    using GenericVector<3, VectorXD<3> >::sub;
27 30
     Vector3D& sub(double x, double y, double z);
28 31
 
29
-    using VectorXD<3>::dotProduct;
32
+    using GenericVector<3, VectorXD<3> >::dotProduct;
30 33
     double dotProduct(double x, double y, double z) const;
31 34
 };
32 35
 

+ 53
- 42
UGameEngine/utils/vectorxd.h View File

@@ -3,68 +3,65 @@
3 3
 
4 4
 #include <QDebug>
5 5
 
6
-#define tmpl template<unsigned X>
6
+#define tmplx template<unsigned X>
7
+#define tmpl template<unsigned X, class T>
7 8
 
8
-tmpl class VectorXD
9
+tmpl class GenericVector
9 10
 {
10 11
 public:
11
-    VectorXD();
12
-    VectorXD(const double scalars[X]);
13
-    VectorXD(const VectorXD<X>& other);
14 12
 
15
-    VectorXD<X>& setScalar(unsigned i, double value);
13
+    T& setScalar(unsigned i, double value);
16 14
     double getScalar(unsigned i) const;
17 15
 
18 16
     bool isNull() const;
19 17
 
20
-    bool equal(const VectorXD<X>& other) const;
21
-
22
-    VectorXD<X>& add(double k);
23
-    VectorXD<X>& add(double scalars[X]);
24
-    VectorXD<X>& add(const VectorXD<X>& other);
18
+    bool equal(const T& other) const;
25 19
 
26
-    VectorXD<X>& sub(double k);
27
-    VectorXD<X>& sub(double scalars[X]);
28
-    VectorXD<X>& sub(const VectorXD<X>& other);
20
+    T& add(double k);
21
+    T& add(double scalars[X]);
22
+    T& add(const T& other);
29 23
 
30
-    VectorXD<X>& mult(double k);
31
-    VectorXD<X>& mult(double scalars[X]);
32
-    VectorXD<X>& mult(const VectorXD<X>& k);
24
+    T& sub(double k);
25
+    T& sub(double scalars[X]);
26
+    T& sub(const T& other);
33 27
 
34
-    VectorXD<X>& div(double k);
35
-    VectorXD<X>& div(double scalars[X]);
36
-    VectorXD<X>& div(const VectorXD<X>& k);
28
+    T& mult(double k);
29
+    T& mult(double scalars[X]);
30
+    T& mult(const T& k);
37 31
 
32
+    T& div(double k);
33
+    T& div(double scalars[X]);
34
+    T& div(const T& k);
38 35
 
39
-    double dotProduct(const VectorXD<X>& other) const;
36
+    double dotProduct(const T& other) const;
40 37
 
41
-    VectorXD<X>& crossProduct(const VectorXD<X>& other);
42
-    static VectorXD<X> crossProduct(const VectorXD<X> &v1, const VectorXD<X> &v2);
38
+    T& crossProduct(const T& other);
39
+    static T crossProduct(const T &v1, const T &v2);
43 40
 
44 41
     double norm() const;
45 42
 
46
-    VectorXD<X> operator+() const;
47
-    VectorXD<X> operator+(const double& k) const;
48
-    VectorXD<X>& operator+=(const double& k);
49
-    VectorXD<X> operator+(const VectorXD<X>& other) const;
50
-    VectorXD<X>& operator+=(const VectorXD<X>& other);
43
+    T operator+() const;
44
+    T operator+(const double& k) const;
45
+    T& operator+=(const double& k);
46
+    T operator+(const T& other) const;
47
+    T& operator+=(const T& other);
51 48
 
52
-    VectorXD<X> operator-() const;
53
-    VectorXD<X> operator-(const double& k) const;
54
-    VectorXD<X>& operator-=(const double& k);
55
-    VectorXD<X> operator-(const VectorXD<X>& other) const;
56
-    VectorXD<X>& operator-=(const VectorXD<X>& other);
49
+    T operator-() const;
50
+    T operator-(const double& k) const;
51
+    T& operator-=(const double& k);
52
+    T operator-(const T& other) const;
53
+    T& operator-=(const T& other);
57 54
 
58
-    VectorXD<X> operator*(const double& k) const;
59
-    VectorXD<X>& operator*=(const double& k);
60
-    VectorXD<X> operator*(const VectorXD<X>& other) const;
61
-    VectorXD<X>& operator*=(const VectorXD<X>& other);
55
+    T operator*(const double& k) const;
56
+    T& operator*=(const double& k);
57
+    T operator*(const T& other) const;
58
+    T& operator*=(const T& other);
62 59
 
63
-    VectorXD<X> operator/(const double& k) const;
64
-    VectorXD<X>& operator/=(const double& k);
60
+    T operator/(const double& k) const;
61
+    T& operator/=(const double& k);
65 62
 
66
-    bool operator==(const VectorXD<X>& other) const;
67
-    bool operator!=(const VectorXD<X>& other) const;
63
+    bool operator==(const T& other) const;
64
+    bool operator!=(const T& other) const;
68 65
 
69 66
     double operator[](unsigned i) const;
70 67
 
@@ -73,9 +70,23 @@ public:
73 70
 
74 71
 protected:
75 72
     double _scalars[X];
73
+
74
+private:
75
+    T* getThis() const;
76
+};
77
+
78
+tmplx class VectorXD: public GenericVector<X, VectorXD<X> >
79
+{
80
+public:
81
+    VectorXD();
82
+    VectorXD(const double scalars[X]);
83
+    VectorXD(const VectorXD<X>& other);
84
+
85
+protected:
86
+    using GenericVector<X, VectorXD<X> >::_scalars;
76 87
 };
77 88
 
78
-tmpl QDebug operator<<(QDebug dbg, const VectorXD<X>& v);
89
+tmplx QDebug operator<<(QDebug dbg, const VectorXD<X>& v);
79 90
 
80 91
 #include "vectorxd.hxx"
81 92
 

+ 80
- 73
UGameEngine/utils/vectorxd.hxx View File

@@ -1,45 +1,46 @@
1 1
 #include <math.h>
2 2
 
3
-#define tmpl template<unsigned X>
3
+#define tmplx template<unsigned X>
4
+#define tmpl template<unsigned X, class T>
4 5
 
5
-tmpl VectorXD<X>::VectorXD()
6
+tmplx VectorXD<X>::VectorXD()
6 7
 {
7 8
     for (unsigned i = 0; i < X; ++i) {
8 9
         _scalars[i] = 0;
9 10
     }
10 11
 }
11 12
 
12
-tmpl VectorXD<X>::VectorXD(const double scalars[X])
13
+tmplx VectorXD<X>::VectorXD(const double scalars[X])
13 14
 {
14 15
     for (unsigned i = 0; i < X; ++i) {
15 16
         _scalars[i] = scalars[i];
16 17
     }
17 18
 }
18 19
 
19
-tmpl VectorXD<X>::VectorXD(const VectorXD<X>& other)
20
+tmplx VectorXD<X>::VectorXD(const VectorXD<X>& other)
20 21
 {
21 22
     for (unsigned i = 0; i < X; ++i) {
22 23
         _scalars[i] = other._scalars[i];
23 24
     }
24 25
 }
25 26
 
26
-tmpl VectorXD<X>& VectorXD<X>::setScalar(unsigned i, double value)
27
+tmpl T& GenericVector<X, T>::setScalar(unsigned i, double value)
27 28
 {
28 29
     _scalars[i] = value;
29
-    return *this;
30
+    return *getThis();
30 31
 }
31 32
 
32
-tmpl double VectorXD<X>::getScalar(unsigned i) const
33
+tmpl double GenericVector<X, T>::getScalar(unsigned i) const
33 34
 {
34 35
     return _scalars[i];
35 36
 }
36 37
 
37
-tmpl bool VectorXD<X>::isNull() const
38
+tmpl bool GenericVector<X, T>::isNull() const
38 39
 {
39
-    return equal(VectorXD<X>());
40
+    return equal(T());
40 41
 }
41 42
 
42
-tmpl bool VectorXD<X>::equal(const VectorXD<X> &other) const
43
+tmpl bool GenericVector<X, T>::equal(const T &other) const
43 44
 {
44 45
     for (unsigned i = 0; i < X; ++i) {
45 46
         if (_scalars[i] != other._scalars[i]) {
@@ -49,94 +50,94 @@ tmpl bool VectorXD<X>::equal(const VectorXD<X> &other) const
49 50
     return true;
50 51
 }
51 52
 
52
-tmpl VectorXD<X> &VectorXD<X>::add(double k)
53
+tmpl T &GenericVector<X, T>::add(double k)
53 54
 {
54 55
     double scalars[X];
55 56
     for (unsigned i = 0; i < X; ++i) {
56 57
         scalars[i] = k;
57 58
     }
58
-    return add(VectorXD<X>(scalars));
59
+    return add(T(scalars));
59 60
 }
60 61
 
61
-tmpl VectorXD<X> &VectorXD<X>::add(double scalars[X])
62
+tmpl T &GenericVector<X, T>::add(double scalars[X])
62 63
 {
63
-    return add(VectorXD<X>(scalars));
64
+    return add(T(scalars));
64 65
 }
65 66
 
66
-tmpl VectorXD<X>& VectorXD<X>::add(const  VectorXD<X> &other)
67
+tmpl T& GenericVector<X, T>::add(const  T &other)
67 68
 {
68 69
     for (unsigned i = 0; i < X; ++i) {
69 70
         _scalars[i] += other._scalars[i];
70 71
     }
71
-    return *this;
72
+    return *getThis();
72 73
 }
73 74
 
74
-tmpl VectorXD<X> &VectorXD<X>::sub(double k)
75
+tmpl T &GenericVector<X, T>::sub(double k)
75 76
 {
76 77
     double scalars[X];
77 78
     for (unsigned i = 0; i < X; ++i) {
78 79
         scalars[i] = k;
79 80
     }
80
-    return sub(VectorXD<X>(scalars));
81
+    return sub(T(scalars));
81 82
 }
82 83
 
83
-tmpl VectorXD<X> &VectorXD<X>::sub(double scalars[X])
84
+tmpl T &GenericVector<X, T>::sub(double scalars[X])
84 85
 {
85
-    return sub(VectorXD<X>(scalars));
86
+    return sub(T(scalars));
86 87
 }
87 88
 
88
-tmpl VectorXD<X>& VectorXD<X>::sub(const VectorXD<X> &other)
89
+tmpl T& GenericVector<X, T>::sub(const T &other)
89 90
 {
90 91
     for (unsigned i = 0; i < X; ++i) {
91 92
         _scalars[i] -= other._scalars[i];
92 93
     }
93
-    return *this;
94
+    return *getThis();
94 95
 }
95 96
 
96
-tmpl VectorXD<X> &VectorXD<X>::mult(double k)
97
+tmpl T &GenericVector<X, T>::mult(double k)
97 98
 {
98 99
     for (unsigned i = 0; i < X; ++i) {
99 100
         _scalars[i] *= k;
100 101
     }
101
-    return *this;
102
+    return *getThis();
102 103
 }
103 104
 
104
-tmpl VectorXD<X> &VectorXD<X>::mult(double scalars[X])
105
+tmpl T &GenericVector<X, T>::mult(double scalars[X])
105 106
 {
106
-    return mult(VectorXD<X>(scalars));
107
+    return mult(T(scalars));
107 108
 }
108 109
 
109
-tmpl VectorXD<X> &VectorXD<X>::mult(const VectorXD<X> &other)
110
+tmpl T &GenericVector<X, T>::mult(const T &other)
110 111
 {
111 112
     for (unsigned i = 0; i < X; ++i) {
112 113
         _scalars[i] *= other._scalars[i];
113 114
     }
114
-    return *this;
115
+    return *getThis();
115 116
 }
116 117
 
117
-tmpl VectorXD<X> &VectorXD<X>::div(double k)
118
+tmpl T &GenericVector<X, T>::div(double k)
118 119
 {
119 120
     double scalars[X];
120 121
     for (unsigned i = 0; i < X; ++i) {
121 122
         scalars[i] = k;
122 123
     }
123
-    return div(VectorXD<X>(scalars));
124
+    return div(T(scalars));
124 125
 }
125 126
 
126
-tmpl VectorXD<X> &VectorXD<X>::div(double scalars[X])
127
+tmpl T &GenericVector<X, T>::div(double scalars[X])
127 128
 {
128
-    return div(VectorXD<X>(scalars));
129
+    return div(T(scalars));
129 130
 }
130 131
 
131
-tmpl VectorXD<X> &VectorXD<X>::div(const VectorXD<X> &other)
132
+tmpl T &GenericVector<X, T>::div(const T &other)
132 133
 {
133 134
     for (unsigned i = 0; i < X; ++i) {
134 135
         _scalars[i] /= other._scalars[i];
135 136
     }
136
-    return *this;
137
+    return *getThis();
137 138
 }
138 139
 
139
-tmpl double VectorXD<X>::dotProduct(const VectorXD<X> &other) const
140
+tmpl double GenericVector<X, T>::dotProduct(const T &other) const
140 141
 {
141 142
     double total = 0;
142 143
     for (unsigned i = 0; i < X; ++i) {
@@ -145,23 +146,23 @@ tmpl double VectorXD<X>::dotProduct(const VectorXD<X> &other) const
145 146
     return total;
146 147
 }
147 148
 
148
-tmpl VectorXD<X>& VectorXD<X>::crossProduct(const VectorXD<X>& other)
149
+tmpl T& GenericVector<X, T>::crossProduct(const T& other)
149 150
 {
150
-    VectorXD<X> t = *this;
151
+    T t = *getThis();
151 152
     for (unsigned i = 0; i < X; ++i) {
152 153
         unsigned j = (i + 1) % X;
153 154
         unsigned k = (i + 2) % X;
154 155
         _scalars[i] = (t._scalars[j] * other._scalars[k]) - (t._scalars[k] * other._scalars[j]);
155 156
     }
156
-    return *this;
157
+    return *getThis();
157 158
 }
158 159
 
159
-tmpl VectorXD<X> VectorXD<X>::crossProduct(const VectorXD<X> &v1, const VectorXD<X> &v2)
160
+tmpl T GenericVector<X, T>::crossProduct(const T &v1, const T &v2)
160 161
 {
161
-    return VectorXD<X>(v1).crossProduct(v2);
162
+    return T(v1).crossProduct(v2);
162 163
 }
163 164
 
164
-tmpl double VectorXD<X>::norm() const
165
+tmpl double GenericVector<X, T>::norm() const
165 166
 {
166 167
     double total = 0;
167 168
     for (unsigned i = 0; i < X; ++i) {
@@ -170,117 +171,123 @@ tmpl double VectorXD<X>::norm() const
170 171
     return sqrt(total);
171 172
 }
172 173
 
173
-tmpl VectorXD<X> VectorXD<X>::operator+() const
174
+tmpl T GenericVector<X, T>::operator+() const
174 175
 {
175
-    return *this;
176
+    return *getThis();
176 177
 }
177 178
 
178
-tmpl VectorXD<X> VectorXD<X>::operator+(const double &k) const
179
+tmpl T GenericVector<X, T>::operator+(const double &k) const
179 180
 {
180
-    return VectorXD(*this).add(k);
181
+    return T(*getThis()).add(k);
181 182
 }
182 183
 
183
-tmpl VectorXD<X> &VectorXD<X>::operator+=(const double &k)
184
+tmpl T &GenericVector<X, T>::operator+=(const double &k)
184 185
 {
185 186
     return add(k);
186 187
 }
187 188
 
188
-tmpl VectorXD<X> VectorXD<X>::operator+(const VectorXD<X> &other) const
189
+tmpl T GenericVector<X, T>::operator+(const T &other) const
189 190
 {
190
-    return VectorXD<X>(*this).add(other);
191
+    T v = *getThis();
192
+    return v.add(other);
191 193
 }
192 194
 
193
-tmpl VectorXD<X> &VectorXD<X>::operator+=(const VectorXD<X> &other)
195
+tmpl T &GenericVector<X, T>::operator+=(const T &other)
194 196
 {
195 197
     return add(other);
196 198
 }
197 199
 
198
-tmpl VectorXD<X> VectorXD<X>::operator-() const
200
+tmpl T GenericVector<X, T>::operator-() const
199 201
 {
200 202
     double scalars[X];
201 203
     for (unsigned i = 0; i < X; ++i) {
202 204
         scalars[i] = -_scalars[i];
203 205
     }
204
-    return VectorXD<X>(scalars);
206
+    return T(scalars);
205 207
 }
206 208
 
207
-tmpl VectorXD<X> VectorXD<X>::operator-(const double &k) const
209
+tmpl T GenericVector<X, T>::operator-(const double &k) const
208 210
 {
209
-    return VectorXD(*this).sub(k);
211
+    return T(*getThis()).sub(k);
210 212
 }
211 213
 
212
-tmpl VectorXD<X> &VectorXD<X>::operator-=(const double &k)
214
+tmpl T &GenericVector<X, T>::operator-=(const double &k)
213 215
 {
214 216
     return sub(k);
215 217
 }
216 218
 
217
-tmpl VectorXD<X> VectorXD<X>::operator-(const VectorXD<X> &other) const
219
+tmpl T GenericVector<X, T>::operator-(const T &other) const
218 220
 {
219
-    return VectorXD(*this).sub(other);
221
+    return T(*getThis()).sub(other);
220 222
 }
221 223
 
222
-tmpl VectorXD<X> &VectorXD<X>::operator-=(const VectorXD<X> &other)
224
+tmpl T &GenericVector<X, T>::operator-=(const T &other)
223 225
 {
224 226
     return sub(other);
225 227
 }
226 228
 
227
-tmpl VectorXD<X> VectorXD<X>::operator*(const double &k) const
229
+tmpl T GenericVector<X, T>::operator*(const double &k) const
228 230
 {
229
-    return VectorXD<X>(*this).mult(k);
231
+    return T(*getThis()).mult(k);
230 232
 }
231 233
 
232
-tmpl VectorXD<X> &VectorXD<X>::operator*=(const double &k)
234
+tmpl T &GenericVector<X, T>::operator*=(const double &k)
233 235
 {
234 236
     return mult(k);
235 237
 }
236 238
 
237
-tmpl VectorXD<X> VectorXD<X>::operator*(const VectorXD<X> &other) const
239
+tmpl T GenericVector<X, T>::operator*(const T &other) const
238 240
 {
239
-    return VectorXD<X>(*this).mult(other);
241
+    return T(*getThis()).mult(other);
240 242
 }
241 243
 
242
-tmpl VectorXD<X> &VectorXD<X>::operator*=(const VectorXD<X> &other)
244
+tmpl T &GenericVector<X, T>::operator*=(const T &other)
243 245
 {
244 246
     dotProduct(other);
245
-    return *this;
247
+    return *getThis();
246 248
 }
247 249
 
248
-tmpl VectorXD<X> VectorXD<X>::operator/(const double &k) const
250
+tmpl T GenericVector<X, T>::operator/(const double &k) const
249 251
 {
250
-    return VectorXD<X>(*this).div(k);
252
+    return T(*getThis()).div(k);
251 253
 }
252 254
 
253
-tmpl VectorXD<X> &VectorXD<X>::operator/=(const double &k)
255
+tmpl T &GenericVector<X, T>::operator/=(const double &k)
254 256
 {
255 257
     return div(k);
256 258
 }
257 259
 
258
-tmpl bool VectorXD<X>::operator==(const VectorXD<X> &other) const
260
+tmpl bool GenericVector<X, T>::operator==(const T &other) const
259 261
 {
260 262
     return equal(other);
261 263
 }
262 264
 
263
-tmpl bool VectorXD<X>::operator!=(const VectorXD<X> &other) const
265
+tmpl bool GenericVector<X, T>::operator!=(const T &other) const
264 266
 {
265 267
     return !equal(other);
266 268
 }
267 269
 
268
-tmpl double VectorXD<X>::operator[](unsigned i) const
270
+tmpl double GenericVector<X, T>::operator[](unsigned i) const
269 271
 {
270 272
     return getScalar(i);
271 273
 }
272 274
 
273
-tmpl bool VectorXD<X>::operator!() const
275
+tmpl bool GenericVector<X, T>::operator!() const
274 276
 {
275 277
     return isNull();
276 278
 }
277 279
 
278
-tmpl VectorXD<X>::operator bool() const
280
+tmpl GenericVector<X, T>::operator bool() const
279 281
 {
280 282
     return !isNull();
281 283
 }
282 284
 
283
-tmpl QDebug operator<<(QDebug dbg, const VectorXD<X> &v)
285
+tmpl T* GenericVector<X, T>::getThis() const
286
+{
287
+    return (T*)this;
288
+}
289
+
290
+tmpl QDebug operator<<(QDebug dbg, const T &v)
284 291
 {
285 292
     return dbg.nospace() << "(" << v.getX() << ", " << v.getY() << ", " << v.getZ() << ")";
286 293
 }

Loading…
Cancel
Save