JDK-4222387 : Filled ellipses are often not as smooth as calling fillOval in JDK 1.1
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 1999-03-21
  • Updated: 1999-04-09
  • Resolved: 1999-04-09
Related Reports
Duplicate :  
Description

Name: dbT83986			Date: 03/21/99


The below code will produce the discrepency between the standard oval in the Graphics package and the Ellipse2D in the
Graphics2D package - the Ellipse2D object doesn't "look" quite right, and certianly not as good as the standard oval object.
The documenation seems to indicate the 2D objects will only look right when anti-aliasing is on unless some "rule" is applied
for selecting pixels during the rasterization process, but it doesn't say what this rule is or how to use it. If anti-aliasing is turned
on, one can't tell the difference between the oval and the Ellipse2D, but with it off, the Ellipse2D doesn't look as intended at all.

Code:


import java.awt.*;

public class inc55846 extends Frame
{
	public inc55846()
	{
		add(new OvalCanvas());
		setSize(100,100);
	}

	public static void main(String[] args)
	{
		new inc55846().show();
	}
}

class OvalCanvas extends Canvas
{

	public void paint(Graphics g)
	{
	    Graphics2D g2 = (Graphics2D)g;
    
	    g2.setColor(Color.red);
 	   g.drawOval(45, 10, 30, 30);
	    // Notice the difference between an Ellipse2D.Float and a simple Oval:
    
	    g2.setPaint(Color.red);
	    Ellipse2D.Float ellipse1 = new Ellipse2D.Float(10.0f, 10.0f, 30.0f, 30.0f);
	    g2.draw(ellipse1);
	}
}
(Review ID: 55846)
======================================================================

Comments
EVALUATION If the ellipse is filled through the general shape mechanism then the outline is expressed as Bezier curve segments. The floating point Bezier curve segments approximate the ellipse quite well (to less than .14% error), but we apparently lose some accuracy during the scan conversion. Also, fillOval will typically be directed to the X11 protocol arc filler if standard screen attributes are used (solid color, no transformations other than translates, no alpha), but if the rendering is to an offscreen image or BufferedImage or if some non-default attributes are used, then we may fill the oval using our own code which will not be quite as smooth. This can be fixed in one of two ways. One way is to work on the accuracy of our scan conversion algorithms which will make all non-antialiased rendering smoother. Another is to detect ellipses in our renderer and use a more specific "conic" scan conversion algorithm. jim.graham@Eng 1999-04-09
09-04-1999