Package com.bric.multislider
Class ShapeBounds
java.lang.Object
com.bric.multislider.ShapeBounds
This class features an efficient and accurate
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.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Rectangle2DThis calculates the precise bounds of a shape.static Rectangle2DgetBounds(PathIterator i, Rectangle2D r) This calculates the precise bounds of a shape.static Rectangle2DThis calculates the precise bounds of a shape.static Rectangle2Dstatic Rectangle2DgetBounds(Shape shape, AffineTransform transform) This calculates the precise bounds of a shape.static Rectangle2DgetBounds(Shape shape, AffineTransform transform, Rectangle2D r) This calculates the precise bounds of a shape.static Rectangle2DgetBounds(Shape shape, Rectangle2D r) This calculates the precise bounds of a shape.
-
Constructor Details
-
ShapeBounds
public ShapeBounds()
-
-
Method Details
-
getBounds
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
-
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 ofshapeas 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 ofshapeas 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
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
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
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.
-