public class Rectangles extends Object
Modifier and Type | Method and Description |
---|---|
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.
|
static Rectangle2D.Double |
ensureDoublePrecision(Rectangle2D input)
Converts the given
Rectangle2D to double precision, if necessary. |
static Rectangle2D |
intersectNullSafe(Rectangle2D a,
Rectangle2D b)
Computes the intersection of two rectangles, considering that one or both of them might be
null . |
static Rectangle2D |
normalize(Rectangle2D r)
Returns a rectangle which is normalized, that is, it has positive values for width and height.
|
static Rectangle2D |
unionNullSafe(Rectangle2D a,
Rectangle2D b)
Computes the union area of two rectangles, considering that one or both of them might be
null . |
public static Rectangle enlargeToGrid(Rectangle2D r)
enlargeToGrid(r).contains(r) == true
holds. This can be depicted as the edges
being stretched in an outward direction.r
- public static double distance(Rectangle2D r, Point2D p)
r
- the rectanglep
- the pointpublic static Rectangle dilate(Rectangle r, int marginX, int marginY)
r
- marginX
- public static Rectangle2D dilate(Rectangle2D r, double marginX, double marginY)
r
- marginX
- public static double area(Rectangle2D r)
public static Rectangle2D normalize(Rectangle2D r)
r
- the rectangle to be normalized. The given instance will not be modified.public static Rectangle2D unionNullSafe(Rectangle2D a, Rectangle2D b)
null
. This method automatically chooses the best subtype of Rectangle2D
.
For example, passing two Rectangle
s will return a Rectangle
.a
- first rectangleb
- second rectanglenull
. If only one of them is
non-null
, it will be returned unchanged. If both are null
,
null
will be returned.public static Rectangle2D intersectNullSafe(Rectangle2D a, Rectangle2D b)
null
. This method automatically chooses the best subtype of Rectangle2D
.
For example, passing two Rectangle
s will return a Rectangle
.a
- first rectangleb
- second rectanglenull
. If only one of
them is non-null
, it will be returned unchanged. If both are
null
, null
will be returned.public static Rectangle2D.Double ensureDoublePrecision(Rectangle2D input)
Rectangle2D
to double precision, if necessary.input
- any rectangle, or null
Rectangle2D.Double
, it will be returned unchanged. If input is
null
, null
will be returned. In all other cases, a new
Rectangle2D.Double
will be created using input's size and position.Copyright © 2024 levigo holding gmbh. All rights reserved.