Fixed GTX_string_cast to support for integer types #249

master
Christophe Riccio ago%!(EXTRA string=11 years)
parent ca4ed31fb6
commit 75939a7960
  1. 11
      glm/gtx/string_cast.hpp
  2. 698
      glm/gtx/string_cast.inl
  3. 1
      readme.txt
  4. 135
      test/gtx/gtx_string_cast.cpp

@ -22,7 +22,7 @@
/// ///
/// @ref gtx_string_cast /// @ref gtx_string_cast
/// @file glm/gtx/string_cast.hpp /// @file glm/gtx/string_cast.hpp
/// @date 2008-04-26 / 2011-06-07 /// @date 2008-04-26 / 2014-05-10
/// @author Christophe Riccio /// @author Christophe Riccio
/// ///
/// @see core (dependence) /// @see core (dependence)
@ -43,8 +43,7 @@
// Dependency: // Dependency:
#include "../glm.hpp" #include "../glm.hpp"
#include "../gtx/integer.hpp" #include "../gtc/type_precision.hpp"
#include "../gtx/quaternion.hpp"
#include <string> #include <string>
#if(GLM_COMPILER & GLM_COMPILER_CUDA) #if(GLM_COMPILER & GLM_COMPILER_CUDA)
@ -60,10 +59,10 @@ namespace glm
/// @addtogroup gtx_string_cast /// @addtogroup gtx_string_cast
/// @{ /// @{
/// Create a string from a GLM type value. /// Create a string from a GLM vector or matrix typed variable.
/// @see gtx_string_cast extension. /// @see gtx_string_cast extension.
template <typename genType> template <template <typename, precision> class matType, typename T, precision P>
GLM_FUNC_DECL std::string to_string(genType const & x); GLM_FUNC_DECL std::string to_string(matType<T, P> const & x);
/// @} /// @}
}//namespace glm }//namespace glm

