[cairo] Matrix Inconsistency?

Lawrence D'Oliveiro ldo at geek-central.gen.nz
Mon Jun 27 04:06:35 UTC 2016


The docs for cairo_matrix_multiply(&result, &a, &b)
<https://www.cairographics.org/manual/cairo-cairo-matrix-t.html#cairo-matrix-multiply>
say “The effect of the resulting transformation is to first apply the
transformation in a to the coordinates and then apply the
transformation in b to the coordinates”, while the docs for
cairo_transform
<https://www.cairographics.org/manual/cairo-Transformations.html#cairo-transform>
say “The new transformation of user space takes place after any
existing transformation”.

It seems to me, then that the sequence

    cairo_matrix_multiply(&resultmat, &mat_rotate, &mat_translate);

should put the same thing into resultmat as the sequence

    cairo_identity_matrix(cr);
    cairo_transform(cr, &mat_rotate);
    cairo_transform(cr, &mat_translate);
    cairo_get_matrix(cr, &resultmat);

but it does not. Given the following definitions for mat_rotate and
mat_translate:

    cairo_matrix_init_rotate(&mat_rotate, M_PI / 4.0);
    cairo_matrix_init_translate(&mat_translate, 1.0, 1.0);

I get the following output from my test program:

    * matrix:
    rotate × translate = [[0.707, -0.707, 1] [0.707, 0.707, 1] [0, 0, 1]]
    translate × rotate = [[0.707, -0.707, 1.11e-16] [0.707, 0.707, 1.41] [0, 0, 1]]
    * context:
    rotate × translate = [[0.707, -0.707, 1.11e-16] [0.707, 0.707, 1.41] [0, 0, 1]]
    translate × rotate = [[0.707, -0.707, 1] [0.707, 0.707, 1] [0, 0, 1]]

The output for the cairo_matrix calls looks the right way round,
that for the cairo_transform calls does not.

See the attached source for the full program.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: matrix_order.c
Type: text/x-c++src
Size: 2730 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20160627/2263e5b9/attachment.c>


More information about the cairo mailing list