MeshLib C++ Docs
Loading...
Searching...
No Matches
MRFormat.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4#include "MRPch/MRFmt.h"
5
6template <typename T>
7struct fmt::formatter<MR::Vector2<T>> : fmt::formatter<T>
8{
9 template <typename Context>
10 constexpr auto format( const MR::Vector2<T>& v, Context& ctx ) const
11 {
12 using Base = fmt::formatter<T>;
13 auto out = ctx.out();
14 out = Base::format( v.x, ctx );
15 *out++ = ',';
16 *out++ = ' ';
17 out = Base::format( v.y, ctx );
18 return out;
19 }
20};
21
22template <typename T>
23struct fmt::formatter<MR::Vector3<T>> : fmt::formatter<T>
24{
25 template <typename Context>
26 constexpr auto format( const MR::Vector3<T>& v, Context& ctx ) const
27 {
28 using Base = fmt::formatter<T>;
29 auto out = ctx.out();
30 out = Base::format( v.x, ctx );
31 *out++ = ',';
32 *out++ = ' ';
33 out = Base::format( v.y, ctx );
34 *out++ = ',';
35 *out++ = ' ';
36 out = Base::format( v.z, ctx );
37 return out;
38 }
39};
40
41template <typename T>
42struct fmt::formatter<MR::Vector4<T>> : fmt::formatter<T>
43{
44 template <typename Context>
45 constexpr auto format( const MR::Vector4<T>& v, Context& ctx ) const
46 {
47 using Base = fmt::formatter<T>;
48 auto out = ctx.out();
49 out = Base::format( v.x, ctx );
50 *out++ = ',';
51 *out++ = ' ';
52 out = Base::format( v.y, ctx );
53 *out++ = ',';
54 *out++ = ' ';
55 out = Base::format( v.z, ctx );
56 *out++ = ',';
57 *out++ = ' ';
58 out = Base::format( v.w, ctx );
59 return out;
60 }
61};
62
63template <typename T>
64struct fmt::formatter<MR::Matrix3<T>> : fmt::formatter<MR::Vector3<T>>
65{
66 template <typename Context>
67 static constexpr auto formatWith( const MR::Matrix3<T>& mat, Context& ctx, const fmt::formatter<MR::Vector3<T>>& v )
68 {
69 auto out = ctx.out();
70 *out++ = '{';
71 out = v.format( mat.x, ctx );
72 *out++ = '}';
73 *out++ = ',';
74 *out++ = ' ';
75 *out++ = '{';
76 out = v.format( mat.y, ctx );
77 *out++ = '}';
78 *out++ = ',';
79 *out++ = ' ';
80 *out++ = '{';
81 out = v.format( mat.z, ctx );
82 *out++ = '}';
83 return out;
84 }
85
86 template <typename Context>
87 constexpr auto format( const MR::Matrix3<T>& mat, Context& ctx ) const
88 {
89 return formatWith( mat, ctx, *this );
90 }
91};
92
93template <typename T>
94struct fmt::formatter<MR::Matrix4<T>> : fmt::formatter<MR::Vector4<T>>
95{
96 template <typename Context>
97 constexpr auto format( const MR::Matrix4<T>& mat, Context& ctx ) const
98 {
99 using Vec = fmt::formatter<MR::Vector4<T>>;
100 auto out = ctx.out();
101 *out++ = '{';
102 out = Vec::format( mat.x, ctx );
103 *out++ = '}';
104 *out++ = ',';
105 *out++ = ' ';
106 *out++ = '{';
107 out = Vec::format( mat.y, ctx );
108 *out++ = '}';
109 *out++ = ',';
110 *out++ = ' ';
111 *out++ = '{';
112 out = Vec::format( mat.z, ctx );
113 *out++ = '}';
114 *out++ = ',';
115 *out++ = ' ';
116 *out++ = '{';
117 out = Vec::format( mat.w, ctx );
118 *out++ = '}';
119 return out;
120 }
121};
122
123template <typename T>
124struct fmt::formatter<MR::AffineXf3<T>> : fmt::formatter<MR::Vector3<T>>
125{
126 template <typename Context>
127 constexpr auto format( const MR::AffineXf3<T>& xf, Context& ctx ) const
128 {
129 using Mat = fmt::formatter<MR::Matrix3<T>>;
130 using Vec = fmt::formatter<MR::Vector3<T>>;
131 auto out = ctx.out();
132 *out++ = '{';
133 out = Mat::formatWith( xf.A, ctx, *this );
134 *out++ = '}';
135 *out++ = ',';
136 *out++ = ' ';
137 *out++ = '{';
138 out = Vec::format( xf.b, ctx );
139 *out++ = '}';
140 return out;
141 }
142};
143
144template <typename V>
145struct fmt::formatter<MR::Box<V>> : fmt::formatter<V>
146{
147 template <typename Context>
148 constexpr auto format( const MR::Box<V>& box, Context& ctx ) const
149 {
150 using Vec = fmt::formatter<V>;
151 auto out = ctx.out();
152 *out++ = '{';
153 out = Vec::format( box.min, ctx );
154 *out++ = '}';
155 *out++ = ',';
156 *out++ = ' ';
157 *out++ = '{';
158 out = Vec::format( box.max, ctx );
159 *out++ = '}';
160 return out;
161 }
162};
163
164template <>
165struct fmt::formatter<MR::BitSet> : fmt::formatter<std::string>
166{
167 template <typename Context>
168 constexpr auto format( const MR::BitSet& bs, Context& ctx ) const
169 {
170 using Base = fmt::formatter<std::string>;
171 return Base::format( toString( bs ), ctx );
172 }
173
174private:
175 MRMESH_API static std::string toString( const MR::BitSet& bs );
176};
#define MRMESH_API
Definition MRMeshFwd.h:80
Definition MRMesh/MRBitSet.h:24
Definition MRCameraOrientationPlugin.h:8
Box given by its min- and max- corners.
Definition MRMesh/MRBox.h:27
V max
Definition MRMesh/MRBox.h:35
V min
Definition MRMesh/MRBox.h:35
Definition MRMesh/MRMatrix3.h:21
Vector3< T > x
rows, identity matrix by default
Definition MRMesh/MRMatrix3.h:26
Vector3< T > y
Definition MRMesh/MRMatrix3.h:27
Vector3< T > z
Definition MRMesh/MRMatrix3.h:28
Definition MRMatrix4.h:22
Vector4< T > z
Definition MRMatrix4.h:29
Vector4< T > y
Definition MRMatrix4.h:28
Vector4< T > w
Definition MRMatrix4.h:30
Vector4< T > x
rows, identity matrix by default
Definition MRMatrix4.h:27
Definition MRVector2.h:29
T x
Definition MRVector2.h:35
T y
Definition MRVector2.h:35
Definition MRMesh/MRVector3.h:30
T x
Definition MRMesh/MRVector3.h:36
T y
Definition MRMesh/MRVector3.h:36
T z
Definition MRMesh/MRVector3.h:36
Definition MRVector4.h:23
T y
Definition MRVector4.h:29
T z
Definition MRVector4.h:29
T x
Definition MRVector4.h:29
T w
Definition MRVector4.h:29
constexpr auto format(const MR::AffineXf3< T > &xf, Context &ctx) const
Definition MRFormat.h:127
constexpr auto format(const MR::BitSet &bs, Context &ctx) const
Definition MRFormat.h:168
constexpr auto format(const MR::Box< V > &box, Context &ctx) const
Definition MRFormat.h:148
constexpr auto format(const MR::Matrix3< T > &mat, Context &ctx) const
Definition MRFormat.h:87
static constexpr auto formatWith(const MR::Matrix3< T > &mat, Context &ctx, const fmt::formatter< MR::Vector3< T > > &v)
Definition MRFormat.h:67
constexpr auto format(const MR::Matrix4< T > &mat, Context &ctx) const
Definition MRFormat.h:97
constexpr auto format(const MR::Vector2< T > &v, Context &ctx) const
Definition MRFormat.h:10
constexpr auto format(const MR::Vector3< T > &v, Context &ctx) const
Definition MRFormat.h:26
constexpr auto format(const MR::Vector4< T > &v, Context &ctx) const
Definition MRFormat.h:45