import java.awt.*;
import java.awt.geom.Path2D;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;

/**
 * @author chrisn@google.com (Chris Nokleberg)
 * @author yamauchi@google.com (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.");
    }
  }
}
