Skip to content

Commit

Permalink
make Vector3D functions const
Browse files Browse the repository at this point in the history
  • Loading branch information
SizzinSeal committed Dec 27, 2024
1 parent 839cb44 commit 1b172d1
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions include/units/Vector3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ template <isQuantity T> class Vector3D {
* @param other vector to add
* @return Vector3D<T>
*/
Vector3D<T> operator+(Vector3D<T>& other) { return Vector3D<T>(x + other.x, y + other.y, z + other.z); }
Vector3D<T> operator+(Vector3D<T>& other) const { return Vector3D<T>(x + other.x, y + other.y, z + other.z); }

/**
* @brief - operator overload
Expand All @@ -75,7 +75,7 @@ template <isQuantity T> class Vector3D {
* @param other vector to subtract
* @return Vector3D<T>
*/
Vector3D<T> operator-(Vector3D<T>& other) { return Vector3D<T>(x - other.x, y - other.y, z - other.z); }
Vector3D<T> operator-(Vector3D<T>& other) const { return Vector3D<T>(x - other.x, y - other.y, z - other.z); }

/**
* @brief * operator overload
Expand All @@ -86,7 +86,7 @@ template <isQuantity T> class Vector3D {
* @param factor scalar to multiply by
* @return Vector3D<T>
*/
Vector3D<T> operator*(double factor) { return Vector3D<T>(x * factor, y * factor, z * factor); }
Vector3D<T> operator*(double factor) const { return Vector3D<T>(x * factor, y * factor, z * factor); }

/**
* @brief / operator overload
Expand All @@ -97,7 +97,7 @@ template <isQuantity T> class Vector3D {
* @param factor scalar to divide by
* @return Vector3D<T>
*/
Vector3D<T> operator/(double factor) { return Vector3D<T>(x / factor, y / factor, z / factor); }
Vector3D<T> operator/(double factor) const { return Vector3D<T>(x / factor, y / factor, z / factor); }

/**
* @brief += operator overload
Expand Down Expand Up @@ -176,7 +176,7 @@ template <isQuantity T> class Vector3D {
* @param other the vector to calculate the dot product with
* @return R the dot product
*/
template <isQuantity Q, isQuantity R = Multiplied<T, Q>> R dot(Vector3D<Q>& other) {
template <isQuantity Q, isQuantity R = Multiplied<T, Q>> R dot(Vector3D<Q>& other) const {
return (x * other.x) + (y * other.y) + (z * other.z);
}

Expand All @@ -193,7 +193,7 @@ template <isQuantity T> class Vector3D {
* @param other the vector to calculate the cross product with
* @return Vector3D<R> the cross product
*/
template <isQuantity Q, isQuantity R = Multiplied<T, Q>> Vector3D<R> cross(Vector3D<Q>& other) {
template <isQuantity Q, isQuantity R = Multiplied<T, Q>> Vector3D<R> cross(Vector3D<Q>& other) const {
return Vector3D<R>(y * other.z - z * other.y, z * other.x - x * other.z, x * other.y - y * other.x);
}

Expand All @@ -202,7 +202,7 @@ template <isQuantity T> class Vector3D {
*
* @return Angle
*/
Vector3D<Angle> theta() {
Vector3D<Angle> theta() const {
const T mag = magnitude();
return Vector3D<Angle>(acos(x / mag), acos(y / mag), acos(z / mag));
}
Expand All @@ -212,7 +212,7 @@ template <isQuantity T> class Vector3D {
*
* @return T
*/
T magnitude() { return sqrt(square(x) + square(y) + square(z)); }
T magnitude() const { return sqrt(square(x) + square(y) + square(z)); }

/**
* @brief difference between two vectors
Expand All @@ -225,23 +225,23 @@ template <isQuantity T> class Vector3D {
* @param other the other vector
* @return Vector3D<T>
*/
Vector3D<T> vectorTo(Vector3D<T>& other) { return Vector2D<T>(other.x - x, other.y - y, other.z - z); }
Vector3D<T> vectorTo(Vector3D<T>& other) const { return Vector2D<T>(other.x - x, other.y - y, other.z - z); }

/**
* @brief the angle between two vectors
*
* @param other the other vector
* @return Angle
*/
Angle angleTo(Vector3D<T>& other) { return units::acos(dot(other) / (magnitude() * other.magnitude())); }
Angle angleTo(Vector3D<T>& other) const { return units::acos(dot(other) / (magnitude() * other.magnitude())); }

/**
* @brief get the distance between two vectors
*
* @param other the other vector
* @return T
*/
T distanceTo(Vector3D<T>& other) { return vectorTo(other).magnitude(); }
T distanceTo(Vector3D<T>& other) const { return vectorTo(other).magnitude(); }

/**
* @brief normalize the vector
Expand Down Expand Up @@ -286,7 +286,7 @@ template <isQuantity T> class Vector3D {
* @param angle
* @return Vector3D<T>
*/
Vector3D<T> rotatedBy(Vector3D<Angle> angle) {
Vector3D<T> rotatedBy(Vector3D<Angle> angle) const {
T m = magnitude();
Angle t = theta() + angle;
return fromPolar(t, m);
Expand All @@ -298,7 +298,7 @@ template <isQuantity T> class Vector3D {
* @param angle
* @return Vector3D<T>
*/
Vector3D<T> rotatedTo(Angle angle) {
Vector3D<T> rotatedTo(Angle angle) const {
T m = magnitude();
return fromPolar(angle, m);
}
Expand Down

0 comments on commit 1b172d1

Please sign in to comment.