Class ShapeBounds

java.lang.Object
com.bric.multislider.ShapeBounds

public class ShapeBounds extends Object
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 Details

    • ShapeBounds

      public ShapeBounds()
  • Method Details

    • 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 of shape as seen through t.
      Returns:
      the bounds of shape, as seen through transform.
      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 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.
      Returns:
      the bounds of shape, as seen through transform.
      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.