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

java.awt.geom.Area computes incorrect union of shapes

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 5.0
    • client-libs
    • 2d
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.5.0_06"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      java.awt.geom.Area computes incorrect union for some values.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run the test program.
      Small changes in the values produce correct output.
      The bug is in the Area functions, it can be seen in the segments returned by PathIterator.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The program should draw 2 indentical shapes..
      ACTUAL -
      2 very different shapes.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class tbug extends java.awt.Component {
        java.util.List<java.awt.geom.GeneralPath> mdl = buildMdl();

        static java.util.List<java.awt.geom.GeneralPath> buildMdl () {
          final int MoveTo = 0;
          final int LineTo = 1;
          final int QuadTo = 2;
          final int Close = 3;
          final float [][][] mdl = {
            {
            {MoveTo,344.84375f,134.29688f},
            {QuadTo,352.0703f,403.125f,57.226562f,419.02344f},
            {LineTo,47.226562f,409.02344f},
            {QuadTo,342.0703f,393.125f,334.84375f,124.296875f},
            {Close},
            },
            {
            {MoveTo,54.335938f,416.1328f},
            {QuadTo,339.0625f,395.89844f,333.28125f,122.734375f},
            {LineTo,323.28125f,112.734375f},
            {QuadTo,329.0625f,385.89844f,44.335938f,406.1328f},
            {Close},
            },
            {
            {MoveTo,340.625f,118.515625f},
            {LineTo,350.625f,128.51562f},
            {LineTo,340.625f,118.515625f},
            },
            };
          java.util.List<java.awt.geom.GeneralPath> ret = new java.util.ArrayList<java.awt.geom.GeneralPath>();
          for ( int n = 0 ; n < mdl.length ; n++ ) {
            float [][] p = mdl[n];
            java.awt.geom.GeneralPath gp = new java.awt.geom.GeneralPath();
            ret.add(gp);
            for ( int e = 0 ; e < p.length ; e++ ) {
              if ( p[e][0] == MoveTo )
                gp.moveTo(p[e][1],p[e][2]);
              else if ( p[e][0] == LineTo )
                gp.lineTo(p[e][1],p[e][2]);
              else if ( p[e][0] == QuadTo )
                gp.quadTo(p[e][1],p[e][2],p[e][3],p[e][4]);
              else if ( p[e][0] == Close )
                gp.closePath();
              else
                throw new Error("type:"+p[e][0]);
              }
            }
          return ret;
          };
        public void paint ( java.awt.Graphics g1 ) {
          java.awt.Graphics2D g = (java.awt.Graphics2D)g1;

          java.awt.geom.Area a = new java.awt.geom.Area();
          for ( int n = 0 ; n < mdl.size() ; n++ ) {
            g.fill(mdl.get(n));
            a.add(new java.awt.geom.Area(mdl.get(n)));
            }

          g1.translate(400,0);
          g.fill(a);

          }
        public java.awt.Dimension getPreferredSize() { return new java.awt.Dimension(800,440); }
        static public void main ( String [] args ) {
          java.awt.Frame f = new java.awt.Frame();
          f.add(new tbug());
          f.pack();
          f.setVisible(true);
          }
      };

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      don't use Area.

            avu Alexey Ushakov
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: