Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4388199

Wrong result from AffineTransform.inverseTransform(d[],i,d[],i,i)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0
    • client-libs
    • 2d
    • beta
    • generic
    • generic



      Name: boT120536 Date: 11/10/2000


      java version "1.3.0beta_refresh"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0beta_refresh-b09)
      Java HotSpot(TM) Client VM (build 1.3.0beta-b07, mixed mode)

      Also FCS version; and Window 1.3 Release

      The AffineTransform.inverseTransform(double[],int,double[],int,int) method
      produces incorrect results when the AffineTransform is a pure shearing transform
      or when it is a shearing and translating transform. The simplest example of
      such a transform is the one returned from
      AffineTransform.getRotateInstance(Math.PI/2.).

      The bug is in the following method of java.awt.geom.AffineTransform
      (four lines need to be changed):

      public void inverseTransform(double[] srcPts, int srcOff,
                                   double[] dstPts, int dstOff,
                                   int numPts)

      /* Line 2641 in source */
      case (APPLY_SHEAR | APPLY_TRANSLATE):
      M01 = m01; M02 = m02;
      M10 = m10; M12 = m12;
      if (M01 == 0.0 || M10 == 0.0) {
      throw new NoninvertibleTransformException("Determinant is 0");
      }
      while (--numPts >= 0) {
      double x = srcPts[srcOff++] - M02;
      dstPts[dstOff++] = (srcPts[srcOff++] - M12) / M01;
      /* BUG!!! M01 above should be M10 */
      dstPts[dstOff++] = x / M10;
      /* BUG!!! M10 above should be M01 */
      }
      return;

      /* Line 2653 */
      case (APPLY_SHEAR):
      M01 = m01; M10 = m10;
      if (M01 == 0.0 || M10 == 0.0) {
      throw new NoninvertibleTransformException("Determinant is 0");
      }
      while (--numPts >= 0) {
      double x = srcPts[srcOff++];
      dstPts[dstOff++] = srcPts[srcOff++] / M01;
      /* BUG!!! M01 above should be M10 */
      dstPts[dstOff++] = x / M10;
      /* BUG!!! M10 above should be M01 */
      }
      return;

      Refer to the code in the inverseTransform(Point2D ptSrc, Point2D ptDst) method
      for comparison.

      The following code will show the bug. If the method were working correctly,
      then both points printed at the end would be the same; instead it produces:

      Both points should be identical:
      Original Point: 1.0 1.0
      inverseTransform method used: -1.0 -1.0


      /* XFormBug.java */
      import java.awt.geom.AffineTransform;
      import java.awt.geom.Point2D;

      /**
       * The AffineTransform method
       * inverseTransform(double[],int,double[],int,int) produces incorrect
       * results for pure shearing transformations or for shearing and
       * translation transformations. The simpliest example of which is a
       * rotation by 90 degrees. */

      public class XFormBug {

          public static void main(String[] args) {

              // Make needed arrays.
              double[] originalPoint = new double[2];
              double[] transformedPoint = new double[2];
              double[] inverseFromOriginalXForm = new double[2];

              // Make the original point to check (x,y)=(1,1).
              originalPoint[0] = 1.;
              originalPoint[1] = 1.;

              // Make a transform which rotates the coordinate system by 90
              // degrees.
              AffineTransform xform =
                  AffineTransform.getRotateInstance(Math.PI/2.);

              try {

                  // Make the transformed point.
                  xform.transform(originalPoint,0,transformedPoint,0,1);

                  // Transform the point back using the original transformation.
                  xform.inverseTransform(transformedPoint,0,
                                         inverseFromOriginalXForm,0,1);

              } catch (Exception e) {
                  System.exit(1);
              }

              System.out.println("Both points should be identical:");
              System.out.println("Original Point: "+
                                 originalPoint[0]+" "+
                                 originalPoint[1]);
              System.out.println("inverseTransform method used: "+
                                 inverseFromOriginalXForm[0]+" "+
                                 inverseFromOriginalXForm[1]);
          }

      }
      /* End of XFormBug.java */
      (Review ID: 110750)
      ======================================================================

            flar Jim Graham
            bonealsunw Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: