-
Bug
-
Resolution: Won't Fix
-
P4
-
7
-
generic
-
generic
Bugzilla submission:
NotANumberTest: Double.NaN isn't handled gracefully when stroking shapes.
-------------NotANumberTest.java------------------
import java.awt.*;
import java.awt.geom.Path2D;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
/**
* @author ###@###.### (Chris Nokleberg)
* @author ###@###.### (Hiroshi Yamauchi)
*/
public class NotANumberTest {
public static void main(String[] args) throws Exception {
BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setPaint(Color.WHITE);
g.fill(new Rectangle(image.getWidth(), image.getHeight()));
Path2D path = new Path2D.Double();
path.moveTo(25.0, 25.0);
path.lineTo(175.0, 25.0);
path.lineTo(175.0, 175.0);
path.lineTo(Double.NaN, Double.NaN);
path.lineTo(25.0, 175.0);
path.lineTo(25.0, 25.0);
g.setPaint(Color.BLUE);
g.fill(path);
// To visually check it
//ImageIO.write(image, "PNG", new File(args[0]));
boolean nonWhitePixelFound = false;
for (int y = 125; y < 200; ++y) {
if (image.getRGB(100, y) != Color.WHITE.getRGB()) {
nonWhitePixelFound = true;
break;
}
}
if (!nonWhitePixelFound) {
throw new RuntimeException("NaN isn't gracefully handled by Path2D.");
}
}
}
NotANumberTest: Double.NaN isn't handled gracefully when stroking shapes.
-------------NotANumberTest.java------------------
import java.awt.*;
import java.awt.geom.Path2D;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
/**
* @author ###@###.### (Chris Nokleberg)
* @author ###@###.### (Hiroshi Yamauchi)
*/
public class NotANumberTest {
public static void main(String[] args) throws Exception {
BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setPaint(Color.WHITE);
g.fill(new Rectangle(image.getWidth(), image.getHeight()));
Path2D path = new Path2D.Double();
path.moveTo(25.0, 25.0);
path.lineTo(175.0, 25.0);
path.lineTo(175.0, 175.0);
path.lineTo(Double.NaN, Double.NaN);
path.lineTo(25.0, 175.0);
path.lineTo(25.0, 25.0);
g.setPaint(Color.BLUE);
g.fill(path);
// To visually check it
//ImageIO.write(image, "PNG", new File(args[0]));
boolean nonWhitePixelFound = false;
for (int y = 125; y < 200; ++y) {
if (image.getRGB(100, y) != Color.WHITE.getRGB()) {
nonWhitePixelFound = true;
break;
}
}
if (!nonWhitePixelFound) {
throw new RuntimeException("NaN isn't gracefully handled by Path2D.");
}
}
}