Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7003516

Methods java.awt.geom.Line2D.Double/Float.getBounds2D() don't satisfy inherited spec

    Details

    • Subcomponent:
      2d
    • Resolved In Build:
      b138
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      The following method of the class Shape is implemented by Line2D.Float and Line2D.Double.
      The spec is inherited however the assertion quoted below is not always satisfied for a line.

          /**
           * ...
           * Note that there is no guarantee that the returned
           * {@link Rectangle2D} is the smallest bounding box that encloses
           * the <code>Shape</code>, only that the <code>Shape</code> lies
           * entirely within the indicated <code>Rectangle2D</code>.
           * ...
           */
          public Rectangle2D getBounds2D();



      Please see the following code sample for Line2D.Double, extracted from more complicated testcase with particular values (Line2D.Float has the same problems):


      import java.awt.geom.Line2D;

      public class GetBounds2D {
          public static void main(String[] args) {

              Line2D.Double vertLine = new Line2D.Double(0.0, 0.0, 0.0, 1.0);
              System.out.println(vertLine.getBounds2D().contains(0.0, 0.0));
              System.out.println(vertLine.getBounds2D().contains(0.0, 1.0));

              Line2D.Double horLine = new Line2D.Double(0.0, 0.0, 1.0, 0.0);
              System.out.println(horLine.getBounds2D().contains(0.0, 0.0));
              System.out.println(horLine.getBounds2D().contains(0.0, 1.0));

              // start point
              Line2D.Double line1 = new Line2D.Double(12345.4352, 12345.4352,
                      -0.56, -1.34);
              System.out.println(line1.getBounds2D().contains(12345.4352, 12345.4352));

              // end point
              Line2D.Double line2 = new Line2D.Double(12345.4352, 0.0, -0.56, 1.234);
              System.out.println(line2.getBounds2D().contains(-0.56, 1.234));

          }

      }

      The output will be

      false
      false
      false
      false
      false
      false

        Attachments

          Activity

            People

            • Assignee:
              bae Andrew Brygin
              Reporter:
              dbessono Dmitry Bessonov
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: