From 4727ed20846bb3d1a9eabb27aaaa9c5524129556 Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Mon, 24 Sep 2018 21:33:39 +0100 Subject: Add a formatting function for Vector3 (#4282) * Vector3: Add custom fmt compatible formatter. * cLuaState: Add fmt version of ApiParamError * Use vector formatting in manual bindings * Always log vectors with FLOG --- src/Vector3.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/Vector3.h') diff --git a/src/Vector3.h b/src/Vector3.h index cb39a6cde..0456b9e2f 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -350,6 +350,22 @@ public: z = -z; } + // tolua_end + + /** Allows formatting a Vector 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 + friend void format_arg(fmt::BasicFormatter & a_Formatter, const char *& a_FormatStr, Vector3 a_Vec) + { + std::array 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; -- cgit v1.2.3