diff --git a/glm/gtx/component_wise.hpp b/glm/gtx/component_wise.hpp index 57925cd001..b1caaa2744 100644 --- a/glm/gtx/component_wise.hpp +++ b/glm/gtx/component_wise.hpp @@ -61,6 +61,16 @@ namespace glm template GLM_FUNC_DECL typename genType::value_type compMax(genType const& v); + /// Find the minimum float between single vector components. + /// @see gtx_component_wise + template + GLM_FUNC_DECL typename genType::value_type fcompMin(genType const& v); + + /// Find the maximum float between single vector components. + /// @see gtx_component_wise + template + GLM_FUNC_DECL typename genType::value_type fcompMax(genType const& v); + /// @} }//namespace glm diff --git a/glm/gtx/component_wise.inl b/glm/gtx/component_wise.inl index cbbc7d41ec..3a993dbcea 100644 --- a/glm/gtx/component_wise.inl +++ b/glm/gtx/component_wise.inl @@ -1,6 +1,7 @@ /// @ref gtx_component_wise #include +#include namespace glm{ namespace detail @@ -124,4 +125,22 @@ namespace detail Result = max(Result, v[i]); return Result; } + + template::value, T>::type> + GLM_FUNC_QUALIFIER T fcompMin(vec const& v) + { + T Result(v[0]); + for(length_t i = 1, n = v.length(); i < n; ++i) + Result = std::fmin(Result, v[i]); + return Result; + } + + template::value, T>::type> + GLM_FUNC_QUALIFIER T fcompMax(vec const& v) + { + T Result(v[0]); + for(length_t i = 1, n = v.length(); i < n; ++i) + Result = std::fmax(Result, v[i]); + return Result; + } }//namespace glm diff --git a/test/gtx/gtx_component_wise.cpp b/test/gtx/gtx_component_wise.cpp index 9fab86f8fe..f8d8c7819b 100644 --- a/test/gtx/gtx_component_wise.cpp +++ b/test/gtx/gtx_component_wise.cpp @@ -105,12 +105,71 @@ namespace compScale } }// compScale +namespace fcompMax +{ + static int run() + { + int Error(0); + + { + float const A = glm::fcompMax(glm::vec4(NAN, 0.2f, 0.5f, 1.0f)); + + Error += A == 1.0f ? 0 : 1; + } + + { + float const A = glm::fcompMax(glm::vec4(2.0f, NAN, 0.3f, 0.7f)); + + Error += A == 2.0f ? 0 : 1; + } + + { + float const A = glm::fcompMax(glm::vec4(NAN, NAN, NAN, NAN)); + + Error += std::isnan(A) ? 0 : 1; + } + + return Error; + } +}// fcompMax + +namespace fcompMin +{ + static int run() + { + int Error(0); + + { + float const A = glm::fcompMin(glm::vec4(NAN, 0.2f, 0.5f, 1.0f)); + + Error += A == 0.2f ? 0 : 1; + } + + { + float const A = glm::fcompMin(glm::vec4(2.0f, NAN, 0.3f, 0.7f)); + + Error += A == 0.3f ? 0 : 1; + } + + { + float const A = glm::fcompMin(glm::vec4(NAN, NAN, NAN, NAN)); + + Error += std::isnan(A) ? 0 : 1; + } + + + return Error; + } +}// fcompMin + int main() { int Error(0); Error += compNormalize::run(); Error += compScale::run(); + Error += fcompMax::run(); + Error += fcompMin::run(); return Error; }