diff --git a/glm/gtx/constants.hpp b/glm/gtx/constants.hpp index b3a908e9..5b028e37 100644 --- a/glm/gtx/constants.hpp +++ b/glm/gtx/constants.hpp @@ -52,8 +52,12 @@ namespace glm /// @addtogroup gtx_constants /// @{ + /// @todo Implement epsilon for half-precision floating point type. template - T pi(); + GLM_FUNC_QUALIFIER T epsilon() + { + return std::numeric_limits::epsilon(); + } template GLM_FUNC_QUALIFIER T pi() diff --git a/glm/gtx/matrix_query.hpp b/glm/gtx/matrix_query.hpp index 9fb8eb17..4f356c71 100644 --- a/glm/gtx/matrix_query.hpp +++ b/glm/gtx/matrix_query.hpp @@ -42,6 +42,7 @@ // Dependency: #include "../glm.hpp" #include "../gtx/vector_query.hpp" +#include #if(defined(GLM_MESSAGES) && !defined(glm_ext)) # pragma message("GLM: GLM_GTX_matrix_query extension included") @@ -52,61 +53,61 @@ namespace glm /// @addtogroup gtx_matrix_query /// @{ - //! Return if a matrix a null matrix. - //! From GLM_GTX_matrix_query extension. + /// Return whether a matrix a null matrix. + /// From GLM_GTX_matrix_query extension. template bool isNull( detail::tmat2x2 const & m, - T const & epsilon = std::numeric_limits::epsilon()); + T const & epsilon/* = std::numeric_limits::epsilon()*/); - //! Return if a matrix a null matrix. - //! From GLM_GTX_matrix_query extension. + /// Return whether a matrix a null matrix. + /// From GLM_GTX_matrix_query extension. template bool isNull( detail::tmat3x3 const & m, - T const & epsilon = std::numeric_limits::epsilon()); + T const & epsilon/* = std::numeric_limits::epsilon()*/); - //! Return if a matrix a null matrix. - //! From GLM_GTX_matrix_query extension. + /// Return whether a matrix is a null matrix. + /// From GLM_GTX_matrix_query extension. template bool isNull( detail::tmat4x4 const & m, - T const & epsilon = std::numeric_limits::epsilon()); + T const & epsilon/* = std::numeric_limits::epsilon()*/); - //! Return if a matrix an identity matrix. - //! From GLM_GTX_matrix_query extension. + /// Return whether a matrix is an identity matrix. + /// From GLM_GTX_matrix_query extension. template bool isIdentity( genType const & m, - typename genType::value_type const & epsilon = std::numeric_limits::epsilon()); + typename genType::value_type const & epsilon/* = std::numeric_limits::epsilon()*/); - //! Return if a matrix a normalized matrix. - //! From GLM_GTX_matrix_query extension. - template + /// Return whether a matrix is a normalized matrix. + /// From GLM_GTX_matrix_query extension. + template bool isNormalized( - detail::tmat2x2 const & m, - T const & epsilon = std::numeric_limits::epsilon()); - - //! Return if a matrix a normalized matrix. - //! From GLM_GTX_matrix_query extension. - template + detail::tmat2x2 const & m, + valType const & epsilon/* = std::numeric_limits::epsilon()*/); + + /// Return whether a matrix is a normalized matrix. + /// From GLM_GTX_matrix_query extension. + template bool isNormalized( - detail::tmat3x3 const & m, - T const & epsilon = std::numeric_limits::epsilon()); - - //! Return if a matrix a normalized matrix. - //! From GLM_GTX_matrix_query extension. - template + detail::tmat3x3 const & m, + valType const & epsilon/* = std::numeric_limits::epsilon()*/); + + /// Return whether a matrix is a normalized matrix. + /// From GLM_GTX_matrix_query extension. + template bool isNormalized( - detail::tmat4x4 const & m, - T const & epsilon = std::numeric_limits::epsilon()); + detail::tmat4x4 const & m, + valType const & epsilon/* = std::numeric_limits::epsilon()*/); - //! Return if a matrix an orthonormalized matrix. - //! From GLM_GTX_matrix_query extension. - template + /// Return whether a matrix is an orthonormalized matrix. + /// From GLM_GTX_matrix_query extension. + template class matType> bool isOrthogonal( - genType const & m, - typename genType::value_type const & epsilon = std::numeric_limits::epsilon()); + matType const & m, + valType const & epsilon/* = std::numeric_limits::epsilon()*/); /// @} }//namespace glm diff --git a/glm/gtx/matrix_query.inl b/glm/gtx/matrix_query.inl index 7b4033ca..0ea53c7f 100644 --- a/glm/gtx/matrix_query.inl +++ b/glm/gtx/matrix_query.inl @@ -70,83 +70,83 @@ namespace glm return result; } - template + template GLM_FUNC_QUALIFIER bool isNormalized ( - detail::tmat2x2 const & m, - T const & epsilon + detail::tmat2x2 const & m, + genType const & epsilon ) { - bool result = true; - for(int i = 0; result && i < 2; ++i) + bool result(true); + for(detail::tmat2x2::size_type i(0); result && i < m.length(); ++i) result = isNormalized(m[i], epsilon); - for(int i = 0; result && i < 2; ++i) + for(detail::tmat2x2::size_type i(0); result && i < m.length(); ++i) { - detail::tvec2 v; - for(int j = 0; j < 2; ++j) + detail::tmat2x2::col_type v; + for(detail::tmat2x2::size_type j(0); j < m.length(); ++j) v[j] = m[j][i]; result = isNormalized(v, epsilon); } return result; } - template + template GLM_FUNC_QUALIFIER bool isNormalized ( - detail::tmat3x3 const & m, - T const & epsilon + detail::tmat3x3 const & m, + genType const & epsilon ) { - bool result = true; - for(int i = 0; result && i < 3; ++i) + bool result(true); + for(detail::tmat3x3::size_type i(0); result && i < m.length(); ++i) result = isNormalized(m[i], epsilon); - for(int i = 0; result && i < 3; ++i) + for(detail::tmat3x3::size_type i(0); result && i < m.length(); ++i) { - detail::tvec3 v; - for(int j = 0; j < 3; ++j) + detail::tmat3x3::col_type v; + for(detail::tmat3x3::size_type j(0); j < m.length(); ++j) v[j] = m[j][i]; result = isNormalized(v, epsilon); } return result; } - template + template GLM_FUNC_QUALIFIER bool isNormalized ( - detail::tmat4x4 const & m, - T const & epsilon + detail::tmat4x4 const & m, + genType const & epsilon ) { - bool result = true; - for(int i = 0; result && i < 4; ++i) + bool result(true); + for(detail::tmat4x4::size_type i(0); result && i < m.length(); ++i) result = isNormalized(m[i], epsilon); - for(int i = 0; result && i < 4; ++i) + for(detail::tmat4x4::size_type i(0); result && i < m.length(); ++i) { - detail::tvec4 v; - for(int j = 0; j < 4; ++j) + detail::tmat4x4::col_type v; + for(detail::tmat4x4::size_type j(0); j < m.length(); ++j) v[j] = m[j][i]; result = isNormalized(v, epsilon); } return result; } - template + template class matType> GLM_FUNC_QUALIFIER bool isOrthogonal ( - genType const & m, - typename genType::value_type const & epsilon + matType const & m, + genType const & epsilon ) { - bool result = true; - for(int i = 0; result && i < genType::col_size() - 1; ++i) - for(int j= i + 1; result && j < genType::col_size(); ++j) + bool result(true); + for(typename matType::size_type i(0); result && i < m.length() - 1; ++i) + for(typename matType::size_type j(i + 1); result && j < m.length(); ++j) result = areOrthogonal(m[i], m[j], epsilon); if(result) { - genType tmp = transpose(m); - for(int i = 0; result && i < genType::col_size() - 1 ; ++i) - for(int j = i + 1; result && j < genType::col_size(); ++j) + matType tmp = transpose(m); + for(typename matType::size_type i(0); result && i < m.length() - 1 ; ++i) + for(typename matType::size_type j(i + 1); result && j < m.length(); ++j) result = areOrthogonal(tmp[i], tmp[j], epsilon); } return result; diff --git a/glm/gtx/vector_query.hpp b/glm/gtx/vector_query.hpp index 4dd7be97..dace1770 100644 --- a/glm/gtx/vector_query.hpp +++ b/glm/gtx/vector_query.hpp @@ -52,59 +52,73 @@ namespace glm /// @addtogroup gtx_vector_query /// @{ - //! Check if two vectors are collinears. + //! Check whether two vectors are collinears. //! From GLM_GTX_vector_query extensions. template bool areCollinear( genType const & v0, genType const & v1, - typename genType::value_type const & epsilon = std::numeric_limits::epsilon()); + typename genType::value_type const & epsilon/* = std::numeric_limits::epsilon()*/); - //! Check if two vectors are opposites. + //! Check whether two vectors are opposites. //! From GLM_GTX_vector_query extensions. template bool areOpposite( genType const & v0, genType const & v1, - typename genType::value_type const & epsilon = std::numeric_limits::epsilon()); + typename genType::value_type const & epsilon/* = std::numeric_limits::epsilon()*/); - //! Check if two vectors are orthogonals. + //! Check whether two vectors are orthogonals. //! From GLM_GTX_vector_query extensions. template bool areOrthogonal( genType const & v0, genType const & v1, - typename genType::value_type const & epsilon = std::numeric_limits::epsilon()); + typename genType::value_type const & epsilon/* = std::numeric_limits::epsilon()*/); - //! Check if a vector is normalized. + //! Check whether a vector is normalized. //! From GLM_GTX_vector_query extensions. - template + template class vecType> bool isNormalized( - genType const & v, - typename genType::value_type const & epsilon = std::numeric_limits::epsilon()); + vecType const & v, + genType const & epsilon/* = std::numeric_limits::epsilon()*/); - //! Check if a vector is null. + //! Check whether a vector is null. //! From GLM_GTX_vector_query extensions. - template + template + bool isNull( + detail::tvec2 const & v, + valType const & epsilon/* = std::numeric_limits::epsilon()*/); + + //! Check whether a vector is null. + //! From GLM_GTX_vector_query extensions. + template + bool isNull( + detail::tvec3 const & v, + valType const & epsilon/* = std::numeric_limits::epsilon()*/); + + //! Check whether a vector is null. + //! From GLM_GTX_vector_query extensions. + template bool isNull( - genType const & v, - typename genType::value_type const & epsilon = std::numeric_limits::epsilon()); + detail::tvec4 const & v, + valType const & epsilon/* = std::numeric_limits::epsilon()*/); - //! Check if two vectors are orthonormal. + //! Check whether two vectors are orthonormal. //! From GLM_GTX_vector_query extensions. template bool areOrthonormal( genType const & v0, genType const & v1, - typename genType::value_type const & epsilon = std::numeric_limits::epsilon()); + typename genType::value_type const & epsilon/* = std::numeric_limits::epsilon()*/); - //! Check if two vectors are similar. + //! Check whether two vectors are similar. //! From GLM_GTX_vector_query extensions. template bool areSimilar( genType const & v0, genType const & v1, - typename genType::value_type const & epsilon = std::numeric_limits::epsilon()); + typename genType::value_type const & epsilon/* = std::numeric_limits::epsilon()*/); /// @} }// namespace glm diff --git a/glm/gtx/vector_query.inl b/glm/gtx/vector_query.inl index b72e1bfb..01834696 100644 --- a/glm/gtx/vector_query.inl +++ b/glm/gtx/vector_query.inl @@ -74,21 +74,41 @@ namespace glm length(v1)) * epsilon; } - template + template class vecType> GLM_FUNC_QUALIFIER bool isNormalized ( - genType const & v, - typename genType::value_type const & epsilon + vecType const & v, + genType const & epsilon ) { - return abs(length(v) - typename genType::value_type(1)) <= typename genType::value_type(2) * epsilon; + return abs(length(v) - genType(1)) <= genType(2) * epsilon; } - template + template GLM_FUNC_QUALIFIER bool isNull ( - genType const & v, - typename genType::value_type const & epsilon + detail::tvec2 const & v, + valType const & epsilon + ) + { + return length(v) <= epsilon; + } + + template + GLM_FUNC_QUALIFIER bool isNull + ( + detail::tvec3 const & v, + valType const & epsilon + ) + { + return length(v) <= epsilon; + } + + template + GLM_FUNC_QUALIFIER bool isNull + ( + detail::tvec4 const & v, + valType const & epsilon ) { return length(v) <= epsilon; diff --git a/test/gtx/CMakeLists.txt b/test/gtx/CMakeLists.txt index 89a55f7a..31af47d9 100644 --- a/test/gtx/CMakeLists.txt +++ b/test/gtx/CMakeLists.txt @@ -1,6 +1,7 @@ glmCreateTestGTC(gtx_bit) glmCreateTestGTC(gtx_gradient_paint) glmCreateTestGTC(gtx_integer) +glmCreateTestGTC(gtx_matrix_query) glmCreateTestGTC(gtx_noise) glmCreateTestGTC(gtx_quaternion) glmCreateTestGTC(gtx_random) diff --git a/test/gtx/gtx_matrix_query.cpp b/test/gtx/gtx_matrix_query.cpp new file mode 100644 index 00000000..d68eb454 --- /dev/null +++ b/test/gtx/gtx_matrix_query.cpp @@ -0,0 +1,54 @@ +/////////////////////////////////////////////////////////////////////////////////////////////////// +// OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net) +/////////////////////////////////////////////////////////////////////////////////////////////////// +// Created : 2011-11-22 +// Updated : 2011-11-22 +// Licence : This source is under MIT licence +// File : test/gtx/matrix_query.cpp +/////////////////////////////////////////////////////////////////////////////////////////////////// + +#include +#include + +int test_isNull() +{ + int Error(0); + + bool TestA = glm::isNull(glm::mat4(0), 0.00001f); + Error += TestA ? 0 : 1; + + return Error; +} + +int test_isNormalized() +{ + int Error(0); + + bool TestA = glm::isNormalized(glm::mat4(1), 0.00001f); + Error += TestA ? 0 : 1; + + return Error; +} + +int test_isOrthogonal() +{ + int Error(0); + + bool TestA = glm::isOrthogonal(glm::mat4(1), 0.00001f); + Error += TestA ? 0 : 1; + + return Error; +} + +int main() +{ + int Error(0); + + Error += test_isNull(); + Error += test_isNormalized(); + Error += test_isOrthogonal(); + + return Error; +} + +