Update to open3d conversion logic
Merge remote-tracking branch 'origin/fmt_formatter_for_math'
This commit is contained in:
@@ -13,9 +13,17 @@
|
||||
#else
|
||||
#error "Failed to find fmt include"
|
||||
#endif
|
||||
#include "Math/ByteSize.hpp"
|
||||
#include "Math/Math.hpp"
|
||||
#include "Math/ByteSize.hpp"
|
||||
#include "Math/DenseVector3i.hpp"
|
||||
#include "Math/Float16.hpp"
|
||||
#include "Math/Int24.hpp"
|
||||
#include "Math/Range.hpp"
|
||||
#include "Math/RGB10A2.hpp"
|
||||
#include "Math/RGB565.hpp"
|
||||
#include "Math/RGBA5551.hpp"
|
||||
#include "Math/Timestamp.hpp"
|
||||
#include "Math/UInt24.hpp"
|
||||
#include "Base/UUID.hpp"
|
||||
#include <filesystem>
|
||||
#include <fmt/chrono.h>
|
||||
@@ -49,132 +57,170 @@ template<> struct fmt::formatter<std::filesystem::path> : fmt::formatter<std::st
|
||||
};
|
||||
|
||||
template<typename T, glm::qualifier Q>
|
||||
struct fmt::formatter<glm::vec<2, T, Q>>
|
||||
struct fmt::formatter<glm::vec<2, T, Q>> : fmt::formatter<T>
|
||||
{
|
||||
template<typename ParseContext> constexpr auto parse(ParseContext& ctx)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template<typename FormatContext>
|
||||
auto format(const glm::vec<2, T, Q>& v, FormatContext& ctx) const
|
||||
{
|
||||
return fmt::format_to(ctx.out(), "({}, {})", v.x, v.y);
|
||||
}
|
||||
template<typename FormatContext>
|
||||
auto format(const glm::vec<2, T, Q>& v, FormatContext& ctx) const
|
||||
{
|
||||
fmt::format_to(ctx.out(), "(");
|
||||
formatter<T>::format(v.x, ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(v.y, ctx);
|
||||
return fmt::format_to(ctx.out(), ")");
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, glm::qualifier Q>
|
||||
struct fmt::formatter<glm::vec<3, T, Q>>
|
||||
struct fmt::formatter<glm::vec<3, T, Q>> : fmt::formatter<T>
|
||||
{
|
||||
template<typename ParseContext> constexpr auto parse(ParseContext& ctx)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template<typename FormatContext>
|
||||
auto format(const glm::vec<3, T, Q>& v, FormatContext& ctx) const
|
||||
{
|
||||
return fmt::format_to(ctx.out(), "({}, {}, {})", v.x, v.y, v.z);
|
||||
}
|
||||
template<typename FormatContext>
|
||||
auto format(const glm::vec<3, T, Q>& v, FormatContext& ctx) const
|
||||
{
|
||||
fmt::format_to(ctx.out(), "(");
|
||||
formatter<T>::format(v.x, ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(v.y, ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(v.z, ctx);
|
||||
return fmt::format_to(ctx.out(), ")");
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, glm::qualifier Q>
|
||||
struct fmt::formatter<glm::vec<4, T, Q>>
|
||||
struct fmt::formatter<glm::vec<4, T, Q>> : fmt::formatter<T>
|
||||
{
|
||||
template<typename ParseContext> constexpr auto parse(ParseContext& ctx)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template<typename FormatContext>
|
||||
auto format(const glm::vec<4, T, Q>& v, FormatContext& ctx) const
|
||||
{
|
||||
return fmt::format_to(ctx.out(), "({}, {}, {}, {})", v.x, v.y, v.z, v.w);
|
||||
}
|
||||
template<typename FormatContext>
|
||||
auto format(const glm::vec<4, T, Q>& v, FormatContext& ctx) const
|
||||
{
|
||||
fmt::format_to(ctx.out(), "(");
|
||||
formatter<T>::format(v.x, ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(v.y, ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(v.z, ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(v.w, ctx);
|
||||
return fmt::format_to(ctx.out(), ")");
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, glm::qualifier Q>
|
||||
struct fmt::formatter<glm::mat<2, 2, T, Q>>
|
||||
struct fmt::formatter<glm::mat<2, 2, T, Q>> : fmt::formatter<T>
|
||||
{
|
||||
template<typename ParseContext> constexpr auto parse(ParseContext& ctx)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template<typename FormatContext>
|
||||
auto format(const glm::mat<2, 2, T, Q>& m, FormatContext& ctx) const
|
||||
{
|
||||
return fmt::format_to(ctx.out(), "[[{}, {}], [{}, {}]]",
|
||||
m[0][0], m[1][0],
|
||||
m[0][1], m[1][1]);
|
||||
}
|
||||
template<typename FormatContext>
|
||||
auto format(const glm::mat<2, 2, T, Q>& m, FormatContext& ctx) const
|
||||
{
|
||||
fmt::format_to(ctx.out(), "[[");
|
||||
formatter<T>::format(m[0][0], ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(m[1][0], ctx);
|
||||
fmt::format_to(ctx.out(), "], [");
|
||||
formatter<T>::format(m[0][1], ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(m[1][1], ctx);
|
||||
return fmt::format_to(ctx.out(), "]]");
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, glm::qualifier Q>
|
||||
struct fmt::formatter<glm::mat<3, 3, T, Q>>
|
||||
struct fmt::formatter<glm::mat<3, 3, T, Q>> : fmt::formatter<T>
|
||||
{
|
||||
template<typename ParseContext> constexpr auto parse(ParseContext& ctx)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template<typename FormatContext>
|
||||
auto format(const glm::mat<3, 3, T, Q>& m, FormatContext& ctx) const
|
||||
{
|
||||
return fmt::format_to(ctx.out(), "[[{}, {}, {}], [{}, {}, {}], [{}, {}, {}]]",
|
||||
m[0][0], m[1][0], m[2][0],
|
||||
m[0][1], m[1][1], m[2][1],
|
||||
m[0][2], m[1][2], m[2][2]);
|
||||
}
|
||||
template<typename FormatContext>
|
||||
auto format(const glm::mat<3, 3, T, Q>& m, FormatContext& ctx) const
|
||||
{
|
||||
fmt::format_to(ctx.out(), "[[");
|
||||
formatter<T>::format(m[0][0], ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(m[1][0], ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(m[2][0], ctx);
|
||||
fmt::format_to(ctx.out(), "], [");
|
||||
formatter<T>::format(m[0][1], ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(m[1][1], ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(m[2][1], ctx);
|
||||
fmt::format_to(ctx.out(), "], [");
|
||||
formatter<T>::format(m[0][2], ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(m[1][2], ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(m[2][2], ctx);
|
||||
return fmt::format_to(ctx.out(), "]]");
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, glm::qualifier Q>
|
||||
struct fmt::formatter<glm::mat<4, 4, T, Q>>
|
||||
struct fmt::formatter<glm::mat<4, 4, T, Q>> : fmt::formatter<T>
|
||||
{
|
||||
template<typename ParseContext> constexpr auto parse(ParseContext& ctx)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template<typename FormatContext>
|
||||
auto format(const glm::mat<4, 4, T, Q>& m, FormatContext& ctx) const
|
||||
{
|
||||
return fmt::format_to(ctx.out(), "[[{}, {}, {}, {}], [{}, {}, {}, {}], [{}, {}, {}, {}], [{}, {}, {}, {}]]",
|
||||
m[0][0], m[1][0], m[2][0], m[3][0],
|
||||
m[0][1], m[1][1], m[2][1], m[3][1],
|
||||
m[0][2], m[1][2], m[2][2], m[3][2],
|
||||
m[0][3], m[1][3], m[2][3], m[3][3]);
|
||||
}
|
||||
template<typename FormatContext>
|
||||
auto format(const glm::mat<4, 4, T, Q>& m, FormatContext& ctx) const
|
||||
{
|
||||
fmt::format_to(ctx.out(), "[[");
|
||||
formatter<T>::format(m[0][0], ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(m[1][0], ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(m[2][0], ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(m[3][0], ctx);
|
||||
fmt::format_to(ctx.out(), "], [");
|
||||
formatter<T>::format(m[0][1], ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(m[1][1], ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(m[2][1], ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(m[3][1], ctx);
|
||||
fmt::format_to(ctx.out(), "], [");
|
||||
formatter<T>::format(m[0][2], ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(m[1][2], ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(m[2][2], ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(m[3][2], ctx);
|
||||
fmt::format_to(ctx.out(), "], [");
|
||||
formatter<T>::format(m[0][3], ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(m[1][3], ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(m[2][3], ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(m[3][3], ctx);
|
||||
return fmt::format_to(ctx.out(), "]]");
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, glm::qualifier Q>
|
||||
struct fmt::formatter<glm::qua<T, Q>>
|
||||
struct fmt::formatter<glm::qua<T, Q>> : fmt::formatter<T>
|
||||
{
|
||||
template<typename ParseContext> constexpr auto parse(ParseContext& ctx)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template<typename FormatContext>
|
||||
auto format(const glm::qua<T, Q>& q, FormatContext& ctx) const
|
||||
{
|
||||
return fmt::format_to(ctx.out(), "({}, {}, {}, {})", q.w, q.x, q.y, q.z);
|
||||
}
|
||||
template<typename FormatContext>
|
||||
auto format(const glm::qua<T, Q>& q, FormatContext& ctx) const
|
||||
{
|
||||
fmt::format_to(ctx.out(), "(");
|
||||
formatter<T>::format(q.w, ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(q.x, ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(q.y, ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(q.z, ctx);
|
||||
return fmt::format_to(ctx.out(), ")");
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct fmt::formatter<OpenVulkano::Math::Range<T>> : fmt::formatter<std::string>
|
||||
struct fmt::formatter<OpenVulkano::Math::Range<T>> : fmt::formatter<T>
|
||||
{
|
||||
template<typename ParseContext>
|
||||
constexpr auto parse(ParseContext& ctx)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template<typename FormatContext>
|
||||
auto format(const OpenVulkano::Math::Range<T>& range, FormatContext& ctx) const
|
||||
{
|
||||
return fmt::format_to(ctx.out(), "[{}, {}]", range.min, range.max);
|
||||
fmt::format_to(ctx.out(), "[");
|
||||
formatter<T>::format(range.min, ctx);
|
||||
fmt::format_to(ctx.out(), ", ");
|
||||
formatter<T>::format(range.max, ctx);
|
||||
return fmt::format_to(ctx.out(), "]");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -193,3 +239,117 @@ struct fmt::formatter<OpenVulkano::UUID> : fmt::formatter<std::string>
|
||||
return fmt::format_to(ctx.out(), "{}", uuid.string());
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct fmt::formatter<OpenVulkano::Math::RGB565>
|
||||
{
|
||||
template<typename ParseContext>
|
||||
constexpr auto parse(ParseContext& ctx)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template<typename FormatContext>
|
||||
auto format(const OpenVulkano::Math::RGB565& color, FormatContext& ctx) const
|
||||
{
|
||||
return fmt::format_to(ctx.out(), "RGB565(r:{}, g:{}, b:{})",
|
||||
color.r, color.g, color.b);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct fmt::formatter<OpenVulkano::Math::RGBA5551>
|
||||
{
|
||||
template<typename ParseContext>
|
||||
constexpr auto parse(ParseContext& ctx)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template<typename FormatContext>
|
||||
auto format(const OpenVulkano::Math::RGBA5551& color, FormatContext& ctx) const
|
||||
{
|
||||
return fmt::format_to(ctx.out(), "RGBA5551(r:{}, g:{}, b:{}, a:{})",
|
||||
color.r, color.g, color.b, color.a);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename TYPE>
|
||||
struct fmt::formatter<OpenVulkano::Math::RGB10A2<TYPE>>
|
||||
{
|
||||
template<typename ParseContext>
|
||||
constexpr auto parse(ParseContext& ctx)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template<typename FormatContext>
|
||||
auto format(const OpenVulkano::Math::RGB10A2<TYPE>& color, FormatContext& ctx) const
|
||||
{
|
||||
return fmt::format_to(ctx.out(), "RGB10A2(r:{}, g:{}, b:{}, a:{})",
|
||||
color.r, color.g, color.b, color.a);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, bool REDUCE_Y_RESOLUTION, bool ASSERT_INPUT_VALUES, int BITS_PER_COMPONENT>
|
||||
struct fmt::formatter<OpenVulkano::Math::DenseVector3i<T, REDUCE_Y_RESOLUTION, ASSERT_INPUT_VALUES, BITS_PER_COMPONENT>>
|
||||
{
|
||||
template<typename ParseContext>
|
||||
constexpr auto parse(ParseContext& ctx)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template<typename FormatContext>
|
||||
auto format(const OpenVulkano::Math::DenseVector3i<T, REDUCE_Y_RESOLUTION, ASSERT_INPUT_VALUES, BITS_PER_COMPONENT>& vec,
|
||||
FormatContext& ctx) const
|
||||
{
|
||||
return fmt::format_to(ctx.out(), "DenseVector3i({}, {}, {})", vec.X(), vec.Y(), vec.Z());
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct fmt::formatter<OpenVulkano::Math::Timestamp>
|
||||
{
|
||||
template<typename ParseContext>
|
||||
constexpr auto parse(ParseContext& ctx)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template<typename FormatContext>
|
||||
auto format(const OpenVulkano::Math::Timestamp& ts, FormatContext& ctx) const
|
||||
{
|
||||
return fmt::format_to(ctx.out(), "{}ns", ts.GetNanos());
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct fmt::formatter<float16> : fmt::formatter<float>
|
||||
{
|
||||
template<typename FormatContext>
|
||||
auto format(const float16& f, FormatContext& ctx) const
|
||||
{
|
||||
return fmt::formatter<float>::format(static_cast<float>(f), ctx);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct fmt::formatter<OpenVulkano::int24> : fmt::formatter<int32_t>
|
||||
{
|
||||
template<typename FormatContext>
|
||||
auto format(const OpenVulkano::int24& i, FormatContext& ctx) const
|
||||
{
|
||||
return fmt::formatter<int32_t>::format(static_cast<int32_t>(i), ctx);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct fmt::formatter<OpenVulkano::uint24> : fmt::formatter<int32_t>
|
||||
{
|
||||
template<typename FormatContext>
|
||||
auto format(const OpenVulkano::uint24& i, FormatContext& ctx) const
|
||||
{
|
||||
return fmt::formatter<int32_t>::format(static_cast<int>(i), ctx);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user