-
Type:
CSR
-
Resolution: Unresolved
-
Priority:
P4
-
Component/s: client-libs
-
None
-
behavioral
-
low
-
Preexisting code might expect Arc2D#getBounds() to return the previous (larger) rectangle.
-
Java API
-
SE
Summary
Arc2D#getBounds() now returns a more concise bounding box, and the method documentation for Arc2D#getBounds2D() is simplified.
Problem
The Shape interface includes getBounds() and getBounds2D(). In most Shape implementations these are extremely similar, but in the Arc2D class they currently have different meanings. Contributing to this problem is that Arc2D extends RectangularShape.
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();
Solution
Implement Arc2D#getBounds() so it simply returns getBounds2D().getBounds() .
This is consistent with how Area, CubicCurve2D, Line2D, Path2D, and QuadCurve2D are implemented.
Specification
Update the specification of java/awt/geom/Arc2D as follows
/**
- * Returns the high-precision framing rectangle of the arc. The framing
- * rectangle contains only the part of this {@code Arc2D} that is
- * in between the starting and ending angles and contains the pie
- * wedge, if this {@code Arc2D} has a {@code PIE} closure type.
- * <p>
- * This method differs from the
- * {@link RectangularShape#getBounds() getBounds} in that the
- * {@code getBounds} method only returns the bounds of the
- * enclosing ellipse of this {@code Arc2D} without considering
- * the starting and ending angles of this {@code Arc2D}.
- *
- * @return the {@code Rectangle2D} that represents the arc's
- * framing rectangle.
+ * {@inheritDoc}
* @since 1.2
*/
public Rectangle2D getBounds2D()
+ /**
+ * {@inheritDoc java.awt.Shape}
+ * @since 1.2
+ */
+ @Override
+ public Rectangle getBounds();
- csr of
-
JDK-4197755 Arc2D.getBounds() returns an unnecessarily large bounding box
-
- Open
-