improvement

This commit is contained in:
2025-09-25 21:43:33 +03:00
parent dac3d8e43f
commit 92dab52d66
5 changed files with 61 additions and 11 deletions

View File

@@ -179,20 +179,20 @@ struct std::formatter<omath::Color> // NOLINT(*-dcl58-cpp)
[[nodiscard]] [[nodiscard]]
static auto format(const omath::Color& col, FormatContext& ctx) static auto format(const omath::Color& col, FormatContext& ctx)
{ {
if constexpr (std::is_same_v<std::format_context::char_type, char>) if constexpr (std::is_same_v<typename FormatContext::char_type, char>)
return std::format_to(ctx.out(), "[r:{}, g:{}, b:{}, a:{}]", return std::format_to(ctx.out(), "[r:{}, g:{}, b:{}, a:{}]",
static_cast<int>(col.x * 255.f), static_cast<int>(col.x * 255.f),
static_cast<int>(col.y * 255.f), static_cast<int>(col.y * 255.f),
static_cast<int>(col.z * 255.f), static_cast<int>(col.z * 255.f),
static_cast<int>(col.w * 255.f)); static_cast<int>(col.w * 255.f));
if constexpr (std::is_same_v<std::format_context::char_type, wchar_t>) if constexpr (std::is_same_v<typename FormatContext::char_type, wchar_t>)
return std::format_to(ctx.out(), L"[r:{}, g:{}, b:{}, a:{}]", return std::format_to(ctx.out(), L"[r:{}, g:{}, b:{}, a:{}]",
static_cast<int>(col.x * 255.f), static_cast<int>(col.x * 255.f),
static_cast<int>(col.y * 255.f), static_cast<int>(col.y * 255.f),
static_cast<int>(col.z * 255.f), static_cast<int>(col.z * 255.f),
static_cast<int>(col.w * 255.f)); static_cast<int>(col.w * 255.f));
if constexpr (std::is_same_v<std::format_context::char_type, char8_t>) if constexpr (std::is_same_v<typename FormatContext::char_type, char8_t>)
return std::format_to(ctx.out(), u8"[r:{}, g:{}, b:{}, a:{}]", return std::format_to(ctx.out(), u8"[r:{}, g:{}, b:{}, a:{}]",
static_cast<int>(col.x * 255.f), static_cast<int>(col.x * 255.f),
static_cast<int>(col.y * 255.f), static_cast<int>(col.y * 255.f),

View File

@@ -328,6 +328,21 @@ namespace omath
return oss.str(); 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]] [[nodiscard]]
bool operator==(const Mat& mat) const bool operator==(const Mat& mat) const
{ {
@@ -706,9 +721,18 @@ struct std::formatter<omath::Mat<Rows, Columns, Type, StoreType>> // NOLINT(*-dc
{ {
return ctx.begin(); return ctx.begin();
} }
template<class FormatContext>
[[nodiscard]] [[nodiscard]]
static auto format(const MatType& mat, std::format_context& ctx) static auto format(const MatType& mat, FormatContext& ctx)
{ {
if constexpr (std::is_same_v<typename FormatContext::char_type, char>)
return std::format_to(ctx.out(), "{}", mat.to_string()); return std::format_to(ctx.out(), "{}", mat.to_string());
if constexpr (std::is_same_v<typename FormatContext::char_type, wchar_t>)
return std::format_to(ctx.out(), L"{}", mat.to_wstring());
if constexpr (std::is_same_v<typename FormatContext::char_type, char8_t>)
return std::format_to(ctx.out(), u8"{}", mat.to_u8string());
} }
}; };

View File

@@ -242,9 +242,18 @@ struct std::formatter<omath::Vector2<Type>> // NOLINT(*-dcl58-cpp)
{ {
return ctx.begin(); return ctx.begin();
} }
template<class FormatContext>
[[nodiscard]] [[nodiscard]]
static auto format(const omath::Vector2<Type>& vec, std::format_context& ctx) static auto format(const omath::Vector2<Type>& vec, FormatContext& ctx)
{ {
if constexpr (std::is_same_v<typename FormatContext::char_type, char>)
return std::format_to(ctx.out(), "[{}, {}]", vec.x, vec.y); return std::format_to(ctx.out(), "[{}, {}]", vec.x, vec.y);
if constexpr (std::is_same_v<typename FormatContext::char_type, wchar_t>)
return std::format_to(ctx.out(), L"[{}, {}]", vec.x, vec.y);
if constexpr (std::is_same_v<typename FormatContext::char_type, char8_t>)
return std::format_to(ctx.out(), u8"[{}, {}]", vec.x, vec.y);
} }
}; };

View File

@@ -303,9 +303,18 @@ struct std::formatter<omath::Vector3<Type>> // NOLINT(*-dcl58-cpp)
{ {
return ctx.begin(); return ctx.begin();
} }
template<class FormatContext>
[[nodiscard]] [[nodiscard]]
static auto format(const omath::Vector3<Type>& vec, std::format_context& ctx) static auto format(const omath::Vector3<Type>& vec, FormatContext& ctx)
{ {
if constexpr (std::is_same_v<typename FormatContext::char_type, char>)
return std::format_to(ctx.out(), "[{}, {}, {}]", vec.x, vec.y, vec.z); return std::format_to(ctx.out(), "[{}, {}, {}]", vec.x, vec.y, vec.z);
if constexpr (std::is_same_v<typename FormatContext::char_type, wchar_t>)
return std::format_to(ctx.out(), L"[{}, {}, {}]", vec.x, vec.y, vec.z);
if constexpr (std::is_same_v<typename FormatContext::char_type, char8_t>)
return std::format_to(ctx.out(), u8"[{}, {}, {}]", vec.x, vec.y, vec.z);
} }
}; };

View File

@@ -210,9 +210,17 @@ struct std::formatter<omath::Vector4<Type>> // NOLINT(*-dcl58-cpp)
{ {
return ctx.begin(); return ctx.begin();
} }
template<class FormatContext>
[[nodiscard]] [[nodiscard]]
static auto format(const omath::Vector4<Type>& vec, std::format_context& ctx) static auto format(const omath::Vector4<Type>& vec, FormatContext& ctx)
{ {
if constexpr (std::is_same_v<typename FormatContext::char_type, char>)
return std::format_to(ctx.out(), "[{}, {}, {}, {}]", vec.x, vec.y, vec.z, vec.w); return std::format_to(ctx.out(), "[{}, {}, {}, {}]", vec.x, vec.y, vec.z, vec.w);
if constexpr (std::is_same_v<typename FormatContext::char_type, wchar_t>)
return std::format_to(ctx.out(), L"[{}, {}, {}, {}]", vec.x, vec.y, vec.z, vec.w);
if constexpr (std::is_same_v<typename FormatContext::char_type, char8_t>)
return std::format_to(ctx.out(), u8"[{}, {}, {}, {}]", vec.x, vec.y, vec.z, vec.w);
} }
}; };