Bug about the multiplyBy with CairoMatrix

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Bug about the multiplyBy with CairoMatrix

Tristan Bourgois-2
Hi!

I found a bug with the method multiplyBy in the class CairoMatrix. I
think the bug come from the fact that you send to the primitive the
self in the result field and also in the parameter field (I found the
difference using the multiply method in VisualWorks and saw the
difference on the graphics result of my work):

self nbCall: #(void   cairo_matrix_multiply
                (AthensCairoMatrix * self,
                AthensCairoMatrix * m ,
                AthensCairoMatrix * self ) )

For example :

a := AthensCairoMatrix new.

c := AthensCairoMatrix new.
c rotateByDegrees: 40.
c translateBy: 50@50.

a := a multiplyBy: c.

a AthensCairoMatrix (
sx:     0.766044443118978
shx:    0.6427876096865393
shy:    -0.6427876096865393
sy:     0.766044443118978
x:      6.1628416716219405
y:      70.44160264027587
)

If you just swap the 2nd field with the 3rd field the result change:
self nbCall: #(void   cairo_matrix_multiply
                (AthensCairoMatrix * self,
                AthensCairoMatrix * self ,
                AthensCairoMatrix * m) )
a  AthensCairoMatrix (
sx:     0.766044443118978
shx:    0.6427876096865393
shy:    -0.6427876096865393
sy:     0.766044443118978
x:      50.0
y:      50.0
)
(the graphic result are good with the 2nd option and I have the same
result with VisualWork)

I think the problem come from this part of the doc of Cairo:

"void                cairo_matrix_multiply
(cairo_matrix_t *result,
                                                         const
cairo_matrix_t *A,
                                                         const
cairo_matrix_t *B);

Multiplies the affine transformations in a and b together and stores
the result in result. 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."

Because of Cairo change the result first with the new matrix A and
store it in the result you change too the 2nd matrix after his
application.

I think to avoid some edge effect it will be more clean to send a new
matrix for the result matrix and not "self".

What do you think?

Tristan.