2021-11-13 11:51:43 +01:00
|
|
|
#ifndef VECTOR2_H
|
|
|
|
#define VECTOR2_H
|
|
|
|
|
2021-11-16 03:08:16 +01:00
|
|
|
#include "core/string.h"
|
|
|
|
|
2021-11-13 11:51:43 +01:00
|
|
|
class Vector2 {
|
|
|
|
public:
|
|
|
|
Vector2 abs() const;
|
|
|
|
float angle() const;
|
|
|
|
float angle_to(const Vector2 &b) const;
|
|
|
|
float cross(const Vector2 &b) const;
|
|
|
|
Vector2 clamped(float len) const;
|
|
|
|
Vector2 direction_to(const Vector2 &b) const;
|
|
|
|
float distance_to_squared(const Vector2 &b) const;
|
|
|
|
float distance_to(const Vector2 &b) const;
|
|
|
|
float dot(const Vector2 &b) const;
|
|
|
|
bool is_equal_approx(const Vector2 &b) const;
|
|
|
|
|
|
|
|
float length() const;
|
|
|
|
float length_squared() const;
|
|
|
|
|
|
|
|
Vector2 lerp(const Vector2 &b, const float t) const;
|
|
|
|
|
|
|
|
Vector2 normalized() const;
|
|
|
|
void normalize();
|
|
|
|
|
|
|
|
void add(const Vector2 &b);
|
|
|
|
void sub(const Vector2 &b);
|
|
|
|
|
|
|
|
Vector2();
|
|
|
|
Vector2(const Vector2 &b);
|
|
|
|
Vector2(const float p_x, const float p_y);
|
|
|
|
|
|
|
|
Vector2 &operator+=(const Vector2 &b);
|
2021-11-16 03:08:16 +01:00
|
|
|
Vector2 operator+(const Vector2 &b) const;
|
2021-11-13 11:51:43 +01:00
|
|
|
Vector2 &operator-=(const Vector2 &b);
|
2021-11-16 03:08:16 +01:00
|
|
|
Vector2 operator-(const Vector2 &b) const;
|
|
|
|
Vector2 &operator*=(const Vector2 &b);
|
|
|
|
Vector2 operator*(const Vector2 &b) const;
|
|
|
|
Vector2 &operator/=(const Vector2 &b);
|
|
|
|
Vector2 operator/(const Vector2 &b) const;
|
|
|
|
|
|
|
|
Vector2 &operator+=(float scalar);
|
|
|
|
Vector2 operator+(float scalar) const;
|
|
|
|
Vector2 &operator-=(float scalar);
|
|
|
|
Vector2 operator-(float scalar) const;
|
|
|
|
Vector2 &operator*=(float scalar);
|
|
|
|
Vector2 operator*(float scalar) const;
|
|
|
|
Vector2 &operator/=(float scalar);
|
|
|
|
Vector2 operator/(float scalar) const;
|
|
|
|
|
|
|
|
Vector2 operator-() const;
|
|
|
|
|
|
|
|
bool operator==(const Vector2 &b) const;
|
|
|
|
bool operator!=(const Vector2 &b) const;
|
|
|
|
|
|
|
|
const float &operator[](int axis) const;
|
|
|
|
float &operator[](int axis);
|
2021-11-13 11:51:43 +01:00
|
|
|
|
2021-11-16 03:08:16 +01:00
|
|
|
operator String() const;
|
2021-11-13 11:51:43 +01:00
|
|
|
|
2021-11-16 03:08:16 +01:00
|
|
|
enum Axis {
|
|
|
|
AXIS_X = 0,
|
|
|
|
AXIS_Y
|
|
|
|
};
|
2021-11-13 11:51:43 +01:00
|
|
|
|
2021-11-16 03:08:16 +01:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
};
|
2021-11-13 11:51:43 +01:00
|
|
|
|
2021-11-16 03:08:16 +01:00
|
|
|
float coordinates[2];
|
|
|
|
};
|
2021-11-13 11:51:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|