Files
viseq/src/datatypes.h
T

67 lines
1.2 KiB
C++
Raw Normal View History

2024-10-09 02:01:23 +02:00
#pragma once
#include <math.h>
// 2D Vectors
template<typename T>
class Vec2D{
public:
Vec2D() {};
Vec2D(T x, T y) : x(x), y(y) {}
T x = 0;
T y = 0;
T dist(Vec2D* v) { return sqrt(pow((v->x - x), 2) + pow((v->y - y), 2));};
T length() { return sqrt(pow(x, 2) + pow(y, 2));};
Vec2D& norm() { return *this * (1.0/length());};
Vec2D& operator=(const Vec2D& vec){
if (this == &vec){
return *this;
}
x = vec.x;
y = vec.y;
return *this;
};
Vec2D& operator+=(const Vec2D& vec){
this->x += vec.x;
this->y += vec.y;
return *this;
};
friend Vec2D operator+(const Vec2D& left, const Vec2D& right){
return Vec2D(left.x + right.x, left.y + right.y);
};
Vec2D& operator-=(const Vec2D& vec){
this->x -= vec.x;
this->y -= vec.y;
return *this;
};
friend Vec2D operator-(const Vec2D& left, const Vec2D& right){
return Vec2D(left.x - right.x, left.y - right.y);
};
Vec2D& operator*(const Vec2D& vec){
this->x *= vec.x;
this->y *= vec.y;
return *this;
};
Vec2D& operator*(T scalar){
this->x *= scalar;
this->y *= scalar;
return *this;
};
};
struct Color{
int r;
int g;
int b;
};