diff --git a/modules/math/public/mat4.hpp b/modules/math/public/mat4.hpp index 499f471..c94dd12 100644 --- a/modules/math/public/mat4.hpp +++ b/modules/math/public/mat4.hpp @@ -9,7 +9,7 @@ template struct mat4_impl { using Column_T = vec4_impl; - explicit mat4_impl(T scalar = 0) + constexpr explicit mat4_impl(T scalar = 0) : values( { Column_T { scalar }, @@ -22,7 +22,7 @@ struct mat4_impl } // clang-format off - mat4_impl( + constexpr mat4_impl( const T& x0, const T& y0, const T& z0, const T& w0, const T& x1, const T& y1, const T& z1, const T& w1, const T& x2, const T& y2, const T& z2, const T& w2, @@ -33,7 +33,7 @@ struct mat4_impl { } - mat4_impl( + constexpr mat4_impl( const Column_T &column_x, const Column_T &column_y, const Column_T &column_z, @@ -53,22 +53,22 @@ struct mat4_impl }; } - [[nodiscard]] auto operator[](size_t idx) -> Column_T & + [[nodiscard]] constexpr auto operator[](size_t idx) -> Column_T & { return values[idx]; } - [[nodiscard]] auto operator[](size_t idx) const -> const Column_T & + [[nodiscard]] constexpr auto operator[](size_t idx) const -> const Column_T & { return values[idx]; } - [[nodiscard]] auto operator*(const mat4_impl &other) const -> mat4_impl + [[nodiscard]] constexpr auto operator*(const mat4_impl &other) const -> mat4_impl { return mat4_impl {}; } - [[nodiscard]] auto operator*(const vec4_impl &other) const -> vec4_impl + [[nodiscard]] constexpr auto operator*(const vec4_impl &other) const -> vec4_impl { return vec4_impl {}; } diff --git a/modules/math/public/vec2.hpp b/modules/math/public/vec2.hpp index abe7382..3f1cd2a 100644 --- a/modules/math/public/vec2.hpp +++ b/modules/math/public/vec2.hpp @@ -51,7 +51,6 @@ struct vec2_impl }; } - T x; // NOLINT T y; // NOLINT @@ -65,3 +64,17 @@ using ivec2 = vec2_impl; using uvec2 = vec2_impl; } // namespace lt::math + +template +struct std::formatter> +{ + constexpr auto parse(std::format_parse_context &context) + { + return context.begin(); + } + + auto format(const lt::math::vec2_impl &val, std::format_context &context) const + { + return std::format_to(context.out(), "{}, {}", val.x, val.y); + } +}; diff --git a/modules/math/public/vec3.hpp b/modules/math/public/vec3.hpp index 9261dbe..c01c901 100644 --- a/modules/math/public/vec3.hpp +++ b/modules/math/public/vec3.hpp @@ -47,6 +47,12 @@ struct vec3_impl }; } + friend auto operator<<(std::ostream &stream, vec3_impl value) -> std::ostream & + { + stream << value.x << ", " << value.y << ", " << value.z; + return stream; + } + T x; // NOLINT T y; // NOLINT @@ -61,3 +67,17 @@ using ivec3 = vec3_impl; using uvec3 = vec3_impl; } // namespace lt::math + +template +struct std::formatter> +{ + constexpr auto parse(std::format_parse_context &context) + { + return context.begin(); + } + + auto format(const lt::math::vec3_impl &val, std::format_context &context) const + { + return std::format_to(context.out(), "{}, {}, {}", val.x, val.y, val.z); + } +}; diff --git a/modules/math/public/vec4.hpp b/modules/math/public/vec4.hpp index e2ef53a..917cfb0 100644 --- a/modules/math/public/vec4.hpp +++ b/modules/math/public/vec4.hpp @@ -7,19 +7,29 @@ namespace lt::math { template struct vec4_impl { - vec4_impl(): x(), y(), z(), w() + constexpr vec4_impl(): x(), y(), z(), w() { } - explicit vec4_impl(T scalar): x(scalar), y(scalar), z(scalar), w(scalar) + constexpr explicit vec4_impl(T scalar): x(scalar), y(scalar), z(scalar), w(scalar) { } - vec4_impl(T x, T y, T z, T w): x(x), y(y), z(z), w(w) + constexpr vec4_impl(T x, T y, T z, T w): x(x), y(y), z(z), w(w) { } - [[nodiscard]] auto operator-(const vec4_impl &other) const -> vec4_impl + [[nodiscard]] auto operator==(const vec4_impl &other) const -> bool + { + return x == other.x && y == other.y && z == other.z && w == other.w; + } + + [[nodiscard]] auto operator!=(const vec4_impl &other) const -> bool + { + return !(*this == other); + } + + [[nodiscard]] constexpr auto operator-(const vec4_impl &other) const -> vec4_impl { return { x - other.x, @@ -29,12 +39,12 @@ struct vec4_impl }; } - [[nodiscard]] auto operator[](size_t idx) -> T & + [[nodiscard]] constexpr auto operator[](size_t idx) -> T & { return values[idx]; } - [[nodiscard]] auto operator[](size_t idx) const -> const T & + [[nodiscard]] constexpr auto operator[](size_t idx) const -> const T & { return values[idx]; } @@ -82,3 +92,17 @@ using ivec4 = vec4_impl; using uvec4 = vec4_impl; } // namespace lt::math + +template +struct std::formatter> +{ + constexpr auto parse(std::format_parse_context &context) + { + return context.begin(); + } + + auto format(const lt::math::vec4_impl &val, std::format_context &context) const + { + return std::format_to(context.out(), "{}, {}, {}, {}", val.x, val.y, val.z, val.w); + } +};