Files
263-0007-00L-Advanced-Syste…/headers/vector2d_float.hpp
T
2026-05-23 20:50:59 +02:00

35 lines
1013 B
C++

#pragma once
#include <math.h>
struct Vector2d {
float x, y;
Vector2d(float a, float b) : x(a), y(b) {}
Vector2d() : x(.0), y(.0) {}
Vector2d operator+(Vector2d v) const { return Vector2d(v.x + x, v.y + y); }
Vector2d operator-(Vector2d v) const { return Vector2d(x - v.x, y - v.y); }
Vector2d operator-(float a) const { return Vector2d(x - a, y - a); }
Vector2d operator+(float a) const { return Vector2d(x + a, y + a); }
Vector2d operator/(float a) const { return Vector2d(x / a, y / a); }
Vector2d operator*(float a) const { return Vector2d(x * a, y * a); }
Vector2d operator+=(const Vector2d &v) {
*this = *this + v;
return *this;
}
Vector2d operator-=(const Vector2d &v) {
*this = *this - v;
return *this;
}
Vector2d reverse_sign() { return Vector2d(-x, -y); }
// # 1 ADD, 2 MULTs, 1 SQRT
float norm() { return sqrt(x * x + y * y); }
// # 1 ADD, 2 MULTs
float dot(Vector2d v) { return x * v.x + y * v.y; }
void reset() {
x = 0;
y = 0;
}
};