@@ -64,7 +64,7 @@ template <isQuantity T> class Vector3D {
64
64
* @param other vector to add
65
65
* @return Vector3D<T>
66
66
*/
67
- Vector3D<T> operator +(Vector3D<T>& other) { return Vector3D<T>(x + other.x , y + other.y , z + other.z ); }
67
+ Vector3D<T> operator +(Vector3D<T>& other) const { return Vector3D<T>(x + other.x , y + other.y , z + other.z ); }
68
68
69
69
/* *
70
70
* @brief - operator overload
@@ -75,7 +75,7 @@ template <isQuantity T> class Vector3D {
75
75
* @param other vector to subtract
76
76
* @return Vector3D<T>
77
77
*/
78
- Vector3D<T> operator -(Vector3D<T>& other) { return Vector3D<T>(x - other.x , y - other.y , z - other.z ); }
78
+ Vector3D<T> operator -(Vector3D<T>& other) const { return Vector3D<T>(x - other.x , y - other.y , z - other.z ); }
79
79
80
80
/* *
81
81
* @brief * operator overload
@@ -86,7 +86,7 @@ template <isQuantity T> class Vector3D {
86
86
* @param factor scalar to multiply by
87
87
* @return Vector3D<T>
88
88
*/
89
- Vector3D<T> operator *(double factor) { return Vector3D<T>(x * factor, y * factor, z * factor); }
89
+ Vector3D<T> operator *(double factor) const { return Vector3D<T>(x * factor, y * factor, z * factor); }
90
90
91
91
/* *
92
92
* @brief / operator overload
@@ -97,7 +97,7 @@ template <isQuantity T> class Vector3D {
97
97
* @param factor scalar to divide by
98
98
* @return Vector3D<T>
99
99
*/
100
- Vector3D<T> operator /(double factor) { return Vector3D<T>(x / factor, y / factor, z / factor); }
100
+ Vector3D<T> operator /(double factor) const { return Vector3D<T>(x / factor, y / factor, z / factor); }
101
101
102
102
/* *
103
103
* @brief += operator overload
@@ -176,7 +176,7 @@ template <isQuantity T> class Vector3D {
176
176
* @param other the vector to calculate the dot product with
177
177
* @return R the dot product
178
178
*/
179
- template <isQuantity Q, isQuantity R = Multiplied<T, Q>> R dot (Vector3D<Q>& other) {
179
+ template <isQuantity Q, isQuantity R = Multiplied<T, Q>> R dot (Vector3D<Q>& other) const {
180
180
return (x * other.x ) + (y * other.y ) + (z * other.z );
181
181
}
182
182
@@ -193,7 +193,7 @@ template <isQuantity T> class Vector3D {
193
193
* @param other the vector to calculate the cross product with
194
194
* @return Vector3D<R> the cross product
195
195
*/
196
- template <isQuantity Q, isQuantity R = Multiplied<T, Q>> Vector3D<R> cross (Vector3D<Q>& other) {
196
+ template <isQuantity Q, isQuantity R = Multiplied<T, Q>> Vector3D<R> cross (Vector3D<Q>& other) const {
197
197
return Vector3D<R>(y * other.z - z * other.y , z * other.x - x * other.z , x * other.y - y * other.x );
198
198
}
199
199
@@ -202,7 +202,7 @@ template <isQuantity T> class Vector3D {
202
202
*
203
203
* @return Angle
204
204
*/
205
- Vector3D<Angle> theta () {
205
+ Vector3D<Angle> theta () const {
206
206
const T mag = magnitude ();
207
207
return Vector3D<Angle>(acos (x / mag), acos (y / mag), acos (z / mag));
208
208
}
@@ -212,7 +212,7 @@ template <isQuantity T> class Vector3D {
212
212
*
213
213
* @return T
214
214
*/
215
- T magnitude () { return sqrt (square (x) + square (y) + square (z)); }
215
+ T magnitude () const { return sqrt (square (x) + square (y) + square (z)); }
216
216
217
217
/* *
218
218
* @brief difference between two vectors
@@ -225,23 +225,23 @@ template <isQuantity T> class Vector3D {
225
225
* @param other the other vector
226
226
* @return Vector3D<T>
227
227
*/
228
- Vector3D<T> vectorTo (Vector3D<T>& other) { return Vector2D<T>(other.x - x, other.y - y, other.z - z); }
228
+ Vector3D<T> vectorTo (Vector3D<T>& other) const { return Vector2D<T>(other.x - x, other.y - y, other.z - z); }
229
229
230
230
/* *
231
231
* @brief the angle between two vectors
232
232
*
233
233
* @param other the other vector
234
234
* @return Angle
235
235
*/
236
- Angle angleTo (Vector3D<T>& other) { return units::acos (dot (other) / (magnitude () * other.magnitude ())); }
236
+ Angle angleTo (Vector3D<T>& other) const { return units::acos (dot (other) / (magnitude () * other.magnitude ())); }
237
237
238
238
/* *
239
239
* @brief get the distance between two vectors
240
240
*
241
241
* @param other the other vector
242
242
* @return T
243
243
*/
244
- T distanceTo (Vector3D<T>& other) { return vectorTo (other).magnitude (); }
244
+ T distanceTo (Vector3D<T>& other) const { return vectorTo (other).magnitude (); }
245
245
246
246
/* *
247
247
* @brief normalize the vector
@@ -286,7 +286,7 @@ template <isQuantity T> class Vector3D {
286
286
* @param angle
287
287
* @return Vector3D<T>
288
288
*/
289
- Vector3D<T> rotatedBy (Vector3D<Angle> angle) {
289
+ Vector3D<T> rotatedBy (Vector3D<Angle> angle) const {
290
290
T m = magnitude ();
291
291
Angle t = theta () + angle;
292
292
return fromPolar (t, m);
@@ -298,7 +298,7 @@ template <isQuantity T> class Vector3D {
298
298
* @param angle
299
299
* @return Vector3D<T>
300
300
*/
301
- Vector3D<T> rotatedTo (Angle angle) {
301
+ Vector3D<T> rotatedTo (Angle angle) const {
302
302
T m = magnitude ();
303
303
return fromPolar (angle, m);
304
304
}
0 commit comments