[PyKDE] QWMatrix bugs ( was Undocumented shortcommings )

myrkraverk at users.sourceforge.net myrkraverk at users.sourceforge.net
Tue Sep 2 16:58:01 BST 2003


Torsten Marek writes:
 > myrkraverk at users.sourceforge.net schrieb:

 > > Before I go any further, I'm going to state that my version of
 > > python is 2.3, PyQt is 3.8 and Qt is 3.2.1.

And my GCC is 3.3.1.

 > > It is not possible to use the new mapRect() method of QWMatrix,
 > > but map() works for QRect, but is obsolete, this should at least
 > > be documented.

 > That's right. This should be changed. Small patch for the sip files
 > included.


 > > Other shortcommings of QWMatrix is the lack of the * operator, a
 > > very commonly used operator when dealing with matrices, I did not
 > > try + but it should be working.  Again, these shortcommings are
 > > only semi-documented as it's only meantioned that the ==, != and
 > > *= operators work.

 > There is no such thing in the Qt class, but if you provide sip code,
 > Phil may put it into PyQt.

Your right -- and wrong.  There is a * operator in the Qt class, it is
just not documented very well, the only reference to it in the docs is
in the following example from qwmatrix.html:

  double a    = pi/180 * 25;         // convert 25 to radians
  double sina = sin(a);
  double cosa = cos(a);
  QWMatrix m1(0, 0, 0, 0, 10, -20);  // translation matrix
  QWMatrix m2( cosa, sina,           // rotation matrix
              -sina, cosa, 0, 0 );
  QWMatrix m3(1.2, 0, 0, 0.7, 0, 0); // scaling matrix
  QWMatrix m;
  m = m3 * m2 * m1;                  // combine all transformations

Unfortunately, the * doesn't seem to work, after running the above
code (with enaugh mods to make it compile), m is the zero matrix ;(

I've yet to determine whether it's a bug in Qt, my compiler or what.

After looking at the Qt code, I discovered that the following
operators are definded, and though I've not tested them myself they
seem to Do The Right Thing(tm):

QWMatrix * QPoint
QWMatrix * QRect
QWMatrix * QRegion
QWMatrix * QPointArray

I'd like to see them as well in PyQt.  I'll consider applying sip code
when I know why * doesn't work for matrices and/or have a fix.  It may
be in the copy constructors or even my compiler -- as I've said, I've
yet to take a look.

 > > Another mis-feature of QWMatrix is that the invert() method does
 > > not work as one would expect.  It is impossible to use an
 > > inverted matrix again with Qt as it's a tuple, which to me, is
 > > useless.  I recommend that this will be fixed, at least with a
 > > constructor that can create a QWMatrix from that tuple.

 > Yes, but the Qt version of the invert function takes a pointer to a
 > boolean to show whether the inverted matrix is the identity matrix.
 > QWMatrix.invert()[0] is the inverted matrix and [1] the boolean
 > value.

Writing this, I've yet to test it, but if I can do

  m = m.invert()[0]

I'm happy ;)

 > > I went mathematical and worked around this shortcommings when
 > > doing part 14 of the tutorial.  If anyone is interested I could
 > > publish the code, and even translate the entire tutorial into
 > > python.  I already have most of the chapters in more or less line
 > > by line compatible code with the text of the tutorial.

This offer still stands.



Emacs is not a text editor -- it's a way of life

More information about the PyQt mailing list