It will return:
false
java.awt.geom.Rectangle2D$Double[x=10.0,y=10.0,w=0.0,h=20.0]
With this code:
Line2D.Double line2d = new Line2D.Double(10, 10, 10, 30);
Rectangle2D.Double rect2d = new Rectangle2D.Double(0, 0, 100, 100);
boolean intersect = line2d.getBounds2D().intersects(rect2d);
System.out.println(intersect);
System.out.println(line2d.getBounds2D());
Although, it's useless to say that a line is 1 pixel, because it can't be other way using Line2D.Double
.
Indeed, for Java, this vertical line as a 0-pixel width boundary, so that's why it will never intersect with any other shape. With a non-vertical and non-horizontal line, its bounds intersect.
Do not use bounds to compute intersection, but directly the Shape:
boolean intersect = line2d.intersects(rect2d);
You may check RectangularShape.intersects() Javadoc for more information on how this method computes intersection.