diff --git a/modules/math/public/vec2.hpp b/modules/math/public/vec2.hpp index 694d97d..abe7382 100644 --- a/modules/math/public/vec2.hpp +++ b/modules/math/public/vec2.hpp @@ -5,18 +5,28 @@ namespace lt::math { template struct vec2_impl { - vec2_impl(): x(), y() + constexpr vec2_impl(): x(), y() { } - explicit vec2_impl(T scalar): x(scalar), y(scalar) + constexpr explicit vec2_impl(T scalar): x(scalar), y(scalar) { } - vec2_impl(T x, T y): x(x), y(y) + constexpr vec2_impl(T x, T y): x(x), y(y) { } + [[nodiscard]] auto operator==(const vec2_impl &other) const -> bool + { + return x == other.x && y == other.y; + } + + [[nodiscard]] auto operator!=(const vec2_impl &other) const -> bool + { + return !(*this == other); + } + [[nodiscard]] auto operator*(const vec2_impl &other) const -> vec2_impl { return { @@ -47,6 +57,7 @@ struct vec2_impl T y; // NOLINT }; + using vec2 = vec2_impl; using ivec2 = vec2_impl; diff --git a/modules/math/public/vec3.hpp b/modules/math/public/vec3.hpp index 685a0c3..9261dbe 100644 --- a/modules/math/public/vec3.hpp +++ b/modules/math/public/vec3.hpp @@ -7,19 +7,29 @@ namespace lt::math { template struct vec3_impl { - vec3_impl(): x(), y(), z() + constexpr vec3_impl(): x(), y(), z() { } - explicit vec3_impl(T scalar): x(scalar), y(scalar), z(scalar) + constexpr explicit vec3_impl(T scalar): x(scalar), y(scalar), z(scalar) { } - vec3_impl(T x, T y, T z): x(x), y(y), z(z) + constexpr vec3_impl(T x, T y, T z): x(x), y(y), z(z) { } - [[nodiscard]] auto operator-(const vec3_impl &other) const -> vec3_impl + [[nodiscard]] auto operator==(const vec3_impl &other) const -> bool + { + return x == other.x && y == other.y && z == other.z; + } + + [[nodiscard]] auto operator!=(const vec3_impl &other) const -> bool + { + return !(*this == other); + } + + [[nodiscard]] constexpr auto operator-(const vec3_impl &other) const -> vec3_impl { return { x - other.x, @@ -28,7 +38,7 @@ struct vec3_impl }; } - [[nodiscard]] auto operator*(const vec3_impl &other) const -> vec3_impl + [[nodiscard]] constexpr auto operator*(const vec3_impl &other) const -> vec3_impl { return { x * other.x, diff --git a/modules/math/public/vec4.hpp b/modules/math/public/vec4.hpp index d505446..e2ef53a 100644 --- a/modules/math/public/vec4.hpp +++ b/modules/math/public/vec4.hpp @@ -39,6 +39,12 @@ struct vec4_impl return values[idx]; } + friend auto operator<<(std::ostream &stream, vec4_impl value) -> std::ostream & + { + stream << value.x << ", " << value.y << ", " << value.z << ", " << value.w; + return stream; + } + // NOLINTNEXTLINE union {