summaryrefslogtreecommitdiffstats
path: root/src/Vector3.h
diff options
context:
space:
mode:
authorpeterbell10 <peterbell10@live.co.uk>2020-05-05 23:52:14 +0200
committerGitHub <noreply@github.com>2020-05-05 23:52:14 +0200
commit57952505e522be868a5a8270d8670163b55ebade (patch)
treecf3c5544612b8a51075b498fa14dba8fe758d656 /src/Vector3.h
parentRequire semi-colon at end of function-like macros (#4719) (diff)
downloadcuberite-57952505e522be868a5a8270d8670163b55ebade.tar
cuberite-57952505e522be868a5a8270d8670163b55ebade.tar.gz
cuberite-57952505e522be868a5a8270d8670163b55ebade.tar.bz2
cuberite-57952505e522be868a5a8270d8670163b55ebade.tar.lz
cuberite-57952505e522be868a5a8270d8670163b55ebade.tar.xz
cuberite-57952505e522be868a5a8270d8670163b55ebade.tar.zst
cuberite-57952505e522be868a5a8270d8670163b55ebade.zip
Diffstat (limited to '')
-rw-r--r--src/Vector3.h61
1 files changed, 45 insertions, 16 deletions
diff --git a/src/Vector3.h b/src/Vector3.h
index b3d54514b..4445c6336 100644
--- a/src/Vector3.h
+++ b/src/Vector3.h
@@ -384,22 +384,6 @@ public:
z = -z;
}
- // tolua_end
-
- /** Allows formatting a Vector<T> using the same format specifiers as for T
- e.g. `fmt::format("{0:0.2f}", Vector3f{0.0231f, 1.2146f, 1.0f}) == "{0.02, 1.21, 1.00}"` */
- template <typename ArgFormatter>
- friend void format_arg(fmt::BasicFormatter<char, ArgFormatter> & a_Formatter, const char *& a_FormatStr, Vector3 a_Vec)
- {
- std::array<T, 3> Data{{a_Vec.x, a_Vec.y, a_Vec.z}};
-
- a_Formatter.writer() << '{';
- fmt::format_arg(a_Formatter, a_FormatStr, fmt::join(Data.cbegin(), Data.cend(), ", "));
- a_Formatter.writer() << '}';
- }
-
- // tolua_begin
-
/** The max difference between two coords for which the coords are assumed equal. */
static const double EPS;
@@ -411,6 +395,51 @@ public:
+namespace fmt
+{
+
+template <typename What>
+class formatter<Vector3<What>>:
+ public fmt::formatter<What>
+{
+ using Super = fmt::formatter<What>;
+
+ template <typename FormatContext, size_t Len>
+ void Write(FormatContext & a_Ctx, const char (& a_Str)[Len])
+ {
+ auto Itr = std::copy_n(&a_Str[0], Len - 1, a_Ctx.out());
+ a_Ctx.advance_to(Itr);
+ }
+
+ template <typename FormatContext>
+ void Write(FormatContext & a_Ctx, const What & a_Arg)
+ {
+ auto Itr = Super::format(a_Arg, a_Ctx);
+ a_Ctx.advance_to(Itr);
+ }
+
+public:
+
+ template <typename FormatContext>
+ auto format(const Vector3<What> & a_Vec, FormatContext & a_Ctx)
+ -> typename FormatContext::iterator
+ {
+ Write(a_Ctx, "{");
+ Write(a_Ctx, a_Vec.x);
+ Write(a_Ctx, ", ");
+ Write(a_Ctx, a_Vec.y);
+ Write(a_Ctx, ", ");
+ Write(a_Ctx, a_Vec.z);
+ Write(a_Ctx, "}");
+ return a_Ctx.out();
+ }
+};
+
+}
+
+
+
+
template <> inline Vector3<int> Vector3<int>::Floor(void) const
{