mirror of
https://github.com/hyprwm/Hyprland.git
synced 2024-11-27 10:15:26 +03:00
added vector2d
This commit is contained in:
parent
ffd309ca2a
commit
52090853da
19
src/helpers/Vector2D.cpp
Normal file
19
src/helpers/Vector2D.cpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include "Vector2D.hpp"
|
||||||
|
|
||||||
|
Vector2D::Vector2D(double xx, double yy) {
|
||||||
|
x = xx;
|
||||||
|
y = yy;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2D::Vector2D() { x = 0; y = 0; }
|
||||||
|
Vector2D::~Vector2D() {}
|
||||||
|
|
||||||
|
double Vector2D::normalize() {
|
||||||
|
// get max abs
|
||||||
|
const auto max = abs(x) > abs(y) ? abs(x) : abs(y);
|
||||||
|
|
||||||
|
x /= max;
|
||||||
|
y /= max;
|
||||||
|
|
||||||
|
return max;
|
||||||
|
}
|
29
src/helpers/Vector2D.hpp
Normal file
29
src/helpers/Vector2D.hpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
class Vector2D {
|
||||||
|
public:
|
||||||
|
Vector2D(double, double);
|
||||||
|
Vector2D();
|
||||||
|
~Vector2D();
|
||||||
|
|
||||||
|
double x = 0;
|
||||||
|
double y = 0;
|
||||||
|
|
||||||
|
// returns the scale
|
||||||
|
double normalize();
|
||||||
|
|
||||||
|
Vector2D operator+(Vector2D a) {
|
||||||
|
return Vector2D(this->x + a.x, this->y + a.y);
|
||||||
|
}
|
||||||
|
Vector2D operator-(Vector2D a) {
|
||||||
|
return Vector2D(this->x - a.x, this->y - a.y);
|
||||||
|
}
|
||||||
|
Vector2D operator*(float a) {
|
||||||
|
return Vector2D(this->x * a, this->y * a);
|
||||||
|
}
|
||||||
|
Vector2D operator/(float a) {
|
||||||
|
return Vector2D(this->x / a, this->y / a);
|
||||||
|
}
|
||||||
|
};
|
@ -66,3 +66,5 @@ extern "C" {
|
|||||||
#undef static
|
#undef static
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "helpers/Vector2D.hpp"
|
||||||
|
Loading…
Reference in New Issue
Block a user