From 5a8bc0a4936cdd461c43740437541f8c991ff117 Mon Sep 17 00:00:00 2001 From: vimene Date: Sun, 3 Dec 2023 09:16:18 +0100 Subject: renamed math_vector.{h,cpp} to vector.{h,cpp} --- src/math/math_vector.cpp | 175 ----------------------------------------------- src/math/math_vector.h | 73 -------------------- src/math/vector.cpp | 175 +++++++++++++++++++++++++++++++++++++++++++++++ src/math/vector.h | 73 ++++++++++++++++++++ 4 files changed, 248 insertions(+), 248 deletions(-) delete mode 100644 src/math/math_vector.cpp delete mode 100644 src/math/math_vector.h create mode 100644 src/math/vector.cpp create mode 100644 src/math/vector.h diff --git a/src/math/math_vector.cpp b/src/math/math_vector.cpp deleted file mode 100644 index aacff86..0000000 --- a/src/math/math_vector.cpp +++ /dev/null @@ -1,175 +0,0 @@ -#include "math/math_vector.h" -#include - -using namespace engine::math; - -MathVector2::MathVector2() { -} - -MathVector2::MathVector2(float x, float y) : x{x}, y{y} { -} - -bool MathVector2::operator==(MathVector2 other) const { - return x == other.x && y == other.y; -} - -bool MathVector2::operator!=(MathVector2 other) const { - return !(*this == other); -} - -MathVector2 MathVector2::operator+() const { - return *this; -} - -MathVector2 MathVector2::operator-() const { - return { -x, -y }; -} - -MathVector2 MathVector2::operator+(MathVector2 other) const { - return { x + other.x, y + other.y }; -} - -MathVector2 MathVector2::operator-(MathVector2 other) const { - return *this + (-other); -} - -float MathVector2::det(MathVector2 other) const { - return this->x * other.y - other.x * this->y; -} - -MathVector2 MathVector2::round() const { - return { std::round(x), std::round(y) }; -} - -MathVector2 engine::math::operator*(float n, MathVector2 other) { - return { n * other.x, n * other.y }; -} - -MathVector2 engine::math::operator*(MathVector2 other, float n) { - return n * other; -} - -MathVector2 engine::math::operator/(MathVector2 other, float n) { - return { other.x / n, other.y / n }; -} - -MathVector3::MathVector3() { -} - -MathVector3::MathVector3(float x, float y, float z) : x{x}, y{y}, z{z} { -} - -bool MathVector3::operator==(MathVector3 other) const { - return x == other.x && y == other.y && z == other.z; -} - -bool MathVector3::operator!=(MathVector3 other) const { - return !(*this == other); -} - -MathVector3 MathVector3::operator+() const { - return *this; -} - -MathVector3 MathVector3::operator-() const { - return { -x, -y, -z }; -} - -MathVector3 MathVector3::operator+(MathVector3 other) const { - return { x + other.x, y + other.y, z + other.z }; -} - -MathVector3 MathVector3::operator-(MathVector3 other) const { - return *this + (-other); -} - -MathVector3 MathVector3::round() const { - return { std::round(x), std::round(y), std::round(z) }; -} - -MathVector2 MathVector3::xy() const { - return { x, y }; -} - -MathVector3 MathVector3::cross(MathVector3 other) const { - return { - y * other.z - z * other.y, - z * other.x - x * other.z, - x * other.y - y * other.x - }; -} - -MathVector3 engine::math::operator*(float n, MathVector3 other) { - return { n * other.x, n * other.y, n * other.z }; -} - -MathVector3 engine::math::operator*(MathVector3 other, float n) { - return n * other; -} - -MathVector3 engine::math::operator/(MathVector3 other, float n) { - return { other.x / n, other.y / n, other.z / n }; -} - -MathVector4::MathVector4() { -} - -MathVector4::MathVector4(float x, float y, float z, float w) : x{x}, y{y}, z{z}, w{w} { -} - -MathVector4::MathVector4(float x, float y, float z) : x{x}, y{y}, z{z}, w{1.f} { -} - -MathVector4::MathVector4(MathVector3 v, float w) : x{v.x}, y{v.y}, z{v.z}, w{w} { -} - -MathVector4::MathVector4(MathVector3 v) : x{v.x}, y{v.y}, z{v.z}, w{1.f} { -} - -bool MathVector4::operator==(MathVector4 other) const { - return x == other.x && y == other.y && z == other.z && w == other.w; -} - -bool MathVector4::operator!=(MathVector4 other) const { - return !(*this == other); -} - -MathVector4 MathVector4::operator+() const { - return *this; -} - -MathVector4 MathVector4::operator-() const { - return { -x, -y, -z, -w }; -} - -MathVector4 MathVector4::operator+(MathVector4 other) const { - return { x + other.x, y + other.y, z + other.z, w + other.w }; -} - -MathVector4 MathVector4::operator-(MathVector4 other) const { - return *this + (-other); -} - -MathVector4 MathVector4::round() const { - return { std::round(x), std::round(y), std::round(z), std::round(w) }; -} - -MathVector3 MathVector4::xyz() const { - return { x, y, z }; -} - -MathVector3 MathVector4::div_by_w() const { - return xyz() / w; -} - -MathVector4 engine::math::operator*(float n, MathVector4 other) { - return { n * other.x, n * other.y, n * other.z, n * other.w }; -} - -MathVector4 engine::math::operator*(MathVector4 other, float n) { - return n * other; -} - -MathVector4 engine::math::operator/(MathVector4 other, float n) { - return { other.x / n, other.y / n, other.z / n, other.w / n }; -} diff --git a/src/math/math_vector.h b/src/math/math_vector.h deleted file mode 100644 index 28ae81e..0000000 --- a/src/math/math_vector.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef MATH_MATH_VECTOR_H -#define MATH_MATH_VECTOR_H - -namespace engine::math { - -class MathVector2 { - public: - float x, y; - - MathVector2(); - MathVector2(float x, float y); - bool operator==(MathVector2 other) const; - bool operator!=(MathVector2 other) const; - MathVector2 operator+() const; - MathVector2 operator-() const; - MathVector2 operator+(MathVector2 other) const; - MathVector2 operator-(MathVector2 other) const; - float det(MathVector2 other) const; - MathVector2 round() const; -}; - -MathVector2 operator*(float n, MathVector2 other); -MathVector2 operator*(MathVector2 other, float n); -MathVector2 operator/(MathVector2 other, float n); - -class MathVector3 { - public: - float x, y, z; - - MathVector3(); - MathVector3(float x, float y, float z); - bool operator==(MathVector3 other) const; - bool operator!=(MathVector3 other) const; - MathVector3 operator+() const; - MathVector3 operator-() const; - MathVector3 operator+(MathVector3 other) const; - MathVector3 operator-(MathVector3 other) const; - MathVector3 round() const; - MathVector2 xy() const; - MathVector3 cross(MathVector3 other) const; -}; - -MathVector3 operator*(float n, MathVector3 other); -MathVector3 operator*(MathVector3 other, float n); -MathVector3 operator/(MathVector3 other, float n); - -class MathVector4 { - public: - float x, y, z, w; - - MathVector4(); - MathVector4(float x, float y, float z, float w); - MathVector4(float x, float y, float z); - MathVector4(MathVector3 v, float w); - MathVector4(MathVector3 v); - bool operator==(MathVector4 other) const; - bool operator!=(MathVector4 other) const; - MathVector4 operator+() const; - MathVector4 operator-() const; - MathVector4 operator+(MathVector4 other) const; - MathVector4 operator-(MathVector4 other) const; - MathVector4 round() const; - MathVector3 xyz() const; - MathVector3 div_by_w() const; -}; - -MathVector4 operator*(float n, MathVector4 other); -MathVector4 operator*(MathVector4 other, float n); -MathVector4 operator/(MathVector4 other, float n); - -} - -#endif // MATH_MATH_VECTOR_H diff --git a/src/math/vector.cpp b/src/math/vector.cpp new file mode 100644 index 0000000..aacff86 --- /dev/null +++ b/src/math/vector.cpp @@ -0,0 +1,175 @@ +#include "math/math_vector.h" +#include + +using namespace engine::math; + +MathVector2::MathVector2() { +} + +MathVector2::MathVector2(float x, float y) : x{x}, y{y} { +} + +bool MathVector2::operator==(MathVector2 other) const { + return x == other.x && y == other.y; +} + +bool MathVector2::operator!=(MathVector2 other) const { + return !(*this == other); +} + +MathVector2 MathVector2::operator+() const { + return *this; +} + +MathVector2 MathVector2::operator-() const { + return { -x, -y }; +} + +MathVector2 MathVector2::operator+(MathVector2 other) const { + return { x + other.x, y + other.y }; +} + +MathVector2 MathVector2::operator-(MathVector2 other) const { + return *this + (-other); +} + +float MathVector2::det(MathVector2 other) const { + return this->x * other.y - other.x * this->y; +} + +MathVector2 MathVector2::round() const { + return { std::round(x), std::round(y) }; +} + +MathVector2 engine::math::operator*(float n, MathVector2 other) { + return { n * other.x, n * other.y }; +} + +MathVector2 engine::math::operator*(MathVector2 other, float n) { + return n * other; +} + +MathVector2 engine::math::operator/(MathVector2 other, float n) { + return { other.x / n, other.y / n }; +} + +MathVector3::MathVector3() { +} + +MathVector3::MathVector3(float x, float y, float z) : x{x}, y{y}, z{z} { +} + +bool MathVector3::operator==(MathVector3 other) const { + return x == other.x && y == other.y && z == other.z; +} + +bool MathVector3::operator!=(MathVector3 other) const { + return !(*this == other); +} + +MathVector3 MathVector3::operator+() const { + return *this; +} + +MathVector3 MathVector3::operator-() const { + return { -x, -y, -z }; +} + +MathVector3 MathVector3::operator+(MathVector3 other) const { + return { x + other.x, y + other.y, z + other.z }; +} + +MathVector3 MathVector3::operator-(MathVector3 other) const { + return *this + (-other); +} + +MathVector3 MathVector3::round() const { + return { std::round(x), std::round(y), std::round(z) }; +} + +MathVector2 MathVector3::xy() const { + return { x, y }; +} + +MathVector3 MathVector3::cross(MathVector3 other) const { + return { + y * other.z - z * other.y, + z * other.x - x * other.z, + x * other.y - y * other.x + }; +} + +MathVector3 engine::math::operator*(float n, MathVector3 other) { + return { n * other.x, n * other.y, n * other.z }; +} + +MathVector3 engine::math::operator*(MathVector3 other, float n) { + return n * other; +} + +MathVector3 engine::math::operator/(MathVector3 other, float n) { + return { other.x / n, other.y / n, other.z / n }; +} + +MathVector4::MathVector4() { +} + +MathVector4::MathVector4(float x, float y, float z, float w) : x{x}, y{y}, z{z}, w{w} { +} + +MathVector4::MathVector4(float x, float y, float z) : x{x}, y{y}, z{z}, w{1.f} { +} + +MathVector4::MathVector4(MathVector3 v, float w) : x{v.x}, y{v.y}, z{v.z}, w{w} { +} + +MathVector4::MathVector4(MathVector3 v) : x{v.x}, y{v.y}, z{v.z}, w{1.f} { +} + +bool MathVector4::operator==(MathVector4 other) const { + return x == other.x && y == other.y && z == other.z && w == other.w; +} + +bool MathVector4::operator!=(MathVector4 other) const { + return !(*this == other); +} + +MathVector4 MathVector4::operator+() const { + return *this; +} + +MathVector4 MathVector4::operator-() const { + return { -x, -y, -z, -w }; +} + +MathVector4 MathVector4::operator+(MathVector4 other) const { + return { x + other.x, y + other.y, z + other.z, w + other.w }; +} + +MathVector4 MathVector4::operator-(MathVector4 other) const { + return *this + (-other); +} + +MathVector4 MathVector4::round() const { + return { std::round(x), std::round(y), std::round(z), std::round(w) }; +} + +MathVector3 MathVector4::xyz() const { + return { x, y, z }; +} + +MathVector3 MathVector4::div_by_w() const { + return xyz() / w; +} + +MathVector4 engine::math::operator*(float n, MathVector4 other) { + return { n * other.x, n * other.y, n * other.z, n * other.w }; +} + +MathVector4 engine::math::operator*(MathVector4 other, float n) { + return n * other; +} + +MathVector4 engine::math::operator/(MathVector4 other, float n) { + return { other.x / n, other.y / n, other.z / n, other.w / n }; +} diff --git a/src/math/vector.h b/src/math/vector.h new file mode 100644 index 0000000..28ae81e --- /dev/null +++ b/src/math/vector.h @@ -0,0 +1,73 @@ +#ifndef MATH_MATH_VECTOR_H +#define MATH_MATH_VECTOR_H + +namespace engine::math { + +class MathVector2 { + public: + float x, y; + + MathVector2(); + MathVector2(float x, float y); + bool operator==(MathVector2 other) const; + bool operator!=(MathVector2 other) const; + MathVector2 operator+() const; + MathVector2 operator-() const; + MathVector2 operator+(MathVector2 other) const; + MathVector2 operator-(MathVector2 other) const; + float det(MathVector2 other) const; + MathVector2 round() const; +}; + +MathVector2 operator*(float n, MathVector2 other); +MathVector2 operator*(MathVector2 other, float n); +MathVector2 operator/(MathVector2 other, float n); + +class MathVector3 { + public: + float x, y, z; + + MathVector3(); + MathVector3(float x, float y, float z); + bool operator==(MathVector3 other) const; + bool operator!=(MathVector3 other) const; + MathVector3 operator+() const; + MathVector3 operator-() const; + MathVector3 operator+(MathVector3 other) const; + MathVector3 operator-(MathVector3 other) const; + MathVector3 round() const; + MathVector2 xy() const; + MathVector3 cross(MathVector3 other) const; +}; + +MathVector3 operator*(float n, MathVector3 other); +MathVector3 operator*(MathVector3 other, float n); +MathVector3 operator/(MathVector3 other, float n); + +class MathVector4 { + public: + float x, y, z, w; + + MathVector4(); + MathVector4(float x, float y, float z, float w); + MathVector4(float x, float y, float z); + MathVector4(MathVector3 v, float w); + MathVector4(MathVector3 v); + bool operator==(MathVector4 other) const; + bool operator!=(MathVector4 other) const; + MathVector4 operator+() const; + MathVector4 operator-() const; + MathVector4 operator+(MathVector4 other) const; + MathVector4 operator-(MathVector4 other) const; + MathVector4 round() const; + MathVector3 xyz() const; + MathVector3 div_by_w() const; +}; + +MathVector4 operator*(float n, MathVector4 other); +MathVector4 operator*(MathVector4 other, float n); +MathVector4 operator/(MathVector4 other, float n); + +} + +#endif // MATH_MATH_VECTOR_H -- cgit v1.2.3