Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#17670 closed defect (fixed)

Results of concatenating matrices (wxGraphicsMatrix) are not the same for different renderers

Reported by: awi Owned by: Artur Wieczorek <artwik@…>
Priority: normal Milestone:
Component: GUI-all Version: dev-latest
Keywords: wxGraphicsMatrix concatenation Cc:
Blocked By: Blocking:
Patch: no

Description

Resulting matrix given by wxGraphicsMatrix::Concat is different for different graphics renderers.
Results obtained with this snippet:

wxGraphicsRenderer *r = wxGraphicsRenderer::GetGDIPlusRenderer();
//wxGraphicsRenderer *r = wxGraphicsRenderer::GetDirect2DRenderer();
//wxGraphicsRenderer *r = wxGraphicsRenderer::GetCairoRenderer();
//...

double a, b, c, d, tx, ty;
wxGraphicsContext* ctx = r->CreateContext(dc);

wxGraphicsMatrix m1b = ctx->CreateMatrix(0.9, 0.4, -0.4, 0.9, 0.0, 0.0);
wxGraphicsMatrix m2b = ctx->CreateMatrix(1.0, 0.0, 0.0, 1.0, 3.0, 5.0);
m2b.Concat(m1b);
m2b.Get(&a, &b, &c, &d, &tx, &ty);
wxLogDebug("%8s: m11=%.1f m12=%.1f m21=%.1f m22=%.1f tx=%.1f ty=%.1f",
                   r->GetName().c_str(), a, b, c, d, tx, ty);

look as follows:

 gdiplus: m11=0.9 m12=0.4 m21=-0.4 m22=0.9 tx=3.0 ty=5.0
direct2d: m11=0.9 m12=0.4 m21=-0.4 m22=0.7 tx=0.7 ty=4.8
   cairo: m11=0.9 m12=0.4 m21=-0.4 m22=0.9 tx=0.7 ty=5.7

It looks that main reason of the problem is the order of the multiplication of the matrices inside Concat method. For GDI+ renderer the matrix passed as an argument to Concat is a multiplicand but for Direct2D and Cairo it is a multiplier.
Documentation of wxGraphicsMatrix::Concat says nothing about the order of the multiplication but for similar method wxAffineMatrix2D::Concat it is stated that matrix passed as an argument is a multiplicand. So for the sake of consistency this convention should be probably applied also to wxGraphicsMatrix::Concat.

Change History (4)

comment:1 Changed 5 years ago by Artur Wieczorek <artwik@…>

In b6d44d5329ef971458941f94fa11526f22242070/git-wxWidgets:

Fix wxGraphicsMatrix concatenation (Direct2D)

  1. Elements of resulting matrix are modified directly (in-place) in Matrix3x2F::SetProduct() so none of the multiplied matrices can be the instance of the resulting matrix.
  2. The parameter matrix in wxGraphicsMatrixData::Concat() should be a multiplicand, not a multiplier.

See #17670.

comment:2 Changed 5 years ago by Artur Wieczorek <artwik@…>

  • Owner set to Artur Wieczorek <artwik@…>
  • Resolution set to fixed
  • Status changed from new to closed

In 4d6d73eab3d59d9d88f7d18593e357fe6acd96fa/git-wxWidgets:

Fix wxGraphicsMatrix concatenation (Cairo)

The parameter matrix in wxGraphicsMatrixData::Concat() should be a multiplicand, not a multiplier.

Closes #17670.

comment:3 Changed 5 years ago by Artur Wieczorek <artwik@…>

In fb9cbc087958a39efaf6acbd917d0d42eb28cf4c/git-wxWidgets:

Add test suite to check wxGraphicsMatrix operations

Implemented tests of some basic operations like Invert() and Concat().

See #17670.

comment:4 Changed 5 years ago by awi

Results with fixed code:

 gdiplus: m11=0.9 m12=0.4 m21=-0.4 m22=0.9 tx=3.0 ty=5.0
direct2d: m11=0.9 m12=0.4 m21=-0.4 m22=0.9 tx=3.0 ty=5.0
   cairo: m11=0.9 m12=0.4 m21=-0.4 m22=0.9 tx=3.0 ty=5.0
Note: See TracTickets for help on using tickets.