From 2af53d5981ba08351003fb531906d0209cbcf13c Mon Sep 17 00:00:00 2001 From: tetrisplusplus Date: Mon, 23 Jan 2023 21:05:35 +0900 Subject: [PATCH 1/3] Added test_isOrthogonal for zero matrix --- test/gtx/gtx_matrix_query.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/gtx/gtx_matrix_query.cpp b/test/gtx/gtx_matrix_query.cpp index 0dda1f09..744d3e58 100644 --- a/test/gtx/gtx_matrix_query.cpp +++ b/test/gtx/gtx_matrix_query.cpp @@ -45,8 +45,14 @@ int test_isOrthogonal() { int Error(0); - bool TestA = glm::isOrthogonal(glm::mat4(1), 0.00001f); - Error += TestA ? 0 : 1; + { + bool TestA = glm::isOrthogonal(glm::mat4(1), 0.00001f); + Error += TestA ? 0 : 1; + } + { + bool TestA = glm::isOrthogonal(glm::mat4(0), 0.00001f); + Error += TestA ? 1 : 0; + } return Error; } From 96b1c72bfc41685d5952adc51bba2689311bbe6f Mon Sep 17 00:00:00 2001 From: tetrisplusplus Date: Mon, 23 Jan 2023 21:27:02 +0900 Subject: [PATCH 2/3] Fixed isOrthogonal, return false for zero matrix --- glm/gtx/matrix_query.inl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/glm/gtx/matrix_query.inl b/glm/gtx/matrix_query.inl index b763c1ab..ab7bf943 100644 --- a/glm/gtx/matrix_query.inl +++ b/glm/gtx/matrix_query.inl @@ -99,14 +99,14 @@ namespace glm bool result = true; for(length_t i(0); result && i < m.length() - 1; ++i) for(length_t j(i + 1); result && j < m.length(); ++j) - result = areOrthogonal(m[i], m[j], epsilon); + result = areOrthonormal(m[i], m[j], epsilon); if(result) { mat tmp = transpose(m); for(length_t i(0); result && i < m.length() - 1 ; ++i) for(length_t j(i + 1); result && j < m.length(); ++j) - result = areOrthogonal(tmp[i], tmp[j], epsilon); + result = areOrthonormal(tmp[i], tmp[j], epsilon); } return result; } From e48b2a72c8b5d10b129eca24b390d4fc9733054e Mon Sep 17 00:00:00 2001 From: tetrisplusplus Date: Mon, 23 Jan 2023 21:41:27 +0900 Subject: [PATCH 3/3] Improved performace. --- glm/gtx/matrix_query.inl | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/glm/gtx/matrix_query.inl b/glm/gtx/matrix_query.inl index ab7bf943..dc3ec845 100644 --- a/glm/gtx/matrix_query.inl +++ b/glm/gtx/matrix_query.inl @@ -97,16 +97,22 @@ namespace glm GLM_FUNC_QUALIFIER bool isOrthogonal(mat const& m, T const& epsilon) { bool result = true; - for(length_t i(0); result && i < m.length() - 1; ++i) - for(length_t j(i + 1); result && j < m.length(); ++j) - result = areOrthonormal(m[i], m[j], epsilon); + for(length_t i(0); result && i < m.length(); ++i) + { + result = isNormalized(m[i], epsilon); + for(length_t j(i + 1); result && j < m.length(); ++j) + result = abs(dot(m[i], m[j])) <= epsilon; + } if(result) { mat tmp = transpose(m); - for(length_t i(0); result && i < m.length() - 1 ; ++i) - for(length_t j(i + 1); result && j < m.length(); ++j) - result = areOrthonormal(tmp[i], tmp[j], epsilon); + for(length_t i(0); result && i < m.length(); ++i) + { + result = isNormalized(tmp[i], epsilon); + for(length_t j(i + 1); result && j < m.length(); ++j) + result = abs(dot(tmp[i], tmp[j])) <= epsilon; + } } return result; }