2023-05-03 22:50:46 +02:00
|
|
|
#ifndef VECTOR2D_H
|
|
|
|
#define VECTOR2D_H
|
|
|
|
|
|
|
|
#include <num/num.h>
|
|
|
|
|
2023-05-06 22:35:15 +02:00
|
|
|
libnum::num32 sqrt_num32(libnum::num32 v);
|
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
class Vector2D {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/* constructors and destructor */
|
|
|
|
Vector2D();
|
|
|
|
Vector2D(float x, float y);
|
|
|
|
Vector2D(libnum::num32 x, libnum::num32 y);
|
|
|
|
Vector2D(const Vector2D &v);
|
|
|
|
~Vector2D();
|
|
|
|
|
|
|
|
/* methods that return a Vector2D */
|
|
|
|
Vector2D Clone(void);
|
|
|
|
Vector2D MakeVector(Vector2D A, Vector2D B);
|
|
|
|
Vector2D PerpCW(void);
|
|
|
|
Vector2D PerpCCW(void);
|
|
|
|
|
|
|
|
/* methods that return nothing */
|
|
|
|
void AddVectors(Vector2D a, Vector2D b);
|
|
|
|
void Add(Vector2D v, libnum::num32 scale);
|
|
|
|
void SubtractVectors(Vector2D a, Vector2D b);
|
|
|
|
void Subtract(Vector2D v, libnum::num32 scale);
|
|
|
|
void Scale(libnum::num32 scale);
|
|
|
|
|
|
|
|
/* methods that return scalar */
|
|
|
|
libnum::num32 Length(void);
|
|
|
|
libnum::num32 Dot(Vector2D v);
|
|
|
|
libnum::num32 Det(Vector2D v);
|
|
|
|
|
|
|
|
/* overloading of most interesting operators */
|
|
|
|
libnum::num32 operator[](uint8_t pos) { return pos == 0 ? x : y; }
|
|
|
|
|
|
|
|
Vector2D &operator=(const Vector2D &v) {
|
|
|
|
this->x = v.x;
|
|
|
|
this->y = v.y;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector2D operator+(const Vector2D &v) const {
|
|
|
|
return Vector2D(x + v.x, y + v.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector2D operator-(const Vector2D &v) const {
|
|
|
|
return Vector2D(x - v.x, y - v.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector2D &operator+=(Vector2D const &other) {
|
|
|
|
this->x += other.x;
|
|
|
|
this->y += other.y;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector2D operator-() const { return (Vector2D(-x, -y)); }
|
|
|
|
|
|
|
|
Vector2D operator+() const { return *this; }
|
|
|
|
|
|
|
|
Vector2D &operator-=(Vector2D const &other) {
|
|
|
|
this->x -= other.x;
|
|
|
|
this->y -= other.y;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector2D &operator*=(libnum::num32 scale) {
|
|
|
|
this->x *= scale;
|
|
|
|
this->y *= scale;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector2D &operator/=(libnum::num32 scale) {
|
|
|
|
this->x /= scale;
|
|
|
|
this->y /= scale;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend Vector2D operator*(libnum::num32 scale, Vector2D const &v) {
|
|
|
|
Vector2D r;
|
|
|
|
r.x = v.x * scale;
|
|
|
|
r.y = v.y * scale;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend Vector2D operator*(Vector2D const &v, libnum::num32 scale) {
|
|
|
|
Vector2D r;
|
|
|
|
r.x = v.x * scale;
|
|
|
|
r.y = v.y * scale;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend Vector2D operator/(Vector2D const &v, libnum::num32 scale) {
|
|
|
|
Vector2D r;
|
|
|
|
r.x = v.x / scale;
|
|
|
|
r.y = v.y / scale;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
libnum::num32 x;
|
|
|
|
libnum::num32 y;
|
2023-05-03 22:50:46 +02:00
|
|
|
};
|
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
class Border {
|
|
|
|
public:
|
|
|
|
Border();
|
|
|
|
~Border();
|
2023-05-16 16:11:39 +02:00
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
Vector2D A;
|
|
|
|
Vector2D B;
|
|
|
|
Vector2D N;
|
|
|
|
uint16_t color;
|
2023-05-16 16:11:39 +02:00
|
|
|
};
|
2023-05-06 22:35:15 +02:00
|
|
|
|
2023-05-03 22:50:46 +02:00
|
|
|
#endif
|