Bug in the XYShapeAnnotation

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Zlatogorov
Posts: 2
Joined: Thu Aug 06, 2015 3:14 pm
antibot: No, of course not.

Bug in the XYShapeAnnotation

Post by Zlatogorov » Fri Aug 07, 2015 9:44 am

In the class XYShapeAnnotation , lines 179,180, 186,179

Code: Select all

 double m00 = (xx1 - xx0) / (x1 - x0);
double m02 = xx0 - x0 * m00;

Code: Select all

 double m11 = (yy1 - yy0) / (y1 - y0);
 double m12 = yy0 - m11 * y0;
if we try draw horizontal or vertical line than x1==x0 or y1==y0,the result of by dividing m00 is NaN :), and following AffineTransform don't work.
Please fix.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Bug in the XYShapeAnnotation

Post by david.gilbert » Wed Sep 09, 2015 6:37 am

I confirm this is a bug. It's not obvious to me, just yet, how to fix it.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: Bug in the XYShapeAnnotation

Post by John Matthews » Wed Sep 09, 2015 9:29 am

Examples here and here avoid the problem by using a similarly stroked XYLineAnnotation.

Zlatogorov
Posts: 2
Joined: Thu Aug 06, 2015 3:14 pm
antibot: No, of course not.

Re: Bug in the XYShapeAnnotation

Post by Zlatogorov » Mon Oct 05, 2015 4:09 pm

Code fix:
double m00 = (x1 - x0 == 0) ? 0 : (xx1 - xx0) / (x1 - x0);
double m11 = (y1 - y0 == 0) ? 0 : (yy1 - yy0) / (y1 - y0);

Locked