Fixed GTX_string_cast to support for integer types #249

This commit is contained in:
Christophe Riccio 2014-10-10 01:21:04 +02:00
parent ca4ed31fb6
commit 75939a7960
4 changed files with 468 additions and 455 deletions

View File

@ -22,7 +22,7 @@
///
/// @ref gtx_string_cast
/// @file glm/gtx/string_cast.hpp
/// @date 2008-04-26 / 2011-06-07
/// @date 2008-04-26 / 2014-05-10
/// @author Christophe Riccio
///
/// @see core (dependence)
@ -43,8 +43,7 @@
// Dependency:
#include "../glm.hpp"
#include "../gtx/integer.hpp"
#include "../gtx/quaternion.hpp"
#include "../gtc/type_precision.hpp"
#include <string>
#if(GLM_COMPILER & GLM_COMPILER_CUDA)
@ -60,10 +59,10 @@ namespace glm
/// @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.
template <typename genType>
GLM_FUNC_DECL std::string to_string(genType const & x);
template <template <typename, precision> class matType, typename T, precision P>
GLM_FUNC_DECL std::string to_string(matType<T, P> const & x);
/// @}
}//namespace glm

View File

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

View File

@ -61,6 +61,7 @@ GLM 0.9.6.0: 2014-XX-XX
- Added Added closestPointOnLine function for tvec2 to GTX_closest_point #238
- Moved template types from 'detail' to 'glm' namespace #239, #244
- 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

View File

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