This commit is contained in:
2026-04-03 12:34:06 +02:00
parent cd77088dbf
commit 85dbded287
25 changed files with 2711 additions and 165 deletions

View File

@@ -35,6 +35,8 @@ struct decimal {
}
inline decimal &operator+=(const decimal &d) { return (*this) = {i + d.i}; }
inline decimal &operator-=(const decimal &d) { return (*this) = {i - d.i}; }
inline friend decimal operator-(const decimal &d1, const decimal &d2) {
return {d1.i - d2.i};
}
@@ -91,7 +93,7 @@ template <int n, class Dev> struct vec {
}
friend Dev operator+(const vec<n, Dev> &v1, const vec<n, Dev> &v2) {
Dev newV = {};
Dev newV;
for (int i = 0; i < n; i++) {
newV.v[i] = v1.v[i] + v2.v[i];
@@ -99,16 +101,24 @@ template <int n, class Dev> struct vec {
return newV;
}
friend Dev operator+=(const vec<n, Dev> &v1, const vec<n, Dev> &v2) {
Dev newV = {};
Dev newV;
for (int i = 0; i < n; i++) {
newV.v[i] = v1.v[i] + v2.v[i];
}
return newV;
}
friend Dev operator-=(const vec<n, Dev> &v1, const vec<n, Dev> &v2) {
Dev newV;
for (int i = 0; i < n; i++) {
newV.v[i] = v1.v[i] - v2.v[i];
}
return newV;
}
friend Dev operator-(const vec<n, Dev> &v1, const vec<n, Dev> &v2) {
Dev newV = {};
Dev newV;
for (int i = 0; i < n; i++) {
newV.v[i] = v1.v[i] - v2.v[i];
@@ -125,7 +135,7 @@ template <int n, class Dev> struct vec {
}
Dev operator-() {
Dev newV = {};
Dev newV;
for (int i = 0; i < n; i++) {
newV.v[i] = -v[i];
}
@@ -135,21 +145,21 @@ template <int n, class Dev> struct vec {
friend Dev operator*(const vec<n, Dev> &v, const decimal &d) {
int32_t f = d.i >> HALF_SHIFT;
Dev newV = {};
Dev newV;
for (int i = 0; i < n; i++) {
newV.v[i] = (v.v[i].i >> HALF_SHIFT) * f;
}
return newV;
}
static Dev max(const vec<n, Dev> &v1, const vec<n, Dev> &v2) {
Dev newV = {};
Dev newV;
for (int i = 0; i < n; i++) {
newV.v[i] = std::max(v1.v[i], v2.v[i]);
}
return newV;
}
static Dev min(const vec<n, Dev> &v1, const vec<n, Dev> &v2) {
Dev newV = {};
Dev newV;
for (int i = 0; i < n; i++) {
newV.v[i] = std::min(v1.v[i], v2.v[i]);
}
@@ -194,7 +204,7 @@ template <int n, class Dev> struct vec {
}
constexpr static Dev zero() {
Dev newV = {};
Dev newV;
for (int i = 0; i < n; i++) {
newV[i] = decimal(0);
}
@@ -203,6 +213,8 @@ template <int n, class Dev> struct vec {
};
struct vec2 : public vec<2, vec2> {
vec2() : vec<2, vec2>() {};
vec2(float x, float y) : vec<2, vec2>(decimal(x), decimal(y)) {}
vec2(double x, double y) : vec<2, vec2>(decimal(x), decimal(y)) {}
@@ -211,6 +223,8 @@ struct vec2 : public vec<2, vec2> {
vec2(decimal x, decimal y) : vec<2, vec2>(x, y) {}
template <class origVec> vec2(origVec v) : vec<2, vec2>(v.v[0], v.v[1]) {}
decimal &x() { return v[0]; }
decimal &y() { return v[1]; }
};