com.levigo.util.swing
Class Rectangles

java.lang.Object
  extended by com.levigo.util.swing.Rectangles

public class Rectangles
extends Object

A few utility methods related to Rectangles, Rectangle2Ds and RectangularShapes.


Method Summary
static double area(Rectangle2D r)
           
static Rectangle2D dilate(Rectangle2D r, double marginX, double marginY)
          Return a new rectangle which covers the area of the given rectangle with an additional margin on the sides.
static Rectangle dilate(Rectangle r, int marginX, int marginY)
          Return a new rectangle which covers the area of the given rectangle with an additional margin on the sides.
static double distance(Rectangle2D r, Point2D p)
          Calculate the shortest distance from the point to any point within the given rectangle.
static Rectangle enlargeToGrid(Rectangle2D r)
          Create a rectangle with the same area as the given input rectangle but with all of its edges snapped (rounded) to the integer grid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

enlargeToGrid

public static Rectangle enlargeToGrid(Rectangle2D r)
Create a rectangle with the same area as the given input rectangle but with all of its edges snapped (rounded) to the integer grid. The resulting rectangle is guaranteed to cover all of the input rectangle's area, so that enlargeToGrid(r).contains(r) == true holds. This can be depicted as the edges being stretched in an outward direction.

Parameters:
r -
Returns:

distance

public static double distance(Rectangle2D r,
                              Point2D p)
Calculate the shortest distance from the point to any point within the given rectangle. For points within the rectangle the result is always zero.

Parameters:
r - the rectangle
p - the point
Returns:
the shortest distance

dilate

public static Rectangle dilate(Rectangle r,
                               int marginX,
                               int marginY)
Return a new rectangle which covers the area of the given rectangle with an additional margin on the sides.

Parameters:
r -
marginX -

dilate

public static Rectangle2D dilate(Rectangle2D r,
                                 double marginX,
                                 double marginY)
Return a new rectangle which covers the area of the given rectangle with an additional margin on the sides.

Parameters:
r -
marginX -

area

public static double area(Rectangle2D r)


Copyright © 1995-2020 levigo holding gmbh. All Rights Reserved.