Skip to content

Commit

Permalink
Merge pull request g-truc#1137 from tetrisplusplus/fix_glm_gtx_matrix…
Browse files Browse the repository at this point in the history
…_query_isOrthogonal

fix: isOrthogonal for a zero matrix g-truc#1137
  • Loading branch information
christophe-lunarg authored Aug 18, 2023
2 parents 2c74560 + e48b2a7 commit db0f79d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
18 changes: 12 additions & 6 deletions glm/gtx/matrix_query.inl
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,22 @@ namespace glm
GLM_FUNC_QUALIFIER bool isOrthogonal(mat<C, R, T, Q> 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 = areOrthogonal(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<C, R, T, Q> 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);
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;
}
Expand Down
10 changes: 8 additions & 2 deletions test/gtx/gtx_matrix_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit db0f79d

Please sign in to comment.