mirror of
https://github.com/g-truc/glm.git
synced 2024-11-25 18:04:34 +00:00
Added compScale
This commit is contained in:
parent
062e1238fa
commit
26f1065429
BIN
doc/glm.docx
BIN
doc/glm.docx
Binary file not shown.
@ -60,6 +60,9 @@ namespace glm
|
||||
template <typename floatType, typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_DECL vecType<floatType, P> compNormalize(vecType<T, P> const & v);
|
||||
|
||||
template <typename floatType, typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_DECL vecType<T, P> compScale(vecType<floatType, P> const & v);
|
||||
|
||||
/// Add all vector components together.
|
||||
/// @see gtx_component_wise
|
||||
template <typename genType>
|
||||
|
@ -67,6 +67,39 @@ namespace detail
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename floatType, precision P, template <typename, precision> class vecType, bool isInteger, bool signedType>
|
||||
struct compute_compScale
|
||||
{};
|
||||
|
||||
template <typename T, typename floatType, precision P, template <typename, precision> class vecType>
|
||||
struct compute_compScale<T, floatType, P, vecType, true, true>
|
||||
{
|
||||
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<floatType, P> const & v)
|
||||
{
|
||||
floatType const Min = static_cast<floatType>(std::numeric_limits<T>::min());
|
||||
floatType const Max = static_cast<floatType>(std::numeric_limits<T>::max());
|
||||
return (vecType<floatType, P>(v) + Min) * (Max - Min) * static_cast<floatType>(2) - static_cast<floatType>(1);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename floatType, precision P, template <typename, precision> class vecType>
|
||||
struct compute_compScale<T, floatType, P, vecType, true, false>
|
||||
{
|
||||
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<floatType, P> const & v)
|
||||
{
|
||||
return vecType<T, P>(vecType<floatType, P>(v) * static_cast<floatType>(std::numeric_limits<T>::max()));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename floatType, precision P, template <typename, precision> class vecType>
|
||||
struct compute_compScale<T, floatType, P, vecType, false, true>
|
||||
{
|
||||
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<floatType, P> const & v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
};
|
||||
}//namespace detail
|
||||
|
||||
template <typename floatType, typename T, precision P, template <typename, precision> class vecType>
|
||||
@ -77,6 +110,14 @@ namespace detail
|
||||
return detail::compute_compNormalize<T, floatType, P, vecType, std::numeric_limits<T>::is_integer, std::numeric_limits<T>::is_signed>::call(v);
|
||||
}
|
||||
|
||||
template <typename T, typename floatType, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> compScale(vecType<floatType, P> const & v)
|
||||
{
|
||||
GLM_STATIC_ASSERT(std::numeric_limits<floatType>::is_iec559, "'compNormalize' accepts only floating-point types for 'floatType' template parameter");
|
||||
|
||||
return detail::compute_compScale<T, floatType, P, vecType, std::numeric_limits<T>::is_integer, std::numeric_limits<T>::is_signed>::call(v);
|
||||
}
|
||||
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER T compAdd(vecType<T, P> const & v)
|
||||
{
|
||||
|
@ -35,7 +35,7 @@
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <limits>
|
||||
|
||||
namespace integer_8bit_test
|
||||
namespace compNormalize
|
||||
{
|
||||
int run()
|
||||
{
|
||||
@ -59,16 +59,6 @@ namespace integer_8bit_test
|
||||
Error += glm::epsilonEqual(A.w, 1.0f, glm::epsilon<float>()) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace integer_8bit_test
|
||||
|
||||
namespace integer_16bit_test
|
||||
{
|
||||
int run()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
{
|
||||
glm::vec4 const A = glm::compNormalize<float>(glm::u16vec4(
|
||||
std::numeric_limits<glm::u16>::min(),
|
||||
@ -97,14 +87,42 @@ namespace integer_16bit_test
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace integer_16bit_test
|
||||
}//namespace compNormalize
|
||||
|
||||
namespace compScale
|
||||
{
|
||||
int run()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
{
|
||||
glm::u8vec4 const A = glm::compScale<glm::u8>(glm::vec4(0.0f, 0.2f, 0.5f, 1.0f));
|
||||
|
||||
Error += A.x == std::numeric_limits<glm::u8>::min() ? 0 : 1;
|
||||
Error += A.y > (std::numeric_limits<glm::u8>::max() >> 1) ? 0 : 1;
|
||||
Error += A.z < (std::numeric_limits<glm::u8>::max() >> 2) ? 0 : 1;
|
||||
Error += A.x == std::numeric_limits<glm::u8>::max() ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::u16vec4 const A = glm::compScale<glm::u16>(glm::vec4(0.0f, 0.2f, 0.5f, 1.0f));
|
||||
|
||||
Error += A.x == std::numeric_limits<glm::u16>::min() ? 0 : 1;
|
||||
Error += A.y > (std::numeric_limits<glm::u16>::max() >> 1) ? 0 : 1;
|
||||
Error += A.z < (std::numeric_limits<glm::u16>::max() >> 2) ? 0 : 1;
|
||||
Error += A.x == std::numeric_limits<glm::u16>::max() ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
}// compScale
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
Error += integer_8bit_test::run();
|
||||
Error += integer_16bit_test::run();
|
||||
Error += compNormalize::run();
|
||||
Error += compScale::run();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user