Skip to content

Commit 1b172d1

Browse files
committed
make Vector3D functions const
1 parent 839cb44 commit 1b172d1

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

include/units/Vector3D.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ template <isQuantity T> class Vector3D {
6464
* @param other vector to add
6565
* @return Vector3D<T>
6666
*/
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); }
6868

6969
/**
7070
* @brief - operator overload
@@ -75,7 +75,7 @@ template <isQuantity T> class Vector3D {
7575
* @param other vector to subtract
7676
* @return Vector3D<T>
7777
*/
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); }
7979

8080
/**
8181
* @brief * operator overload
@@ -86,7 +86,7 @@ template <isQuantity T> class Vector3D {
8686
* @param factor scalar to multiply by
8787
* @return Vector3D<T>
8888
*/
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); }
9090

9191
/**
9292
* @brief / operator overload
@@ -97,7 +97,7 @@ template <isQuantity T> class Vector3D {
9797
* @param factor scalar to divide by
9898
* @return Vector3D<T>
9999
*/
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); }
101101

102102
/**
103103
* @brief += operator overload
@@ -176,7 +176,7 @@ template <isQuantity T> class Vector3D {
176176
* @param other the vector to calculate the dot product with
177177
* @return R the dot product
178178
*/
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 {
180180
return (x * other.x) + (y * other.y) + (z * other.z);
181181
}
182182

@@ -193,7 +193,7 @@ template <isQuantity T> class Vector3D {
193193
* @param other the vector to calculate the cross product with
194194
* @return Vector3D<R> the cross product
195195
*/
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 {
197197
return Vector3D<R>(y * other.z - z * other.y, z * other.x - x * other.z, x * other.y - y * other.x);
198198
}
199199

@@ -202,7 +202,7 @@ template <isQuantity T> class Vector3D {
202202
*
203203
* @return Angle
204204
*/
205-
Vector3D<Angle> theta() {
205+
Vector3D<Angle> theta() const {
206206
const T mag = magnitude();
207207
return Vector3D<Angle>(acos(x / mag), acos(y / mag), acos(z / mag));
208208
}
@@ -212,7 +212,7 @@ template <isQuantity T> class Vector3D {
212212
*
213213
* @return T
214214
*/
215-
T magnitude() { return sqrt(square(x) + square(y) + square(z)); }
215+
T magnitude() const { return sqrt(square(x) + square(y) + square(z)); }
216216

217217
/**
218218
* @brief difference between two vectors
@@ -225,23 +225,23 @@ template <isQuantity T> class Vector3D {
225225
* @param other the other vector
226226
* @return Vector3D<T>
227227
*/
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); }
229229

230230
/**
231231
* @brief the angle between two vectors
232232
*
233233
* @param other the other vector
234234
* @return Angle
235235
*/
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())); }
237237

238238
/**
239239
* @brief get the distance between two vectors
240240
*
241241
* @param other the other vector
242242
* @return T
243243
*/
244-
T distanceTo(Vector3D<T>& other) { return vectorTo(other).magnitude(); }
244+
T distanceTo(Vector3D<T>& other) const { return vectorTo(other).magnitude(); }
245245

246246
/**
247247
* @brief normalize the vector
@@ -286,7 +286,7 @@ template <isQuantity T> class Vector3D {
286286
* @param angle
287287
* @return Vector3D<T>
288288
*/
289-
Vector3D<T> rotatedBy(Vector3D<Angle> angle) {
289+
Vector3D<T> rotatedBy(Vector3D<Angle> angle) const {
290290
T m = magnitude();
291291
Angle t = theta() + angle;
292292
return fromPolar(t, m);
@@ -298,7 +298,7 @@ template <isQuantity T> class Vector3D {
298298
* @param angle
299299
* @return Vector3D<T>
300300
*/
301-
Vector3D<T> rotatedTo(Angle angle) {
301+
Vector3D<T> rotatedTo(Angle angle) const {
302302
T m = magnitude();
303303
return fromPolar(angle, m);
304304
}

0 commit comments

Comments
 (0)