@ -2,7 +2,7 @@
// OpenGL Mathematics Copyright (c) 2006 G-Truc Creation (www.g-truc.net) // OpenGL Mathematics Copyright (c) 2006 G-Truc Creation (www.g-truc.net)
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2008-04-27 // Created : 2008-04-27
// Updated : 2008-05-24 // Updated : 2014-05-10
// Licence : This source is under MIT License // Licence : This source is under MIT License
// File : glm/gtx/string_cast.hpp // File : glm/gtx/string_cast.hpp
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
@ -35,410 +35,372 @@ namespace detail
static const char* True = "true"; static const char* True = "true";
static const char* False = "false"; static const char* False = "false";
}//namespace detail
//////////////////////////////// template <typename T>
// Scalars struct prefix{};
GLM_FUNC_QUALIFIER std::string to_string(float x) template <>
struct prefix<float>
{ {
return detail::format("float(%f)", x); static char const * value() {return "";};
} };
GLM_FUNC_QUALIFIER std::string to_string(double x) template <>
struct prefix<double>
{ {
return detail::format("double(%f)", x); static char const * value() {return "d";};
} };
GLM_FUNC_QUALIFIER std::string to_string(int x) template <>
struct prefix<bool>
{ {
return detail::format("int(%d)", x); static char const * value() {return "b";};
} };
GLM_FUNC_QUALIFIER std::string to_string(unsigned int x) template <>
struct prefix<uint8_t>
{ {
return detail::format("uint(%d)", x); static char const * value() {return "u8";};
} };
////////////////////////////////
// Bool vectors
template <precision P> template <>
GLM_FUNC_QUALIFIER std::string to_string struct prefix<int8_t>
(
tvec2<bool, P> const & v
)
{ {
return detail::format("bvec2(%s, %s)", static char const * value() {return "i8";};
v.x ? detail::True : detail::False, };
v.y ? detail::True : detail::False);
}
template <precision P> template <>
GLM_FUNC_QUALIFIER std::string to_string struct prefix<uint16_t>
(
tvec3<bool, P> const & v
)
{ {
return detail::format("bvec3(%s, %s, %s)", static char const * value() {return "u16";};
v.x ? detail::True : detail::False, };
v.y ? detail::True : detail::False,
v.z ? detail::True : detail::False);
}
template <precision P> template <>
GLM_FUNC_QUALIFIER std::string to_string struct prefix<int16_t>
(
tvec4<bool, P> const & v
)
{ {
return detail::format("bvec4(%s, %s, %s, %s)", static char const * value() {return "i16";};
v.x ? detail::True : detail::False, };
v.y ? detail::True : detail::False,
v.z ? detail::True : detail::False,
v.w ? detail::True : detail::False);
}
//////////////////////////////// template <>
// Float vectors struct prefix<uint32_t>
template <precision P>
GLM_FUNC_QUALIFIER std::string to_string
(
tvec2<float, P> const & v
)
{ {
return detail::format("fvec2(%f, %f)", v.x, v.y); static char const * value() {return "u";};
} };
template <precision P> template <>
GLM_FUNC_QUALIFIER std::string to_string struct prefix<int32_t>
(
tvec3<float, P> const & v
)
{ {
return detail::format("fvec3(%f, %f, %f)", v.x, v.y, v.z); static char const * value() {return "i";};
} };
template <precision P> template <>
GLM_FUNC_QUALIFIER std::string to_string struct prefix<uint64_t>
(
tvec4<float, P> const & v
)
{ {
return detail::format("fvec4(%f, %f, %f, %f)", v.x, v.y, v.z, v.w); static char const * value() {return "u64";};
} };
//////////////////////////////// template <>
// Double vectors struct prefix<int64_t>
template <precision P>
GLM_FUNC_QUALIFIER std::string to_string
(
tvec2<double, P> const & v
)
{ {
return detail::format("dvec2(%f, %f)", v.x, v.y); static char const * value() {return "i64";};
} };
template <precision P> template <template <typename, precision> class matType, typename T, precision P>
GLM_FUNC_QUALIFIER std::string to_string struct compute_to_string
( {};
tvec3<double, P> const & v
)
{
return detail::format("dvec3(%f, %f, %f)", v.x, v.y, v.z);
}
template <precision P> template <precision P>
GLM_FUNC_QUALIFIER std::string to_string struct compute_to_string<tvec1, bool, P>
(
tvec4<double, P> const & v
)
{ {
return detail::format("dvec4(%f, %f, %f, %f)", v.x, v.y, v.z, v.w); GLM_FUNC_QUALIFIER static std::string call(tvec1<bool, P> const & x)
} {
return detail::format("bvec1(%s)",
//////////////////////////////// x[0] ? detail::True : detail::False);
// Int vectors }
};
template <precision P> template <precision P>
GLM_FUNC_QUALIFIER std::string to_string struct compute_to_string<tvec2, bool, P>
(
tvec2<int, P> const & v
)
{ {
return detail::format("ivec2(%d, %d)", v.x, v.y); GLM_FUNC_QUALIFIER static std::string call(tvec2<bool, P> const & x)
} {
return detail::format("bvec2(%s, %s)",
x[0] ? detail::True : detail::False,
x[1] ? detail::True : detail::False);
}
};
template <precision P> template <precision P>
GLM_FUNC_QUALIFIER std::string to_string struct compute_to_string<tvec3, bool, P>
(
tvec3<int, P> const & v
)
{ {
return detail::format("ivec3(%d, %d, %d)", v.x, v.y, v.z); GLM_FUNC_QUALIFIER static std::string call(tvec3<bool, P> const & x)
} {
return detail::format("bvec3(%s, %s, %s)",
x[0] ? detail::True : detail::False,
x[1] ? detail::True : detail::False,
x[2] ? detail::True : detail::False);
}
};
template <precision P> template <precision P>
GLM_FUNC_QUALIFIER std::string to_string struct compute_to_string<tvec4, bool, P>
(
tvec4<int, P> const & v
)
{ {
return detail::format("ivec4(%d, %d, %d, %d)", v.x, v.y, v.z, v.w); GLM_FUNC_QUALIFIER static std::string call(tvec4<bool, P> const & x)
} {
return detail::format("bvec4(%s, %s, %s, %s)",
x[0] ? detail::True : detail::False,
x[1] ? detail::True : detail::False,
x[2] ? detail::True : detail::False,
x[3] ? detail::True : detail::False);
}
};
//////////////////////////////// template <typename T, precision P>
// Unsigned int vectors struct compute_to_string<tvec1, T, P>
{
template <precision P> GLM_FUNC_QUALIFIER static std::string call(tvec1<T, P> const & x)
GLM_FUNC_QUALIFIER std::string to_string {
( char const * PrefixStr = prefix<T>::value();
tvec2<unsigned int, P> const & v char const * LiteralStr = std::numeric_limits<T>::is_iec559 ? "%f" : "%d";
) std::string FormatStr(detail::format("%svec1(%s)",
{ PrefixStr,
return detail::format("uvec2(%d, %d)", v.x, v.y); LiteralStr));
}
return detail::format(FormatStr.c_str(), x[0]);
template <precision P> }
GLM_FUNC_QUALIFIER std::string to_string };
(
tvec3<unsigned int, P> const & v template <typename T, precision P>
) struct compute_to_string<tvec2, T, P>
{ {
return detail::format("uvec3(%d, %d, %d)", v.x, v.y, v.z); GLM_FUNC_QUALIFIER static std::string call(tvec2<T, P> const & x)
} {
char const * PrefixStr = prefix<T>::value();
template <precision P> char const * LiteralStr = std::numeric_limits<T>::is_iec559 ? "%f" : "%d";
GLM_FUNC_QUALIFIER std::string to_string std::string FormatStr(detail::format("%svec2(%s, %s)",
( PrefixStr,
tvec4<unsigned int, P> const & v LiteralStr, LiteralStr));
)
{ return detail::format(FormatStr.c_str(), x[0], x[1]);
return detail::format("uvec4(%d, %d, %d, %d)", v.x, v.y, v.z, v.w); }
} };
//////////////////////////////// template <typename T, precision P>
// Float matrices struct compute_to_string<tvec3, T, P>
{
template <precision P> GLM_FUNC_QUALIFIER static std::string call(tvec3<T, P> const & x)
GLM_FUNC_QUALIFIER std::string to_string {
( char const * PrefixStr = prefix<T>::value();
tmat2x2<float, P> const & x char const * LiteralStr = std::numeric_limits<T>::is_iec559 ? "%f" : "%d";
) std::string FormatStr(detail::format("%svec3(%s, %s, %s)",
{ PrefixStr,
return detail::format("mat2x2((%f, %f), (%f, %f))", LiteralStr, LiteralStr, LiteralStr));
x[0][0], x[0][1],
x[1][0], x[1][1]); return detail::format(FormatStr.c_str(), x[0], x[1], x[2]);
} }
};
template <precision P>
GLM_FUNC_QUALIFIER std::string to_string template <typename T, precision P>
( struct compute_to_string<tvec4, T, P>
tmat2x3<float, P> const & x {
) GLM_FUNC_QUALIFIER static std::string call(tvec4<T, P> const & x)
{ {
return detail::format("mat2x3((%f, %f, %f), (%f, %f, %f))", char const * PrefixStr = prefix<T>::value();
x[0][0], x[0][1], x[0][2], char const * LiteralStr = std::numeric_limits<T>::is_iec559 ? "%f" : "%d";
x[1][0], x[1][1], x[1][2]); std::string FormatStr(detail::format("%svec4(%s, %s, %s, %s)",
} PrefixStr,
LiteralStr, LiteralStr, LiteralStr, LiteralStr));
template <precision P>
GLM_FUNC_QUALIFIER std::string to_string return detail::format(FormatStr.c_str(), x[0], x[1], x[2], x[3]);
( }
tmat2x4<float, P> const & x };
)
{
return detail::format("mat2x4((%f, %f, %f, %f), (%f, %f, %f, %f))", template <typename T, precision P>
x[0][0], x[0][1], x[0][2], x[0][3], struct compute_to_string<tmat2x2, T, P>
x[1][0], x[1][1], x[1][2], x[1][3]); {
} GLM_FUNC_QUALIFIER static std::string call(tmat2x2<T, P> const & x)
{
template <precision P> char const * PrefixStr = prefix<T>::value();
GLM_FUNC_QUALIFIER std::string to_string char const * LiteralStr = std::numeric_limits<T>::is_iec559 ? "%f" : "%d";
( std::string FormatStr(detail::format("%smat2x2((%s, %s), (%s, %s))",
tmat3x2<float, P> const & x PrefixStr,
) LiteralStr, LiteralStr,
{ LiteralStr, LiteralStr));
return detail::format("mat3x2((%f, %f), (%f, %f), (%f, %f))",
x[0][0], x[0][1], return detail::format(FormatStr.c_str(),
x[1][0], x[1][1], x[0][0], x[0][1],
x[2][0], x[2][1]); x[1][0], x[1][1]);
} }
};
template <precision P>
GLM_FUNC_QUALIFIER std::string to_string template <typename T, precision P>
( struct compute_to_string<tmat2x3, T, P>
tmat3x3<float, P> const & x {
) GLM_FUNC_QUALIFIER static std::string call(tmat2x3<T, P> const & x)
{ {
return detail::format("mat3x3((%f, %f, %f), (%f, %f, %f), (%f, %f, %f))", char const * PrefixStr = prefix<T>::value();
x[0][0], x[0][1], x[0][2], char const * LiteralStr = std::numeric_limits<T>::is_iec559 ? "%f" : "%d";
x[1][0], x[1][1], x[1][2], std::string FormatStr(detail::format("%smat2x3((%s, %s, %s), (%s, %s, %s))",
x[2][0], x[2][1], x[2][2]); PrefixStr,
} LiteralStr, LiteralStr, LiteralStr,
LiteralStr, LiteralStr, LiteralStr));
template <precision P>
GLM_FUNC_QUALIFIER std::string to_string return detail::format(FormatStr.c_str(),
( x[0][0], x[0][1], x[0][2],
tmat3x4<float, P> const & x x[1][0], x[1][1], x[1][2]);
) }
{ };
return detail::format("mat3x4((%f, %f, %f, %f), (%f, %f, %f, %f), (%f, %f, %f, %f))",
x[0][0], x[0][1], x[0][2], x[0][3], template <typename T, precision P>
x[1][0], x[1][1], x[1][2], x[1][3], struct compute_to_string<tmat2x4, T, P>
x[2][0], x[2][1], x[2][2], x[2][3]); {
} GLM_FUNC_QUALIFIER static std::string call(tmat2x4<T, P> const & x)
{
template <precision P> char const * PrefixStr = prefix<T>::value();
GLM_FUNC_QUALIFIER std::string to_string char const * LiteralStr = std::numeric_limits<T>::is_iec559 ? "%f" : "%d";
( std::string FormatStr(detail::format("%smat2x4((%s, %s, %s, %s), (%s, %s, %s, %s))",
tmat4x2<float, P> const & x PrefixStr,
) LiteralStr, LiteralStr, LiteralStr, LiteralStr,
{ LiteralStr, LiteralStr, LiteralStr, LiteralStr));
return detail::format("mat4x2((%f, %f), (%f, %f), (%f, %f), (%f, %f))",
x[0][0], x[0][1], return detail::format(FormatStr.c_str(),
x[1][0], x[1][1], x[0][0], x[0][1], x[0][2], x[0][3],
x[2][0], x[2][1], x[1][0], x[1][1], x[1][2], x[1][3]);
x[3][0], x[3][1]); }
} };
template <precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER std::string to_string struct compute_to_string<tmat3x2, T, P>
( {
tmat4x3<float, P> const & x GLM_FUNC_QUALIFIER static std::string call(tmat3x2<T, P> const & x)
) {
{ char const * PrefixStr = prefix<T>::value();
return detail::format("mat4x3((%f, %f, %f), (%f, %f, %f), (%f, %f, %f), (%f, %f, %f))", char const * LiteralStr = std::numeric_limits<T>::is_iec559 ? "%f" : "%d";
x[0][0], x[0][1], x[0][2], std::string FormatStr(detail::format("%smat3x2((%s, %s), (%s, %s), (%s, %s))",
x[1][0], x[1][1], x[1][2], PrefixStr,
x[2][0], x[2][1], x[2][2], LiteralStr, LiteralStr,
x[3][0], x[3][1], x[3][2]); LiteralStr, LiteralStr,
} LiteralStr, LiteralStr));
template <precision P> return detail::format(FormatStr.c_str(),
GLM_FUNC_QUALIFIER std::string to_string x[0][0], x[0][1],
( x[1][0], x[1][1],
tmat4x4<float, P> const & x x[2][0], x[2][1]);
) }
{ };
return detail::format("mat4x4((%f, %f, %f, %f), (%f, %f, %f, %f), (%f, %f, %f, %f), (%f, %f, %f, %f))",
x[0][0], x[0][1], x[0][2], x[0][3], template <typename T, precision P>
x[1][0], x[1][1], x[1][2], x[1][3], struct compute_to_string<tmat3x3, T, P>
x[2][0], x[2][1], x[2][2], x[2][3], {
x[3][0], x[3][1], x[3][2], x[3][3]); GLM_FUNC_QUALIFIER static std::string call(tmat3x3<T, P> const & x)
} {
char const * PrefixStr = prefix<T>::value();
//////////////////////////////// char const * LiteralStr = std::numeric_limits<T>::is_iec559 ? "%f" : "%d";
// Double matrices std::string FormatStr(detail::format("%smat3x3((%s, %s, %s), (%s, %s, %s), (%s, %s, %s))",
PrefixStr,
template <precision P> LiteralStr, LiteralStr, LiteralStr,
GLM_FUNC_QUALIFIER std::string to_string LiteralStr, LiteralStr, LiteralStr,
( LiteralStr, LiteralStr, LiteralStr));
tmat2x2<double, P> const & x
) return detail::format(FormatStr.c_str(),
{ x[0][0], x[0][1], x[0][2],
return detail::format("dmat2x2((%f, %f), (%f, %f))", x[1][0], x[1][1], x[1][2],
x[0][0], x[0][1], x[2][0], x[2][1], x[2][2]);
x[1][0], x[1][1]); }
} };
template <precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER std::string to_string struct compute_to_string<tmat3x4, T, P>
( {
tmat2x3<double, P> const & x GLM_FUNC_QUALIFIER static std::string call(tmat3x4<T, P> const & x)
) {
{ char const * PrefixStr = prefix<T>::value();
return detail::format("dmat2x3((%f, %f, %f), (%f, %f, %f))", char const * LiteralStr = std::numeric_limits<T>::is_iec559 ? "%f" : "%d";
x[0][0], x[0][1], x[0][2], std::string FormatStr(detail::format("%smat3x4((%s, %s, %s, %s), (%s, %s, %s, %s), (%s, %s, %s, %s))",
x[1][0], x[1][1], x[1][2]); PrefixStr,
} LiteralStr, LiteralStr, LiteralStr, LiteralStr,
LiteralStr, LiteralStr, LiteralStr, LiteralStr,
template <precision P> LiteralStr, LiteralStr, LiteralStr, LiteralStr));
GLM_FUNC_QUALIFIER std::string to_string
( return detail::format(FormatStr.c_str(),
tmat2x4<double, P> const & x x[0][0], x[0][1], x[0][2], x[0][3],
) x[1][0], x[1][1], x[1][2], x[1][3],
{ x[2][0], x[2][1], x[2][2], x[2][3]);
return detail::format("dmat2x4((%f, %f, %f, %f), (%f, %f, %f, %f))", }
x[0][0], x[0][1], x[0][2], x[0][3], };
x[1][0], x[1][1], x[1][2], x[1][3]);
} template <typename T, precision P>
struct compute_to_string<tmat4x2, T, P>
template <precision P> {
GLM_FUNC_QUALIFIER std::string to_string GLM_FUNC_QUALIFIER static std::string call(tmat4x2<T, P> const & x)
( {
tmat3x2<double, P> const & x char const * PrefixStr = prefix<T>::value();
) char const * LiteralStr = std::numeric_limits<T>::is_iec559 ? "%f" : "%d";
{ std::string FormatStr(detail::format("%smat4x2((%s, %s), (%s, %s), (%s, %s), (%s, %s))",
return detail::format("dmat3x2((%f, %f), (%f, %f), (%f, %f))", PrefixStr,
x[0][0], x[0][1], LiteralStr, LiteralStr,
x[1][0], x[1][1], LiteralStr, LiteralStr,
x[2][0], x[2][1]); LiteralStr, LiteralStr,
} LiteralStr, LiteralStr));
template <precision P> return detail::format(FormatStr.c_str(),
GLM_FUNC_QUALIFIER std::string to_string x[0][0], x[0][1],
( x[1][0], x[1][1],
tmat3x3<double, P> const & x x[2][0], x[2][1],
) x[3][0], x[3][1]);
{ }
return detail::format("dmat3x3((%f, %f, %f), (%f, %f, %f), (%f, %f, %f))", };
x[0][0], x[0][1], x[0][2],
x[1][0], x[1][1], x[1][2], template <typename T, precision P>
x[2][0], x[2][1], x[2][2]); struct compute_to_string<tmat4x3, T, P>
} {
GLM_FUNC_QUALIFIER static std::string call(tmat4x3<T, P> const & x)
template <precision P> {
GLM_FUNC_QUALIFIER std::string to_string char const * PrefixStr = prefix<T>::value();
( char const * LiteralStr = std::numeric_limits<T>::is_iec559 ? "%f" : "%d";
tmat3x4<double, P> const & x std::string FormatStr(detail::format("%smat4x3((%s, %s, %s), (%s, %s, %s), (%s, %s, %s), (%s, %s, %s))",
) PrefixStr,
{ LiteralStr, LiteralStr, LiteralStr,
return detail::format("dmat3x4((%f, %f, %f, %f), (%f, %f, %f, %f), (%f, %f, %f, %f))", LiteralStr, LiteralStr, LiteralStr,
x[0][0], x[0][1], x[0][2], x[0][3], LiteralStr, LiteralStr, LiteralStr,
x[1][0], x[1][1], x[1][2], x[1][3], LiteralStr, LiteralStr, LiteralStr));
x[2][0], x[2][1], x[2][2], x[2][3]);
} return detail::format(FormatStr.c_str(),
x[0][0], x[0][1], x[0][2],
template <precision P> x[1][0], x[1][1], x[1][2],
GLM_FUNC_QUALIFIER std::string to_string x[2][0], x[2][1], x[2][2],
( x[3][0], x[3][1], x[3][2]);
tmat4x2<double, P> const & x }
) };
{
return detail::format("dmat4x2((%f, %f), (%f, %f), (%f, %f), (%f, %f))", template <typename T, precision P>
x[0][0], x[0][1], struct compute_to_string<tmat4x4, T, P>
x[1][0], x[1][1], {
x[2][0], x[2][1], GLM_FUNC_QUALIFIER static std::string call(tmat4x4<T, P> const & x)
x[3][0], x[3][1]); {
} char const * PrefixStr = prefix<T>::value();
char const * LiteralStr = std::numeric_limits<T>::is_iec559 ? "%f" : "%d";
template <precision P> std::string FormatStr(detail::format("%smat4x4((%s, %s, %s, %s), (%s, %s, %s, %s), (%s, %s, %s, %s), (%s, %s, %s, %s))",
GLM_FUNC_QUALIFIER std::string to_string PrefixStr,
( LiteralStr, LiteralStr, LiteralStr, LiteralStr,
tmat4x3<double, P> const & x LiteralStr, LiteralStr, LiteralStr, LiteralStr,
) LiteralStr, LiteralStr, LiteralStr, LiteralStr,
{ LiteralStr, LiteralStr, LiteralStr, LiteralStr));
return detail::format("dmat4x3((%f, %f, %f), (%f, %f, %f), (%f, %f, %f), (%f, %f, %f))",
x[0][0], x[0][1], x[0][2], return detail::format(FormatStr.c_str(),
x[1][0], x[1][1], x[1][2], x[0][0], x[0][1], x[0][2], x[0][3],
x[2][0], x[2][1], x[2][2], x[1][0], x[1][1], x[1][2], x[1][3],
x[3][0], x[3][1], x[3][2]); x[2][0], x[2][1], x[2][2], x[2][3],
} x[3][0], x[3][1], x[3][2], x[3][3]);
}
};
}//namespace detail
template <precision P> template <template <typename, precision> class matType, typename T, precision P>
GLM_FUNC_QUALIFIER std::string to_string GLM_FUNC_DECL std::string to_string(matType<T, P> const & x)
( {
tmat4x4<double, P> const & x return detail::compute_to_string<matType, T, P>::call(x);
) }
{
return detail::format("dmat4x4((%f, %f, %f, %f), (%f, %f, %f, %f), (%f, %f, %f, %f), (%f, %f, %f, %f))",
x[0][0], x[0][1], x[0][2], x[0][3],
x[1][0], x[1][1], x[1][2], x[1][3],
x[2][0], x[2][1], x[2][2], x[2][3],
x[3][0], x[3][1], x[3][2], x[3][3]);
}
}//namespace glm }//namespace glm

