public class ShapeBounds extends Object
getBounds() method. The
java.awt.Shape API clearly states that the
Shape.getBounds2D() method may return a rectangle larger than the bounds of the actual shape, so here I present a method to get the bounds without resorting to the very-accurate-but-very-slow
java.awt.geom.Area class.
com.bric.geom.ShapeBoundsDemo
| Constructor and Description |
|---|
ShapeBounds()
|
| Modifier and Type | Method and Description |
|---|---|
static Rectangle2D |
getBounds(PathIterator
This calculates the precise bounds of a shape.
|
static Rectangle2D |
getBounds(PathIterator
This calculates the precise bounds of a shape.
|
static Rectangle2D |
getBounds(Shape
This calculates the precise bounds of a shape.
|
static Rectangle2D |
getBounds(Shape
|
static Rectangle2D |
getBounds(Shape
This calculates the precise bounds of a shape.
|
static Rectangle2D |
getBounds(Shape
This calculates the precise bounds of a shape.
|
static Rectangle2D |
getBounds(Shape
This calculates the precise bounds of a shape.
|
public static Rectangle2DgetBounds(Shape shape) throws EmptyPathException
shape - the shape you want the bounds of. This method throws a NullPointerException if this is null.
shape.
EmptyPathException - if the shape argument is empty.
public static Rectangle2DgetBounds(Shape [] shapes)
public static Rectangle2DgetBounds(Shape shape, AffineTransform transform) throws EmptyPathException
shape - the shape you want the bounds of. This method throws a NullPointerException if this is null.
transform - if this is non-null, then this method returns the bounds of
shape as seen through
t.
shape, as seen through
transform.
EmptyPathException - if the shape argument is empty.
public static Rectangle2DgetBounds(Shape shape, AffineTransform transform, Rectangle2D r) throws EmptyPathException
shape - the shape you want the bounds of. This method throws a NullPointerException if this is null.
transform - if this is non-null, then this method returns the bounds of
shape as seen through
t.
r - if this is non-null, then the result is stored in this rectangle. This is useful when you need to call this method repeatedly without allocating a lot of memory.
shape, as seen through
transform.
EmptyPathException - if the shape argument is empty.
public static Rectangle2DgetBounds(Shape shape, Rectangle2D r) throws EmptyPathException
shape - the shape you want the bounds of. This method throws a NullPointerException if this is null.
r - if this is non-null, then the result is stored in this rectangle. This is useful when you need to call this method repeatedly without allocating a lot of memory.
shape.
EmptyPathException - if the shape argument is empty.
public static Rectangle2DgetBounds(PathIterator i)
i - the shape you want the bounds of. This method throws a NullPointerException if this is null.
i.
public static Rectangle2DgetBounds(PathIterator i, Rectangle2D r)
i - the shape you want the bounds of. This method throws a NullPointerException if this is null.
r - if this is non-null, then the result is stored in this rectangle. This is useful when you need to call this method repeatedly without allocating a lot of memory.
i.