Package com.bric.multislider
Class ShapeBounds
- java.lang.Object
-
- com.bric.multislider.ShapeBounds
-
public class ShapeBounds extends Object
This class features an efficient and accurategetBounds()
method. Thejava.awt.Shape
API clearly states that theShape.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-slowjava.awt.geom.Area
class.
-
-
Constructor Summary
Constructors Constructor Description ShapeBounds()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Rectangle2D
getBounds(PathIterator i)
This calculates the precise bounds of a shape.static Rectangle2D
getBounds(PathIterator i, Rectangle2D r)
This calculates the precise bounds of a shape.static Rectangle2D
getBounds(Shape shape)
This calculates the precise bounds of a shape.static Rectangle2D
getBounds(Shape[] shapes)
static Rectangle2D
getBounds(Shape shape, AffineTransform transform)
This calculates the precise bounds of a shape.static Rectangle2D
getBounds(Shape shape, AffineTransform transform, Rectangle2D r)
This calculates the precise bounds of a shape.static Rectangle2D
getBounds(Shape shape, Rectangle2D r)
This calculates the precise bounds of a shape.
-
-
-
Method Detail
-
getBounds
public static Rectangle2D getBounds(Shape shape) throws EmptyPathException
This calculates the precise bounds of a shape.- Parameters:
shape
- the shape you want the bounds of. This method throws a NullPointerException if this is null.- Returns:
- the bounds of
shape
. - Throws:
EmptyPathException
- if the shape argument is empty.
-
getBounds
public static Rectangle2D getBounds(Shape[] shapes)
-
getBounds
public static Rectangle2D getBounds(Shape shape, AffineTransform transform) throws EmptyPathException
This calculates the precise bounds of a shape.- Parameters:
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 ofshape
as seen throught
.- Returns:
- the bounds of
shape
, as seen throughtransform
. - Throws:
EmptyPathException
- if the shape argument is empty.
-
getBounds
public static Rectangle2D getBounds(Shape shape, AffineTransform transform, Rectangle2D r) throws EmptyPathException
This calculates the precise bounds of a shape.- Parameters:
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 ofshape
as seen throught
.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.- Returns:
- the bounds of
shape
, as seen throughtransform
. - Throws:
EmptyPathException
- if the shape argument is empty.
-
getBounds
public static Rectangle2D getBounds(Shape shape, Rectangle2D r) throws EmptyPathException
This calculates the precise bounds of a shape.- Parameters:
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.- Returns:
- the bounds of
shape
. - Throws:
EmptyPathException
- if the shape argument is empty.
-
getBounds
public static Rectangle2D getBounds(PathIterator i)
This calculates the precise bounds of a shape.- Parameters:
i
- the shape you want the bounds of. This method throws a NullPointerException if this is null.- Returns:
- the bounds of
i
.
-
getBounds
public static Rectangle2D getBounds(PathIterator i, Rectangle2D r)
This calculates the precise bounds of a shape.- Parameters:
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.- Returns:
- the bounds of
i
.
-
-