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

Arc2D.Double may not draw correctly for tiny angular extents

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 1.4.0
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
      2d
    • CPU:
      generic
    • OS:
      generic

      Description



      Name: ddT132432 Date: 07/31/2001


      Java(TM) 2 Runtime Environment, Standard Edition (build Blackdown-1.3.1-FCS)
      Java HotSpot(TM) Client VM (build Blackdown-1.3.1-FCS, mixed mode)


      //file: Ikebana.java
      import java.awt.*;
      import java.awt.event.*;
      import java.awt.geom.*;
      import javax.swing.*;

      /** The following program exhibits a Bug in Arc2D.Double
       * It creates an arc with a very small angular extent.
       * Then the arc is drawn with different strokes.
       * One time the result is wrong (red),
       * one time it is o.k. (blue)
       *
       * My conjecture for the bug's source: deep inside the implementation
       * an inverse trig function (like Math.acos or Math.asin)
       * returns NaN (instead of 0, or Math.PI, or so)
       * because its argument is NOT IN [-1,1].
       * Theoretically it should be, but practically (due to roundoff errors)
       * its absolute value is greater than 1.
       *
       * Platform: JDK1.3 under Linux(i386) (Display: 17", 1024x768)
       * Reproduciblity may depend on the screen's resolution.
       */

      public class Ikebana extends JComponent {

        public void paint(Graphics g) {
          Graphics2D g2 = (Graphics2D)g;

          // ==== create an arc with a very small angular extent ========

          Arc2D.Double s=new Arc2D.Double(100.0, 100.0, 240.0, 240.0, -180.0, 1.e-15, Arc2D.PIE);

          g2.setPaint(Color.red); // BAD CASE
          g2.setStroke(new BasicStroke(1)); // draw the arc, thickness 1
          g2.draw(s);

          g2.setStroke(new BasicStroke(2)); // GOOD CASE
          g2.setPaint(Color.blue); // g2.draw((Arc2D.Double)s);
          g2.draw(s);

          // ============================================================
        }

          // ==== almost literally from Niemeyer & Knudsen

        public static void main(String[] args) {
          JFrame f = new JFrame("Ikebana");
          Container c = f.getContentPane( );
          c.setLayout(new BorderLayout( ));
          c.add(new Ikebana(), BorderLayout.CENTER);
          f.setSize(400, 400);
          f.setLocation(100, 100);
          f.addWindowListener(new WindowAdapter( ) {
            public void windowClosing(WindowEvent e) { System.exit(0); }
          });
          f.setVisible(true);
        }
      }
      // =========== END of Sample Program ====================
      (Review ID: 128180)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              spikalev Sergei Pikalev (Inactive)
              Reporter:
              ddressersunw Daniel Dresser (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: