/// @ref gtx_component_wise /// @file glm/gtx/component_wise.inl #include namespace glm{ namespace detail { template struct compute_compNormalize {}; template struct compute_compNormalize { GLM_FUNC_QUALIFIER static vec call(vec const& v) { floatType const Min = static_cast(std::numeric_limits::min()); floatType const Max = static_cast(std::numeric_limits::max()); return (vec(v) - Min) / (Max - Min) * static_cast(2) - static_cast(1); } }; template struct compute_compNormalize { GLM_FUNC_QUALIFIER static vec call(vec const& v) { return vec(v) / static_cast(std::numeric_limits::max()); } }; template struct compute_compNormalize { GLM_FUNC_QUALIFIER static vec call(vec const& v) { return v; } }; template struct compute_compScale {}; template struct compute_compScale { GLM_FUNC_QUALIFIER static vec call(vec const& v) { floatType const Max = static_cast(std::numeric_limits::max()) + static_cast(0.5); vec const Scaled(v * Max); vec const Result(Scaled - static_cast(0.5)); return Result; } }; template struct compute_compScale { GLM_FUNC_QUALIFIER static vec call(vec const& v) { return vec(vec(v) * static_cast(std::numeric_limits::max())); } }; template struct compute_compScale { GLM_FUNC_QUALIFIER static vec call(vec const& v) { return v; } }; }//namespace detail template GLM_FUNC_QUALIFIER vec compNormalize(vec 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 GLM_FUNC_QUALIFIER vec compScale(vec 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 GLM_FUNC_QUALIFIER T compAdd(vec const& v) { T Result(0); for(length_t i = 0, n = v.length(); i < n; ++i) Result += v[i]; return Result; } template GLM_FUNC_QUALIFIER T compMul(vec const& v) { T Result(1); for(length_t i = 0, n = v.length(); i < n; ++i) Result *= v[i]; return Result; } template GLM_FUNC_QUALIFIER T compMin(vec 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 GLM_FUNC_QUALIFIER T compMax(vec 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