summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDickby <felix.dick@web.de>2023-11-18 22:37:16 +0100
committerGitHub <noreply@github.com>2023-11-18 21:37:16 +0000
commit3d89654254a3cc23a57e1bdcd39ad9f743bf98e2 (patch)
tree1c4aac96d2f3f45299b6de3ee4aa4ed30ca46192 /src
parent6ad5f26cfebbdf48ed9633f2ba92e92f5b6622fb (diff)
vector: New operator overloads and small fix in Vector2D. (#3891)
Diffstat (limited to 'src')
-rw-r--r--src/helpers/Vector2D.hpp34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/helpers/Vector2D.hpp b/src/helpers/Vector2D.hpp
index c79c967c..34b06862 100644
--- a/src/helpers/Vector2D.hpp
+++ b/src/helpers/Vector2D.hpp
@@ -25,10 +25,10 @@ class Vector2D {
Vector2D operator-() const {
return Vector2D(-this->x, -this->y);
}
- Vector2D operator*(const float& a) const {
+ Vector2D operator*(const double& a) const {
return Vector2D(this->x * a, this->y * a);
}
- Vector2D operator/(const float& a) const {
+ Vector2D operator/(const double& a) const {
return Vector2D(this->x / a, this->y / a);
}
@@ -55,6 +55,36 @@ class Vector2D {
bool operator<(const Vector2D& a) const {
return this->x < a.x && this->y < a.y;
}
+ Vector2D& operator+=(const Vector2D& a) {
+ this->x += a.x;
+ this->y += a.y;
+ return *this;
+ }
+ Vector2D& operator-=(const Vector2D& a) {
+ this->x -= a.x;
+ this->y -= a.y;
+ return *this;
+ }
+ Vector2D& operator*=(const Vector2D& a) {
+ this->x *= a.x;
+ this->y *= a.y;
+ return *this;
+ }
+ Vector2D& operator/=(const Vector2D& a) {
+ this->x /= a.x;
+ this->y /= a.y;
+ return *this;
+ }
+ Vector2D& operator*=(const double& a) {
+ this->x *= a;
+ this->y *= a;
+ return *this;
+ }
+ Vector2D& operator/=(const double& a) {
+ this->x /= a;
+ this->y /= a;
+ return *this;
+ }
double distance(const Vector2D& other) const;
double size() const;