Extract Vector

This commit is contained in:
Oshgnacknak 2021-12-29 14:22:22 +01:00
parent 7e99f4b204
commit 1f5892a1b7
Signed by: Oshgnacknak
GPG key ID: 8CB7375654585956
2 changed files with 61 additions and 0 deletions

37
src/Vector.cpp Normal file
View file

@ -0,0 +1,37 @@
#include "Vector.h"
Vector2::Vector2(double x, double y) : x(x), y(y) {}
Vector2 Vector2::conjugate() {
return {x, -y};
}
Vector2 Vector2::operator*(double d) {
return {x*d, y*d};
}
Vector2 Vector2::operator*=(double d) {
x *= d;
y *= d;
return *this;
}
Vector2 Vector2::operator+(Vector2 v) {
return {x+v.x, y+v.y};
}
Vector2 Vector2::operator+=(Vector2 v) {
x += v.x;
y += v.y;
return *this;
}
Vector2 Vector2::operator-(Vector2 v) {
return {x-v.x, y-v.y};
}
Vector2 Vector2::operator-=(Vector2 v) {
x -= v.x;
y -= v.y;
return *this;
}

24
src/Vector.h Normal file
View file

@ -0,0 +1,24 @@
#ifndef VECTOR_H
#define VECTOR_H
struct Vector2 {
double x, y;
Vector2(double x = 0, double y = 0);
Vector2 conjugate();
Vector2 operator*(double d);
Vector2 operator*=(double d);
Vector2 operator+(Vector2 v);
Vector2 operator+=(Vector2 v);
Vector2 operator-(Vector2 v);
Vector2 operator-=(Vector2 v);
};
#endif /* VECTOR_H */