/// @ref gtx_component_wise /// @file glm/gtx/component_wise.inl #include namespace glm{ namespace detail { template class vecType, bool isInteger, bool signedType> struct compute_compNormalize {}; template class vecType> struct compute_compNormalize { GLM_FUNC_QUALIFIER static vecType call(vecType const & v) { floatType const Min = static_cast(std::numeric_limits::min()); floatType const Max = static_cast(std::numeric_limits::max()); return (vecType(v) - Min) / (Max - Min) * static_cast(2) - static_cast(1); } }; template class vecType> struct compute_compNormalize { GLM_FUNC_QUALIFIER static vecType call(vecType const & v) { return vecType(v) / static_cast(std::numeric_limits::max()); } }; template class vecType> struct compute_compNormalize { GLM_FUNC_QUALIFIER static vecType call(vecType const & v) { return v; } }; template class vecType, bool isInteger, bool signedType> struct compute_compScale {}; template class vecType> struct compute_compScale { GLM_FUNC_QUALIFIER static vecType call(vecType const & v) { floatType const Max = static_cast(std::numeric_limits::max()) + static_cast(0.5); vecType const Scaled(v * Max); vecType const Result(Scaled - static_cast(0.5)); return Result; } }; template class vecType> struct compute_compScale { GLM_FUNC_QUALIFIER static vecType call(vecType const & v) { return vecType(vecType(v) * static_cast(std::numeric_limits::max())); } }; template class vecType> struct compute_compScale { GLM_FUNC_QUALIFIER static vecType call(vecType const & v) { return v; } }; }//namespace detail template class vecType> GLM_FUNC_QUALIFIER vecType compNormalize(vecType const & v) { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'compNormalize' accepts only floating-point types for 'floatType' template parameter"); return detail::compute_compNormalize::is_integer, std::numeric_limits::is_signed>::call(v); } template class vecType> GLM_FUNC_QUALIFIER vecType compScale(vecType const & v) { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'compScale' accepts only floating-point types for 'floatType' template parameter"); return detail::compute_compScale::is_integer, std::numeric_limits::is_signed>::call(v); } template class vecType> GLM_FUNC_QUALIFIER T compAdd(vecType const & v) { T Result(0); for(length_t i = 0, n = v.length(); i < n; ++i) Result += v[i]; return Result; } template class vecType> GLM_FUNC_QUALIFIER T compMul(vecType const & v) { T Result(1); for(length_t i = 0, n = v.length(); i < n; ++i) Result *= v[i]; return Result; } template class vecType> GLM_FUNC_QUALIFIER T compMin(vecType const & v) { T Result(v[0]); for(length_t i = 1, n = v.length(); i < n; ++i) Result = min(Result, v[i]); return Result; } template class vecType> GLM_FUNC_QUALIFIER T compMax(vecType const & v) { T Result(v[0]); for(length_t i = 1, n = v.length(); i < n; ++i) Result = max(Result, v[i]); return Result; } }//namespace glm