Hi folks,

I've found what seems like a bug in the java2d drawing code.  I've
included a simple test application, at the end of this email, that
demonstrates the problem.  It involves drawing dashed lines whose
ratio of line length to dash length is very large.  I've tested it in
both java 1.4.2 and java 1.5 and found the problem in both cases.

Here are some results of my tests that demonstrate the issue.

Drawing a solid line seems fine no matter what the length...

[EMAIL PROTECTED]> time java -cp . DrawDash 0 10000000

real    0m0.980s
user    0m0.752s
sys     0m0.052s

...However, when we add a dash to this long line it suddenly takes
much longer to draw...

[EMAIL PROTECTED]> time java -cp . DrawDash 5
10000000

real    0m10.262s
user    0m9.865s
sys     0m0.080s

...however, if we simply drop the length of the line down by a factor
of 10 we are back to a reasonable length of time ...

[EMAIL PROTECTED]> time java -cp . DrawDash 5 1000000

real    0m1.317s
user    0m1.212s
sys     0m0.016s

... The problem seems to be more based upon the ratio of the dash length to the
line length as evidenced by the following set of results.  First, this
short line length with this incredibly short dash length is mostly
fine...

[EMAIL PROTECTED]> time java -cp . DrawDash .0005 100

real    0m2.426s
user    0m2.220s
sys     0m0.044s


...while these two, with a dash/length ratio 1/10th of that above, I
had to kill because they were taking longer than 2 minutes!...

time java -cp . DrawDash .0005 1000
time java -cp . DrawDash .00005 100

...which seems to suggest that it is not entirely based upon the ratio
since if that were the case they should take around 10 or 11 seconds
as the one above with the same ratio.  However, they take much longer
than that.  Maybe they will never finish!

But, anyway, something is going on that it seems should be easily
fixed.  Anyone have any ideas?

Cheers,

Ken


Here is the code for my tests...

import javax.swing.JDialog;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;

public class DrawDash
{
    public static void main( String[]    args )
    {
        double    lineSize = 1000.;
        float     dashLength = 10;

        if ( args.length >= 1 )
        {
            dashLength = Float.parseFloat( args[0] );
        }

        if ( args.length >= 2 )
        {
            lineSize = Double.parseDouble( args[1] );
        }

        JDialog    dialog = new JDialog();
        dialog.setSize( new Dimension( 800, 800 ) );
        dialog.show();

        Graphics2D    graphics = (Graphics2D) dialog.getGraphics();
        graphics.setPaint( Color.RED );

        if ( dashLength > 0 )
        {
            float[]    dashArray = new float[]{ dashLength, dashLength };

            BasicStroke    stroke;
            stroke = new BasicStroke( 1,
                                      BasicStroke.CAP_ROUND,
                                      BasicStroke.JOIN_ROUND,
                                      10.0f,
                                      dashArray,
                                      0 );
            graphics.setStroke( stroke );
        }

        graphics.draw( new Line2D.Double( -lineSize,
                                          -lineSize,
                                          lineSize,
                                          lineSize ) );

        System.exit( 0 );
    }
}

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to