Skip to content

graphene_matrix_is_2d is buggy #289

Description

@matthiasclasen

Here is a test that fails

#include <glib.h>
#include <graphene.h>

int main (int argc, char *argv[])
{
  graphene_matrix_t m;
  float f[] = { 0.5, 0, 0, 0,  0, 0.1, 0, 0,   0, 0, 2, 0,   0, 0, 0, 1 };
  graphene_matrix_init_from_float (&m, f);
  g_assert (!graphene_matrix_is_2d (&m));
  return 0;
}

From a quick look, this might fix it:

diff --git a/include/graphene-simd4x4f.h b/include/graphene-simd4x4f.h
index 69d4e8f..86602a5 100644
--- a/include/graphene-simd4x4f.h
+++ b/include/graphene-simd4x4f.h
@@ -1166,11 +1166,11 @@ graphene_simd4x4f_is_2d (const graphene_simd4x4f_t *m)
   graphene_simd4f_dup_4f (m->z, f);
   if (!(fabsf (f[0]) < FLT_EPSILON &&
         fabsf (f[1]) < FLT_EPSILON &&
-        1.f - fabsf (f[2]) < FLT_EPSILON &&
+        fabsf (1.f - f[2]) < FLT_EPSILON &&
         fabsf (f[3]) < FLT_EPSILON))
     return false;
 
-  if (!(fabsf (graphene_simd4f_get_z (m->w)) < FLT_EPSILON && 1.f - fabsf (graphene_simd4f_get_w (m->w)) < FLT_EPSILON))
+  if (!(fabsf (graphene_simd4f_get_z (m->w)) < FLT_EPSILON && fabsf (1.f - graphene_simd4f_get_w (m->w)) < FLT_EPSILON))
     return false;
 
   return true;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions