On Wed, 2004-02-04 at 00:33, graydon hoare wrote:
> Olga Rodimina wrote:
> 
> > Here is the patch that fixes few errors in the AffineTransform class. 
> > It corrects a small error in shear transformation and fixes
> > createInverse() to return correct inverse matrix.
> 
> hi olga,
> 
> this stuff looks good, thanks a lot! it's surprising this just sat there 
> broken for so long. I've checked it against a few algebra texts I have 
> kicking around and some geometry libraries (including cairo) and they 
> seem to mostly agree with your calculation; though just to be difficult 
> they all use different notation and half of them do it upside down :)
> 

Hi,

I fixed the suggested changes. Attached is the revised patch that I'll
be committing.


> 
> it might be nice to write up a mauve testsuite which generates a bunch 
> of pseudorandom vectors and runs them through a bunch of pseudorandom 
> scaled, sheared and translated transformations (and their inverses) and 
> checks that the vectors pop out the same as they went in, within some 
> epsilon to account for floating point error. anything to make this stuff 
> less fidgety and prone to eyes-glossing-over would probably be good. 
> it's too easy to make a minor arithmetic mistake which completely breaks it.
> 

Sure. I'll do that.

Olga.
? .snprj
? libjava.proj
? patch
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2637
diff -c -p -u -r1.2637 ChangeLog
--- ChangeLog   4 Feb 2004 00:07:19 -0000       1.2637
+++ ChangeLog   4 Feb 2004 15:55:56 -0000
@@ -1,3 +1,13 @@
+2004-02-04  Olga Rodimina  <[EMAIL PROTECTED]>
+
+       * java/awt/geom/AffineTransform.java: 
+       Corrected comments on the field definitions for
+       m11 and m10.
+       (shear): Fixed few errors that caused shear
+       transformation to be performed incorrectly.
+       (createInverse): Fixed to return correct
+       inverse of the given matrix.
+
 2004-02-03  Tom Tromey  <[EMAIL PROTECTED]>
 
        * java/lang/natPosixProcess.cc (startProcess): Handle case where
Index: java/awt/geom/AffineTransform.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/geom/AffineTransform.java,v
retrieving revision 1.7
diff -c -p -u -r1.7 AffineTransform.java
--- java/awt/geom/AffineTransform.java  17 Sep 2003 19:06:55 -0000      1.7
+++ java/awt/geom/AffineTransform.java  4 Feb 2004 15:55:57 -0000
@@ -226,7 +226,7 @@ public class AffineTransform implements 
   private double m00;
 
   /**
-   * The Y coordinate scaling element of the transform matrix.
+   * The Y coordinate shearing element of the transform matrix.
    *
    * @serial matrix[1,0]
    */
@@ -240,7 +240,7 @@ public class AffineTransform implements 
   private double m01;
 
   /**
-   * The Y coordinate shearing element of the transform matrix.
+   * The Y coordinate scaling element of the transform matrix.
    *
    * @serial matrix[1,1]
    */
@@ -738,10 +738,10 @@ public class AffineTransform implements 
    */
   public void shear(double shx, double shy)
   {
-    double n00 = m00 + shx * m01;
-    double n01 = shx * m00 + m01;
-    double n10 = m10 * shy + m11;
-    double n11 = shx * m10 + m11;
+    double n00 = m00 + (shy * m01);
+    double n01 = m01 + (shx * m00);
+    double n10 = m10 + (shy * m11);
+    double n11 = m11 + (shx * m10);
     m00 = n00;
     m01 = n01;
     m10 = n10;
@@ -996,6 +996,38 @@ public class AffineTransform implements 
    * map multiple points to the same line or point). A transform exists only
    * if getDeterminant() has a non-zero value.
    *
+   * The inverse is calculated as:
+   * 
+   * <pre>
+   *
+   * Let A be the matrix for which we want to find the inverse:
+   *
+   * A = [ m00 m01 m02 ]
+   *     [ m10 m11 m12 ]
+   *     [ 0   0   1   ] 
+   *
+   *
+   *                 1    
+   * inverse (A) =  ---   x  adjoint(A) 
+   *                det 
+   *
+   *
+   *
+   *             =   1       [  m11  -m01   m01*m12-m02*m11  ]
+   *                ---   x  [ -m10   m00  -m00*m12+m10*m02  ]
+   *                det      [  0     0     m00*m11-m10*m01  ]
+   *
+   *
+   *
+   *             = [  m11/det  -m01/det   m01*m12-m02*m11/det ]
+   *               [ -m10/det   m00/det  -m00*m12+m10*m02/det ]
+   *               [   0           0          1               ]
+   *
+   *
+   * </pre>
+   *
+   *
+   *
    * @return a new inverse transform
    * @throws NoninvertibleTransformException if inversion is not possible
    * @see #getDeterminant()
@@ -1006,8 +1038,15 @@ public class AffineTransform implements 
     double det = getDeterminant();
     if (det == 0)
       throw new NoninvertibleTransformException("can't invert transform");
-    return new AffineTransform(m11 / det, -m10 / det, m01 / det, -m00 / det,
-                               -m02, -m12);
+    
+    double im00 = m11 / det;
+    double im10 = -m10 / det;
+    double im01 = -m01 / det;
+    double im11 = m00 / det;
+    double im02 = (m01 * m12 - m02 * m11) / det;
+    double im12 = (-m00 * m12 + m10 * m02) / det;
+    
+    return new AffineTransform (im00, im10, im01, im11, im02, im12);
   }
 
   /**
_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/classpath

Reply via email to