From 51a16e894d765e00471844297ad825f0cfdf2c2f Mon Sep 17 00:00:00 2001 From: Liam Teale Date: Thu, 26 Dec 2024 18:23:00 -0800 Subject: [PATCH] make refs in Vector2D const --- include/units/Vector2D.hpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/include/units/Vector2D.hpp b/include/units/Vector2D.hpp index 0da98c2..3e0fa55 100644 --- a/include/units/Vector2D.hpp +++ b/include/units/Vector2D.hpp @@ -65,7 +65,7 @@ template class Vector2D { * @param other vector to add * @return Vector2D */ - Vector2D operator+(Vector2D& other) const { return Vector2D(x + other.x, y + other.y); } + Vector2D operator+(const Vector2D& other) const { return Vector2D(x + other.x, y + other.y); } /** * @brief - operator overload @@ -76,7 +76,7 @@ template class Vector2D { * @param other vector to subtract * @return Vector2D */ - Vector2D operator-(Vector2D& other) const { return Vector2D(x - other.x, y - other.y); } + Vector2D operator-(const Vector2D& other) const { return Vector2D(x - other.x, y - other.y); } /** * @brief * operator overload @@ -109,7 +109,7 @@ template class Vector2D { * @param other vector to add * @return Vector2D& */ - Vector2D& operator+=(Vector2D& other) { + Vector2D& operator+=(const Vector2D& other) { x += other.x; y += other.y; return (*this); @@ -124,7 +124,7 @@ template class Vector2D { * @param other vector to subtract * @return Vector2D& */ - Vector2D& operator-=(Vector2D& other) { + Vector2D& operator-=(const Vector2D& other) { x -= other.x; y -= other.y; return (*this); @@ -173,7 +173,7 @@ template class Vector2D { * @param other the vector to calculate the dot product with * @return R the dot product */ - template > R dot(Vector2D& other) const { + template > R dot(const Vector2D& other) const { return (x * other.x) + (y * other.y); } @@ -188,7 +188,7 @@ template class Vector2D { * @param other the vector to calculate the cross product with * @return R the cross product */ - template > R cross(Vector2D& other) const { + template > R cross(const Vector2D& other) const { return (x * other.y) - (y * other.x); } @@ -215,7 +215,7 @@ template class Vector2D { * @param other the other vector * @return Vector2D */ - Vector2D vectorTo(Vector2D& other) const { return Vector2D(other.x - x, other.y - y); } + Vector2D vectorTo(const Vector2D& other) const { return Vector2D(other.x - x, other.y - y); } /** * @brief the angle between two vectors @@ -223,7 +223,7 @@ template class Vector2D { * @param other the other vector * @return Angle */ - Angle angleTo(Vector2D& other) const { return atan2(other.y - y, other.x - x); } + Angle angleTo(const Vector2D& other) const { return atan2(other.y - y, other.x - x); } /** * @brief get the distance between two vectors @@ -231,7 +231,7 @@ template class Vector2D { * @param other the other vector * @return T */ - T distanceTo(Vector2D& other) const { return sqrt(square(x - other.x, 2) + square(y - other.y, 2)); } + T distanceTo(const Vector2D& other) const { return sqrt(square(x - other.x, 2) + square(y - other.y, 2)); } /** * @brief normalize the vector