Arc2D.getBounds() and Arc2D.getBounds2D() should be similar in meaning

XMLWordPrintable

    • Type: CSR
    • Resolution: Unresolved
    • Priority: P4
    • None
    • Component/s: client-libs
    • None
    • 2d
    • low
    • Preexisting code might expect Arc2D#getBounds() to return the previous (larger) rectangle.

      Summary

      We should implement Arc2D#getBounds() so it returns a more concise bounding box, and simplify method documentation for Arc2D#getBounds2D().

      Problem

      The Shape interface includes getBounds() and getBounds2D(). In most implementations these are extremely similar, but in the Arc2D class they currently have different meanings.

      Arc2D#getBounds2D() is defined in Arc2D.java. This returns a high-precision Rectangle2D that concisely encloses the shape's PathIterator. Its documentation includes a sentence explaining that it is different than Arc2D#getBounds().

      Arc2D#getBounds() is not defined in Arc2D.java. Instead it is currently inherited through RectangularShape. It returns a Rectangle that encloses the ellipse that the arc is a subset of.

      These methods should only vary in the precision of the rectangle they return -- they should not vary in meaning.

      In practical terms this problem manifests as follows. If createShape() returns an Arc2D, then r1 may be significantly different than the other rectangles:

      Shape s = createShape();
      Rectangle r1 = s.getBounds();
      Rectangle2D r2 = s.getBounds2D();
      Rectangle r3 = bounds2D.getBounds();
      

      (A significant part of the confusion here is probably that Arc2D extends RectangularShape. I'd argue Arc2D should have a "has-a" relationship with a rectangular frame, but it does not have a "is-a" relationship with its rectangular frame. In our current state we have to decide if methods relate to the arc itself, or to its rectangular frame.)

      Solution

      My argument is that one of these methods (getBounds vs getBounds2D()) needs to change to align with the other.

      I recommend implementing Arc2D#getBounds() so it simply returns getBounds2D().getBounds() . This is basically how Area, CubicCurve2D, Line2D, Path2D, and QuadCurve2D are implemented.

      Alternatively: we could change Arc2D#getBounds2D() so it aligns with Arc2D#getBounds().

      Specification

      I recommend 2 changes.

      1. Adding this to Arc2D:

        /**

        • {@inheritDoc}
        • @since 1.2 */ @Override public Rectangle getBounds() { return getBounds2D().getBounds(); }
      2. And simplifying Arc2D#getBounds2D documentation to simply say:

        /**

        • {@inheritDoc}
        • @since 1.2 */

      In my opinion we no longer need a qualifying explanation for either method now.

            Assignee:
            Jeremy Wood
            Reporter:
            Jim Graham
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated: