diff --git a/include/units/Vector3D.hpp b/include/units/Vector3D.hpp index 1bae018..37262ff 100644 --- a/include/units/Vector3D.hpp +++ b/include/units/Vector3D.hpp @@ -64,7 +64,7 @@ template class Vector3D { * @param other vector to add * @return Vector3D */ - Vector3D operator+(Vector3D& other) { return Vector3D(x + other.x, y + other.y, z + other.z); } + Vector3D operator+(Vector3D& other) const { return Vector3D(x + other.x, y + other.y, z + other.z); } /** * @brief - operator overload @@ -75,7 +75,7 @@ template class Vector3D { * @param other vector to subtract * @return Vector3D */ - Vector3D operator-(Vector3D& other) { return Vector3D(x - other.x, y - other.y, z - other.z); } + Vector3D operator-(Vector3D& other) const { return Vector3D(x - other.x, y - other.y, z - other.z); } /** * @brief * operator overload @@ -86,7 +86,7 @@ template class Vector3D { * @param factor scalar to multiply by * @return Vector3D */ - Vector3D operator*(double factor) { return Vector3D(x * factor, y * factor, z * factor); } + Vector3D operator*(double factor) const { return Vector3D(x * factor, y * factor, z * factor); } /** * @brief / operator overload @@ -97,7 +97,7 @@ template class Vector3D { * @param factor scalar to divide by * @return Vector3D */ - Vector3D operator/(double factor) { return Vector3D(x / factor, y / factor, z / factor); } + Vector3D operator/(double factor) const { return Vector3D(x / factor, y / factor, z / factor); } /** * @brief += operator overload @@ -176,7 +176,7 @@ template class Vector3D { * @param other the vector to calculate the dot product with * @return R the dot product */ - template > R dot(Vector3D& other) { + template > R dot(Vector3D& other) const { return (x * other.x) + (y * other.y) + (z * other.z); } @@ -193,7 +193,7 @@ template class Vector3D { * @param other the vector to calculate the cross product with * @return Vector3D the cross product */ - template > Vector3D cross(Vector3D& other) { + template > Vector3D cross(Vector3D& other) const { return Vector3D(y * other.z - z * other.y, z * other.x - x * other.z, x * other.y - y * other.x); } @@ -202,7 +202,7 @@ template class Vector3D { * * @return Angle */ - Vector3D theta() { + Vector3D theta() const { const T mag = magnitude(); return Vector3D(acos(x / mag), acos(y / mag), acos(z / mag)); } @@ -212,7 +212,7 @@ template 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 @@ -225,7 +225,7 @@ template class Vector3D { * @param other the other vector * @return Vector3D */ - Vector3D vectorTo(Vector3D& other) { return Vector2D(other.x - x, other.y - y, other.z - z); } + Vector3D vectorTo(Vector3D& other) const { return Vector2D(other.x - x, other.y - y, other.z - z); } /** * @brief the angle between two vectors @@ -233,7 +233,7 @@ template class Vector3D { * @param other the other vector * @return Angle */ - Angle angleTo(Vector3D& other) { return units::acos(dot(other) / (magnitude() * other.magnitude())); } + Angle angleTo(Vector3D& other) const { return units::acos(dot(other) / (magnitude() * other.magnitude())); } /** * @brief get the distance between two vectors @@ -241,7 +241,7 @@ template class Vector3D { * @param other the other vector * @return T */ - T distanceTo(Vector3D& other) { return vectorTo(other).magnitude(); } + T distanceTo(Vector3D& other) const { return vectorTo(other).magnitude(); } /** * @brief normalize the vector @@ -286,7 +286,7 @@ template class Vector3D { * @param angle * @return Vector3D */ - Vector3D rotatedBy(Vector3D angle) { + Vector3D rotatedBy(Vector3D angle) const { T m = magnitude(); Angle t = theta() + angle; return fromPolar(t, m); @@ -298,7 +298,7 @@ template class Vector3D { * @param angle * @return Vector3D */ - Vector3D rotatedTo(Angle angle) { + Vector3D rotatedTo(Angle angle) const { T m = magnitude(); return fromPolar(angle, m); }