2022-03-16 22:21:12 +01:00
|
|
|
#pragma once
|
|
|
|
|
2023-08-07 13:35:19 +02:00
|
|
|
#include <cmath>
|
2022-03-16 22:21:12 +01:00
|
|
|
|
|
|
|
class Vector2D {
|
2022-12-16 18:17:31 +01:00
|
|
|
public:
|
2022-03-16 22:21:12 +01:00
|
|
|
Vector2D(double, double);
|
|
|
|
Vector2D();
|
|
|
|
~Vector2D();
|
|
|
|
|
|
|
|
double x = 0;
|
|
|
|
double y = 0;
|
|
|
|
|
|
|
|
// returns the scale
|
2022-12-16 18:17:31 +01:00
|
|
|
double normalize();
|
2022-03-16 22:21:12 +01:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
Vector2D operator+(const Vector2D& a) const {
|
2022-03-16 22:21:12 +01:00
|
|
|
return Vector2D(this->x + a.x, this->y + a.y);
|
|
|
|
}
|
2022-12-16 18:17:31 +01:00
|
|
|
Vector2D operator-(const Vector2D& a) const {
|
2022-03-16 22:21:12 +01:00
|
|
|
return Vector2D(this->x - a.x, this->y - a.y);
|
|
|
|
}
|
2022-12-16 18:17:31 +01:00
|
|
|
Vector2D operator*(const float& a) const {
|
2022-03-16 22:21:12 +01:00
|
|
|
return Vector2D(this->x * a, this->y * a);
|
|
|
|
}
|
2022-12-16 18:17:31 +01:00
|
|
|
Vector2D operator/(const float& a) const {
|
2022-03-16 22:21:12 +01:00
|
|
|
return Vector2D(this->x / a, this->y / a);
|
|
|
|
}
|
2022-03-17 15:53:45 +01:00
|
|
|
|
2022-04-23 14:40:51 +02:00
|
|
|
bool operator==(const Vector2D& a) const {
|
2022-03-17 15:53:45 +01:00
|
|
|
return a.x == x && a.y == y;
|
|
|
|
}
|
|
|
|
|
2022-04-23 14:40:51 +02:00
|
|
|
bool operator!=(const Vector2D& a) const {
|
2022-03-17 15:53:45 +01:00
|
|
|
return a.x != x || a.y != y;
|
|
|
|
}
|
|
|
|
|
2022-08-28 10:14:43 +02:00
|
|
|
Vector2D operator*(const Vector2D& a) const {
|
|
|
|
return Vector2D(this->x * a.x, this->y * a.y);
|
|
|
|
}
|
|
|
|
|
2023-01-29 16:58:36 +01:00
|
|
|
Vector2D operator/(const Vector2D& a) const {
|
|
|
|
return Vector2D(this->x / a.x, this->y / a.y);
|
|
|
|
}
|
|
|
|
|
2023-08-14 14:22:06 +02:00
|
|
|
bool operator>(const Vector2D& a) const {
|
|
|
|
return this->x > a.x && this->y > a.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator<(const Vector2D& a) const {
|
|
|
|
return this->x < a.x && this->y < a.y;
|
|
|
|
}
|
|
|
|
|
2023-06-23 21:14:04 +02:00
|
|
|
double distance(const Vector2D& other) const;
|
2022-07-02 22:17:17 +02:00
|
|
|
|
2023-06-23 21:14:04 +02:00
|
|
|
Vector2D clamp(const Vector2D& min, const Vector2D& max = Vector2D()) const;
|
|
|
|
|
|
|
|
Vector2D floor() const;
|
2023-07-11 13:37:25 +02:00
|
|
|
|
|
|
|
bool inTriangle(const Vector2D& p1, const Vector2D& p2, const Vector2D& p3) const;
|
2023-02-18 23:35:31 +01:00
|
|
|
};
|