Skip to content

Commit

Permalink
vector: New operator overloads and small fix in Vector2D. (#3891)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dickby authored Nov 18, 2023
1 parent 6ad5f26 commit 3d89654
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/helpers/Vector2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;
Expand Down

0 comments on commit 3d89654

Please sign in to comment.