diff --git a/include/omath/color.hpp b/include/omath/color.hpp index b606231..7de2efe 100644 --- a/include/omath/color.hpp +++ b/include/omath/color.hpp @@ -179,20 +179,20 @@ struct std::formatter // NOLINT(*-dcl58-cpp) [[nodiscard]] static auto format(const omath::Color& col, FormatContext& ctx) { - if constexpr (std::is_same_v) + if constexpr (std::is_same_v) return std::format_to(ctx.out(), "[r:{}, g:{}, b:{}, a:{}]", static_cast(col.x * 255.f), static_cast(col.y * 255.f), static_cast(col.z * 255.f), static_cast(col.w * 255.f)); - if constexpr (std::is_same_v) + if constexpr (std::is_same_v) return std::format_to(ctx.out(), L"[r:{}, g:{}, b:{}, a:{}]", static_cast(col.x * 255.f), static_cast(col.y * 255.f), static_cast(col.z * 255.f), static_cast(col.w * 255.f)); - if constexpr (std::is_same_v) + if constexpr (std::is_same_v) return std::format_to(ctx.out(), u8"[r:{}, g:{}, b:{}, a:{}]", static_cast(col.x * 255.f), static_cast(col.y * 255.f), diff --git a/include/omath/linear_algebra/mat.hpp b/include/omath/linear_algebra/mat.hpp index 3549db2..b926edd 100644 --- a/include/omath/linear_algebra/mat.hpp +++ b/include/omath/linear_algebra/mat.hpp @@ -328,6 +328,21 @@ namespace omath return oss.str(); } + [[nodiscard]] + std::wstring to_wstring() const noexcept + { + const auto ascii_string = to_string(); + return {ascii_string.cbegin(), ascii_string.cend()}; + } + + [[nodiscard]] + // ReSharper disable once CppInconsistentNaming + std::u8string to_u8string() const noexcept + { + const auto ascii_string = to_string(); + return {ascii_string.cbegin(), ascii_string.cend()}; + } + [[nodiscard]] bool operator==(const Mat& mat) const { @@ -706,9 +721,18 @@ struct std::formatter> // NOLINT(*-dc { return ctx.begin(); } + + template [[nodiscard]] - static auto format(const MatType& mat, std::format_context& ctx) + static auto format(const MatType& mat, FormatContext& ctx) { - return std::format_to(ctx.out(), "{}", mat.to_string()); + if constexpr (std::is_same_v) + return std::format_to(ctx.out(), "{}", mat.to_string()); + + if constexpr (std::is_same_v) + return std::format_to(ctx.out(), L"{}", mat.to_wstring()); + + if constexpr (std::is_same_v) + return std::format_to(ctx.out(), u8"{}", mat.to_u8string()); } }; \ No newline at end of file diff --git a/include/omath/linear_algebra/vector2.hpp b/include/omath/linear_algebra/vector2.hpp index 7e8ddc8..4dc96c7 100644 --- a/include/omath/linear_algebra/vector2.hpp +++ b/include/omath/linear_algebra/vector2.hpp @@ -242,9 +242,18 @@ struct std::formatter> // NOLINT(*-dcl58-cpp) { return ctx.begin(); } + + template [[nodiscard]] - static auto format(const omath::Vector2& vec, std::format_context& ctx) + static auto format(const omath::Vector2& vec, FormatContext& ctx) { - return std::format_to(ctx.out(), "[{}, {}]", vec.x, vec.y); + if constexpr (std::is_same_v) + return std::format_to(ctx.out(), "[{}, {}]", vec.x, vec.y); + + if constexpr (std::is_same_v) + return std::format_to(ctx.out(), L"[{}, {}]", vec.x, vec.y); + + if constexpr (std::is_same_v) + return std::format_to(ctx.out(), u8"[{}, {}]", vec.x, vec.y); } }; diff --git a/include/omath/linear_algebra/vector3.hpp b/include/omath/linear_algebra/vector3.hpp index e5f4fda..63e731e 100644 --- a/include/omath/linear_algebra/vector3.hpp +++ b/include/omath/linear_algebra/vector3.hpp @@ -303,9 +303,18 @@ struct std::formatter> // NOLINT(*-dcl58-cpp) { return ctx.begin(); } + + template [[nodiscard]] - static auto format(const omath::Vector3& vec, std::format_context& ctx) + static auto format(const omath::Vector3& vec, FormatContext& ctx) { - return std::format_to(ctx.out(), "[{}, {}, {}]", vec.x, vec.y, vec.z); + if constexpr (std::is_same_v) + return std::format_to(ctx.out(), "[{}, {}, {}]", vec.x, vec.y, vec.z); + + if constexpr (std::is_same_v) + return std::format_to(ctx.out(), L"[{}, {}, {}]", vec.x, vec.y, vec.z); + + if constexpr (std::is_same_v) + return std::format_to(ctx.out(), u8"[{}, {}, {}]", vec.x, vec.y, vec.z); } }; diff --git a/include/omath/linear_algebra/vector4.hpp b/include/omath/linear_algebra/vector4.hpp index 95c095f..d1e1377 100644 --- a/include/omath/linear_algebra/vector4.hpp +++ b/include/omath/linear_algebra/vector4.hpp @@ -210,9 +210,17 @@ struct std::formatter> // NOLINT(*-dcl58-cpp) { return ctx.begin(); } + template [[nodiscard]] - static auto format(const omath::Vector4& vec, std::format_context& ctx) + static auto format(const omath::Vector4& vec, FormatContext& ctx) { - return std::format_to(ctx.out(), "[{}, {}, {}, {}]", vec.x, vec.y, vec.z, vec.w); + if constexpr (std::is_same_v) + return std::format_to(ctx.out(), "[{}, {}, {}, {}]", vec.x, vec.y, vec.z, vec.w); + + if constexpr (std::is_same_v) + return std::format_to(ctx.out(), L"[{}, {}, {}, {}]", vec.x, vec.y, vec.z, vec.w); + + if constexpr (std::is_same_v) + return std::format_to(ctx.out(), u8"[{}, {}, {}, {}]", vec.x, vec.y, vec.z, vec.w); } }; \ No newline at end of file