diff options
author | fschildt <florian.schildt@protonmail.com> | 2025-07-21 16:07:28 +0200 |
---|---|---|
committer | fschildt <florian.schildt@protonmail.com> | 2025-07-21 16:07:28 +0200 |
commit | b46a0d9369fbaa1938f0968ab216bc2d564a9c37 (patch) | |
tree | c28b75187d01be9642af56a54a6101f51b25e4a7 /src/basic |
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/defs.hpp | 14 | ||||
-rw-r--r-- | src/basic/math.cpp | 98 | ||||
-rw-r--r-- | src/basic/math.hpp | 59 |
3 files changed, 171 insertions, 0 deletions
diff --git a/src/basic/defs.hpp b/src/basic/defs.hpp new file mode 100644 index 0000000..bfd302e --- /dev/null +++ b/src/basic/defs.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include <cassert> +#include <cstdint> +#include <cstddef> + +#define ARRAY_COUNT(x) (sizeof(x) / sizeof(x[0])) + +#define InvalidDefaultCase assert(0) + +#define KIBIBYTES(x) ((x)*1024) +#define MEBIBYTES(x) ((x)*KIBIBYTES(1024)) +#define GIBIBYTES(x) ((x)*MEBIBYTES(1024)) + diff --git a/src/basic/math.cpp b/src/basic/math.cpp new file mode 100644 index 0000000..3067255 --- /dev/null +++ b/src/basic/math.cpp @@ -0,0 +1,98 @@ +#include <basic/math.hpp> + + +V2ST::V2ST(size_t x, size_t y) : x(x), y(y) { +} + +V2ST::V2ST(int32_t x, int32_t y) : x((size_t)x), y((size_t)y) { +} + +bool V2ST::operator==(V2ST &b) { + bool result = this->x == b.x && this->y == b.y; + return result; +} + + +V2F32::V2F32(float x, float y) { + this->x = x; + this->y = y; +} + +V2F32 V2F32::operator/(float scalar) { + V2F32 result = {}; + result.x = this->x / scalar; + result.y = this->y / scalar; + return result; +} + +V2F32 V2F32::operator*(float scalar) { + V2F32 result = {}; + result.x = this->x * scalar; + result.y = this->y * scalar; + return result; +} + +V2F32 V2F32::operator+(V2F32 other) { + V2F32 result = {}; + result.x = this->x + other.x; + result.y = this->y + other.y; + return result; +} + + +V3F32::V3F32(float x, float y, float z) { + this->x = x; + this->y = y; + this->z = z; +} + +V3F32 V3F32::operator/(float scalar) { + V3F32 result = {}; + result.x = this->x / scalar; + result.y = this->y / scalar; + result.z = this->z / scalar; + return result; +} + +V3F32 V3F32::operator*(float scalar) { + V3F32 result = {}; + result.x = this->x * scalar; + result.y = this->y * scalar; + result.z = this->z * scalar; + return result; +} + + +V4F32::V4F32(float x, float y, float z, float w) { + this->x = x; + this->y = y; + this->z = z; + this->w = w; +} + +V4F32 V4F32::operator/(float scalar) { + V4F32 result = {}; + result.x = this->x / scalar; + result.y = this->y / scalar; + result.z = this->z / scalar; + result.w = this->w / scalar; + return result; +} + +V4F32 V4F32::operator*(float scalar) { + V4F32 result = {}; + result.x = this->x * scalar; + result.y = this->y * scalar; + result.z = this->z * scalar; + result.w = this->z * scalar; + return result; +} + +V2I32::V2I32(int32_t x, int32_t y) : x(x), y(y) { +} + +bool V2I32::operator==(V2I32 other) { + bool result = x == other.x && y == other.y; + return result; +} + diff --git a/src/basic/math.hpp b/src/basic/math.hpp new file mode 100644 index 0000000..0f21181 --- /dev/null +++ b/src/basic/math.hpp @@ -0,0 +1,59 @@ +#pragma once + +#include <basic/defs.hpp> + +struct V2ST { + size_t x; + size_t y; + + V2ST() = default; + V2ST(size_t x, size_t y); + V2ST(int32_t x, int32_t y); + bool operator==(V2ST &b); + bool operator==(const V2ST& other) const { + return x == other.x && y == other.y; + } +}; + +struct V2F32 { + float x; + float y; + + V2F32() = default; + V2F32(float x, float y); + V2F32 operator/(float scalar); + V2F32 operator*(float scalar); + V2F32 operator+(V2F32 other); +}; + +struct V3F32 { + float x; + float y; + float z; + + V3F32() = default; + V3F32(float x, float y, float z); + V3F32 operator/(float scalar); + V3F32 operator*(float scalar); +}; + +struct V4F32 { + float x; + float y; + float z; + float w; + + V4F32() = default; + V4F32 (float x, float y, float z, float w); + V4F32 operator/(float scalar); + V4F32 operator*(float scalar); +}; + +struct V2I32 { + int32_t x; + int32_t y; + + V2I32() = default; + V2I32 (int32_t x, int32_t y); + bool operator==(V2I32 other); +}; |