@ -61,6 +61,7 @@ GLM 0.9.6.0: 2014-XX-XX
- Added Added closestPointOnLine function for tvec2 to GTX_closest_point #238 - Added Added closestPointOnLine function for tvec2 to GTX_closest_point #238
- Moved template types from 'detail' to 'glm' namespace #239, #244 - Moved template types from 'detail' to 'glm' namespace #239, #244
- Added GLM_FORCE_SIZE_FUNC to replace .length() by .size() #245 - Added GLM_FORCE_SIZE_FUNC to replace .length() by .size() #245
- Fixed GTX_string_cast to support for integer types #249
================================================================================ ================================================================================
GLM 0.9.5.4: 2014-06-21 GLM 0.9.5.4: 2014-06-21

@ -12,61 +12,106 @@
#include <iostream> #include <iostream>
#include <limits> #include <limits>
int test_string_cast_scalar() int test_string_cast_vector()
{ {
int Error = 0; int Error = 0;
{
glm::vec2 A1(1, 2);
std::string A2 = glm::to_string(A1);
Error += A2 != std::string("vec2(1.000000, 2.000000)") ? 1 : 0;
float B1(1.0); glm::vec3 B1(1, 2, 3);
std::string B2 = glm::to_string(B1); std::string B2 = glm::to_string(B1);
Error += B2 != std::string("float(1.000000)") ? 1 : 0; Error += B2 != std::string("vec3(1.000000, 2.000000, 3.000000)") ? 1 : 0;
glm::vec4 C1(1, 2, 3, 4);
std::string C2 = glm::to_string(C1);
Error += C2 != std::string("vec4(1.000000, 2.000000, 3.000000, 4.000000)") ? 1 : 0;
double C1(1.0); glm::dvec2 J1(1, 2);
std::string C2 = glm::to_string(C1); std::string J2 = glm::to_string(J1);
Error += C2 != std::string("double(1.000000)") ? 1 : 0; Error += J2 != std::string("dvec2(1.000000, 2.000000)") ? 1 : 0;
return Error; glm::dvec3 K1(1, 2, 3);
} std::string K2 = glm::to_string(K1);
Error += K2 != std::string("dvec3(1.000000, 2.000000, 3.000000)") ? 1 : 0;
int test_string_cast_vector()
{
int Error = 0;
glm::vec2 A1(1, 2); glm::dvec4 L1(1, 2, 3, 4);
std::string A2 = glm::to_string(A1); std::string L2 = glm::to_string(L1);
Error += A2 != std::string("fvec2(1.000000, 2.000000)") ? 1 : 0; Error += L2 != std::string("dvec4(1.000000, 2.000000, 3.000000, 4.000000)") ? 1 : 0;
}
{
glm::bvec2 M1(false, true);
std::string M2 = glm::to_string(M1);
Error += M2 != std::string("bvec2(false, true)") ? 1 : 0;
glm::vec3 B1(1, 2, 3); glm::bvec3 O1(false, true, false);
std::string B2 = glm::to_string(B1); std::string O2 = glm::to_string(O1);
Error += B2 != std::string("fvec3(1.000000, 2.000000, 3.000000)") ? 1 : 0; Error += O2 != std::string("bvec3(false, true, false)") ? 1 : 0;
glm::bvec4 P1(false, true, false, true);
std::string P2 = glm::to_string(P1);
Error += P2 != std::string("bvec4(false, true, false, true)") ? 1 : 0;
}
glm::vec4 C1(1, 2, 3, 4); {
std::string C2 = glm::to_string(C1); glm::ivec2 D1(1, 2);
Error += C2 != std::string("fvec4(1.000000, 2.000000, 3.000000, 4.000000)") ? 1 : 0; std::string D2 = glm::to_string(D1);
Error += D2 != std::string("ivec2(1, 2)") ? 1 : 0;
glm::ivec3 E1(1, 2, 3);
std::string E2 = glm::to_string(E1);
Error += E2 != std::string("ivec3(1, 2, 3)") ? 1 : 0;
glm::ivec2 D1(1, 2); glm::ivec4 F1(1, 2, 3, 4);
std::string D2 = glm::to_string(D1); std::string F2 = glm::to_string(F1);
Error += D2 != std::string("ivec2(1, 2)") ? 1 : 0; Error += F2 != std::string("ivec4(1, 2, 3, 4)") ? 1 : 0;
}
{
glm::i8vec2 D1(1, 2);
std::string D2 = glm::to_string(D1);
Error += D2 != std::string("i8vec2(1, 2)") ? 1 : 0;
glm::ivec3 E1(1, 2, 3); glm::i8vec3 E1(1, 2, 3);
std::string E2 = glm::to_string(E1); std::string E2 = glm::to_string(E1);
Error += E2 != std::string("ivec3(1, 2, 3)") ? 1 : 0; Error += E2 != std::string("i8vec3(1, 2, 3)") ? 1 : 0;
glm::ivec4 F1(1, 2, 3, 4); glm::i8vec4 F1(1, 2, 3, 4);
std::string F2 = glm::to_string(F1); std::string F2 = glm::to_string(F1);
Error += F2 != std::string("ivec4(1, 2, 3, 4)") ? 1 : 0; Error += F2 != std::string("i8vec4(1, 2, 3, 4)") ? 1 : 0;
}
{
glm::i16vec2 D1(1, 2);
std::string D2 = glm::to_string(D1);
Error += D2 != std::string("i16vec2(1, 2)") ? 1 : 0;
glm::dvec2 J1(1, 2); glm::i16vec3 E1(1, 2, 3);
std::string J2 = glm::to_string(J1); std::string E2 = glm::to_string(E1);
Error += J2 != std::string("dvec2(1.000000, 2.000000)") ? 1 : 0; Error += E2 != std::string("i16vec3(1, 2, 3)") ? 1 : 0;
glm::dvec3 K1(1, 2, 3); glm::i16vec4 F1(1, 2, 3, 4);
std::string K2 = glm::to_string(K1); std::string F2 = glm::to_string(F1);
Error += K2 != std::string("dvec3(1.000000, 2.000000, 3.000000)") ? 1 : 0; Error += F2 != std::string("i16vec4(1, 2, 3, 4)") ? 1 : 0;
}
{
glm::i64vec2 D1(1, 2);
std::string D2 = glm::to_string(D1);
Error += D2 != std::string("i64vec2(1, 2)") ? 1 : 0;
glm::dvec4 L1(1, 2, 3, 4); glm::i64vec3 E1(1, 2, 3);
std::string L2 = glm::to_string(L1); std::string E2 = glm::to_string(E1);
Error += L2 != std::string("dvec4(1.000000, 2.000000, 3.000000, 4.000000)") ? 1 : 0; Error += E2 != std::string("i64vec3(1, 2, 3)") ? 1 : 0;
glm::i64vec4 F1(1, 2, 3, 4);
std::string F2 = glm::to_string(F1);
Error += F2 != std::string("i64vec4(1, 2, 3, 4)") ? 1 : 0;
}
return Error; return Error;
} }
@ -74,15 +119,21 @@ int test_string_cast_matrix()
{ {
int Error = 0; int Error = 0;
glm::mat2x2 A1(1.000000, 2.000000, 3.000000, 4.000000);
std::string A2 = glm::to_string(A1);
Error += A2 != std::string("mat2x2((1.000000, 2.000000), (3.000000, 4.000000))") ? 1 : 0;
return Error; return Error;
} }
int main() int main()
{ {
int Error = 0; int Error = 0;
Error += test_string_cast_scalar();
Error += test_string_cast_vector(); Error += test_string_cast_vector();
Error += test_string_cast_matrix(); Error += test_string_cast_matrix();
printf("GNI");
return Error; return Error;
} }

Loading…
Cancel
Save