[cairo] Reduce number of floating point operations

Jeff Smith whydoubt at yahoo.com
Wed Sep 20 11:46:27 PDT 2006


> >> +    /* memcmp() should be faster than 4 soft float operations */
> >> +    static const cairo_matrix_t identity = {
> >> +           1.0, 0.0,
> >> +           0.0, 1.0,
> >> +           0.0, 0.0
> >> +    };
> >> +    return (memcmp (matrix, &identity, 4 * sizeof(double)) == 0);
> >> +#else 
> >>      return (matrix->xx == 1.0 && matrix->yx == 0.0 &&
> >> -           matrix->xy == 0.0 && matrix->yy == 1.0 &&
> >> -           matrix->x0 == 0.0 && matrix->y0 == 0.0);
> >> +           matrix->xy == 0.0 && matrix->yy == 1.0);
> >> +#endif
> >>     
> >
> > Why is it called is_identity if it doesn't check for translation?
> >   
> According to wikipedia (http://en.wikipedia.org/wiki/Identity_matrix)
> identity matrix is n x n, so third row in cairo_matrix_t actually is a
> translation vector.

In 2D graphics we use a 3x3 matrix.  In normalized form, the last column (or row,
depending on how you set up your orientation) will (with one exception) always contain
[0]
[0]
[1]
which is always implied when using the commonly-seen six-element form, as in the case of
cairo_matrix_t.  So we really are checking for the identity matrix
[1 0 0]
[0 1 0]
[0 0 1]
but the final column is implicit, so we can (and need) only handle and test against
[1 0]
[0 1]
[0 0]

 -- Jeff "Pedantic" Smith

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the cairo mailing list