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

AffineTransform.createTransformedShape destroys type information

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.1
    • client-libs
    • 2d
    • generic
    • generic



      Name: boT120536 Date: 03/23/2001


      java version "1.3.1-beta"
      java(tm) 2 runtime environment, standard edition (build 1.3.1-beta-b15)
      java hotspot(tm) client vm (build 1.3.1beta-b15, mixed mode)

      // To transform a Line2D without turning it into a GeneralPath,
      // the following hack works:

      private Line2D line;

      void transform(AffineTransform transform) {
        double[] array = new double[4];
        array[0] = line.getX1();
        array[1] = line.getY1();
        array[2] = line.getX2();
        array[3] = line.getY2();
        transform.transform(array, 0, array, 0, 2);
        line.setLine(array[0], array[1], array[2], array[3]);
      }

      // But what do you do with an Ellipse? If you try the hack above, it won't
      // work for a rotate transform:

      private Ellipse2D ellipse;

      void transform(AffineTransform transform) {
        double[] array = new double[4];
        array[0] = ellipse.getX();
        array[1] = ellipse.getY();
        array[2] = ellipse.getWidth();
        array[3] = ellipse.getHeight();
        transform.transform(array, 0, array, 0, 2);
        ellipse.setFrame(array[0], array[1], array[2], array[3]);
      }

      // I submitted two earlier bug reports on this issue, but now I realize it
      // is really much more serious than I had first imagined.
      // First of all, there is no way to use an AffineTransform to transform a shape
      // without getting back a GeneralPath object. Now I understand that some classes
      // (i.e. Ellipse2D) cannot represent the shape once it has been transformed.
      // For example, the Ellipse2D cannot represent an Ellipse once it has been
      // rotated. Therefore, once a transform has been applied, one must work with
      // a GeneralPath object. This is a SERIOUS design flaw, much like cloning
      // ObjectA and getting back (an unrelated) ObjectB. How can you create a
      // good design in this situation?
      // Furthermore, in the case (for example) of the rotated
      // Ellipse2D, you can't even get the points from the GeneralPath that
      // model the transformed shape. You can only get the PathIterator, which
      // then gives you (say) the later 3 points of a cubic ("cube to"), but not the
      // starting point!!
      (Review ID: 119351)
      ======================================================================

            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: