Top Description Constructors Methods
impl.org.controlsfx.tools.rectangle

public Class Rectangles2D

extends Object
Class Inheritance
Imports
impl.org.controlsfx.tools.MathTools, java.util.Objects, javafx.geometry.Bounds, .Orientation, .Point2D, .Rectangle2D

Usability methods for rectangles.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

true if both end points of the edge are contained in the rectangle
contains
(Rectangle2D
the rectangle to check
rectangle
,
Edge2D
the edge to check
edge
)

Indicates whether the specified rectangle contains the specified edge.

private static double

Returns:

the corrected difference
correctCoordinateDifferenceByRatio
(double
the difference to check
difference
,
double
the other difference
otherDifference
,
double
the ratio as a multiplier for the other difference
ratioAsMultiplier
)

Returns the difference with the following properties: - it has the same sign as the specified difference - its absolute value is the minimum of the absolute values of ...

private static Rectangle2D

Returns:

a new Rectangle2D with the specified centerPoint and ratio; it has the specified area unless this would violate the bounds; in this case it is as large as possible while still staying within the bounds
createForCenterAreaAndRatioWithinBounds
(Point2D
the new rectangle's center point
centerPoint
,
double
the new rectangle's area (if possible without violating the bounds)
area
,
double
the new ratio
ratio
,
Rectangle2D
the bounds within which the new rectangle will be located
bounds
)

Creates a new rectangle with the specified centerPoint, area (if possible) and ratio, respecting the specified bounds (if not-null).

private static Rectangle2D

Returns:

a rectangle
createForEdgeAndOtherDimension
(Edge2D
the edge which will be contained in the returned rectangle
edge
,
double
if the edge's orientation is horizontal, this is interpreted as the height; if the edge's orientation is vertical, this is interpreted as the width
otherDimension
)

Returns a rectangle that has the specified edge and a height or width (depending on the edge's orientation) as specified by otherDimension.

private static Rectangle2D

Returns:

a rectangle
createForHorizontalEdgeAndHeight
(Edge2D
the horizontal edge which will be contained in the returned rectangle
horizontalEdge
,
double
the returned rectangle's height
height
)

Returns a rectangle that has the specified horizontal edge and height.

private static Rectangle2D

Returns:

a rectangle
createForVerticalEdgeAndWidth
(Edge2D
the vertical edge which will be contained in the returned rectangle
verticalEdge
,
double
the returned rectangle's height
width
)

Returns a rectangle that has the specified horizontal edge and width.

private static Rectangle2D

Returns:

a new Rectangle2D with the same center point as the original and the specified ratio; it has the same area as the original unless this would violate the bounds; in this case it is as large as possible while still staying within the bounds
createWithFixedRatioWithinBounds
(Rectangle2D
the original rectangle
original
,
double
the new ratio
ratio
,
Rectangle2D
the bounds within which the new rectangle will be located; might be null
bounds
)

Creates a new rectangle with the same center point and area as the specified original rectangle with the specified ratio and respecting the specified bounds (if not-null).

public static Rectangle2D

Returns:

a new Rectangle2D with the same center point as the original and the specified ratio; it has the same area as the original
fixRatio
(Rectangle2D
the original rectangle
original
,
double
the new ratio
ratio
)

Creates a new rectangle with the same center point and area as the specified original rectangle with the specified ratio.

public static Rectangle2D

Returns:

a new Rectangle2D with the same center point as the original and the specified ratio; it has the same area as the original unless this would violate the bounds; in this case it is as large as possible while still staying within the bounds
fixRatioWithinBounds
(Rectangle2D
the original rectangle
original
,
double
the new ratio
ratio
,
Rectangle2D
the bounds within which the new rectangle will be located
bounds
)

Creates a new rectangle with the same center point and area (if possible) as the specified original rectangle with the specified ratio and respecting the specified bounds.

public static Rectangle2D

Returns:

a new Rectangle2D with the specified centerPoint, area and ratio
forCenterAndAreaAndRatio
(Point2D
the new rectangle's center point
centerPoint
,
double
the new rectangle's area
area
,
double
the new ratio
ratio
)

Creates a new rectangle with the specified centerPoint, area and ratio.

public static Rectangle2D

Returns:

a new Rectangle2D with the specified centerPoint and ratio; it has the specified area unless this would violate the bounds; in this case it is as large as possible while still staying within the bounds
forCenterAndAreaAndRatioWithinBounds
(Point2D
the new rectangle's center point
centerPoint
,
double
the new rectangle's area (if possible without violating the bounds)
area
,
double
the new ratio
ratio
,
Rectangle2D
the bounds within which the new rectangle will be located
bounds
)

Creates a new rectangle with the specified centerPoint, area (if possible) and ratio, respecting the specified bounds.

public static Rectangle2D

Returns:

a rectangle with the specified center and size
forCenterAndSize
(Point2D
the center point o the new rectangle
centerPoint
,
double
the width of the new rectangle
width
,
double
the height of the new rectangle
height
)

Creates a new rectangle with the specified center and the specified width and height.

public static Rectangle2D

Returns:

the Rectangle2D which is defined by the two corners
forDiagonalCorners
(Point2D
one corner
oneCorner
,
Point2D
another corner, diagonal from the first
diagonalCorner
)

Creates a new rectangle with the two specified corners.

public static Rectangle2D

Returns:

the Rectangle2D which is defined by the fixedCorner, the x- or y-parallel of the diagonalCorner and the ratio
forDiagonalCornersAndRatio
(Point2D
one corner
fixedCorner
,
Point2D
another corner, diagonal from the first
diagonalCorner
,
double
the ratio the returned rectangle must have; must be non-negative
ratio
)

Creates a new rectangle with the two specified corners.

public static Rectangle2D

Returns:

a rectangle
forEdgeAndOpposingPoint
(Edge2D
the edge which will be contained in the returned rectangle
edge
,
Point2D
the point whose X or Y coordinate defines the other edge
point
)

Returns a rectangle that has the specified edge and has its opposing edge on the parallel axis defined by the specified point's X or Y coordinate (depending on the edge's orientation).

public static Rectangle2D

Returns:

a rectangle
forEdgeAndOpposingPointAndRatioWithinBounds
(Edge2D
the edge which defines the center point and orientation of one of the rectangle's edges; must be within the specified bounds
edge
,
Point2D
the point to which the rectangle spans if ratio and bounds allow it
point
,
double
the ratio the new rectangle must have
ratio
,
Rectangle2D
the bounds within which the new rectangle must lie
bounds
)

Returns a rectangle that is principally defined by the specified edge and point.

public static Rectangle2D

Returns:

the Rectangle2D which is defined by the specified upper left corner and width and height
forUpperLeftCornerAndSize
(Point2D
one corner
upperLeft
,
double
the new rectangle's width
width
,
double
the new rectangle's height
height
)

Creates a new rectangle with the specified upperLeft corner and the specified width and height.

public static Rectangle2D

Returns:

a Rectangle2D with the same minX-, minY-, maxX- and maxY-coordiantes as the specified bounds
fromBounds
(Bounds
the Bounds for which the rectangle will be created
bounds
)

Returns a rectangle with the same coordinates as the specified bounds.

public static Point2D

Returns:

the Point2D whose x/y coordinates lie at (min + max) / 2.
getCenterPoint
(Rectangle2D
the Rectangle2D whose center point will be returned
rectangle
)

Returns the center of the specified rectangle as a point.

private static double

Returns:

fixedCoordinate + difference; if difference < 0
fixedCoordinate; else
getMinCoordinate
(double
the coordinate which must be a corner
fixedCoordinate
,
double
the difference in the computed coordinate
difference
)

Returns the minimum coordinate such that a rectangle starting from that coordinate will contain the fixed coordinate as a corner.

public static Point2D

Returns:

either the specified point or the Point2D which is closest to it while still being contained on the rectangle
inRectangle
(Rectangle2D
the Rectangle2D into which the point should be moved
rectangle
,
Point2D
the Point2D which is checked
point
)

Moves the specified point into the specified rectangle.

public static Rectangle2D

Returns:

a Rectangle2D which is the intersection of a and b; possible Rectangle2D#EMPTY.
intersection
(Rectangle2D a, Rectangle2D
another Rectangle2D
b
)

Returns the rectangle which represents the intersection of the two specified rectangles.

private static double

Returns:

the factor with which the width and height must be multiplied to stay within the bounds; always in the closed interval [0; 1]
lengthReductionToStayWithinBounds
(Point2D
the center point of the new rectangle
centerPoint
,
double
the original width which might be too large
width
,
double
the original height which might be too large
height
,
Rectangle2D
the bounds within which the new rectangle will be located
bounds
)

Computes the factor by which the specified width and height must be multiplied to keep a rectangle with their ratio and the specified center point within the specified bounds.

private static Point2D

Returns:

either point or a new Point2D whose coordinates were changed so that it lies within the bounds
movePointIntoBounds
(Point2D
the point to move into the bounds
point
,
Rectangle2D
the bounds into which the point will be moved
bounds
)

Returns either the specified point if if the specified bounds contain it or a point whose X and/or Y coordinates are moved into the bounds.

private static Edge2D

Returns:

either the specified edge if it is with in the bounds or one with a corrected length
resizeEdgeForBounds
(Edge2D
the edge whose center point and orientation defines the returned edge's center point and orientation; the center point must be within the bounds or an IllegalArgumentException will be thrown
edge
,
Rectangle2D
the bounds within which the returned edge must be contained
bounds
)

Returns an edge with the same center point and orientation as the specified edge.

private static Edge2D

Returns:

an Edge2D
resizeEdgeForDistanceAndRatio
(Edge2D
the edge whose center point and orientation defines the returned edge's center point and orientation
edge
,
Point2D
the point to which the distance is measured
point
,
double
the ratio between the distance to the point and the returned edge's length
ratio
)

Returns an edge with the same center point and orientation as the specified edge.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Rectangles2Dback to summary
public Rectangles2D()

Method Detail

containsback to summary
public static boolean contains(Rectangle2D rectangle, Edge2D edge)

Indicates whether the specified rectangle contains the specified edge.

Parameters
rectangle:Rectangle2D

the rectangle to check

edge:Edge2D

the edge to check

Returns:boolean

true if both end points of the edge are contained in the rectangle

correctCoordinateDifferenceByRatioback to summary
private static double correctCoordinateDifferenceByRatio(double difference, double otherDifference, double ratioAsMultiplier)

Returns the difference with the following properties:
- it has the same sign as the specified difference
- its absolute value is the minimum of the absolute values of ...
... the specified difference and
... the product of the specified ratio and the other specified difference

Parameters
difference:double

the difference to check

otherDifference:double

the other difference

ratioAsMultiplier:double

the ratio as a multiplier for the other difference

Returns:double

the corrected difference

createForCenterAreaAndRatioWithinBoundsback to summary
private static Rectangle2D createForCenterAreaAndRatioWithinBounds(Point2D centerPoint, double area, double ratio, Rectangle2D bounds)

Creates a new rectangle with the specified centerPoint, area (if possible) and ratio, respecting the specified bounds (if not-null).

Parameters
centerPoint:Point2D

the new rectangle's center point

area:double

the new rectangle's area (if possible without violating the bounds)

ratio:double

the new ratio

bounds:Rectangle2D

the bounds within which the new rectangle will be located

Returns:Rectangle2D

a new Rectangle2D with the specified centerPoint and ratio; it has the specified area unless this would violate the bounds; in this case it is as large as possible while still staying within the bounds

Exceptions
IllegalArgumentException:
if the centerPoint is out of the bounds
createForEdgeAndOtherDimensionback to summary
private static Rectangle2D createForEdgeAndOtherDimension(Edge2D edge, double otherDimension)

Returns a rectangle that has the specified edge and a height or width (depending on the edge's orientation) as specified by otherDimension.

Parameters
edge:Edge2D

the edge which will be contained in the returned rectangle

otherDimension:double

if the edge's orientation is horizontal, this is interpreted as the height; if the edge's orientation is vertical, this is interpreted as the width

Returns:Rectangle2D

a rectangle

createForHorizontalEdgeAndHeightback to summary
private static Rectangle2D createForHorizontalEdgeAndHeight(Edge2D horizontalEdge, double height)

Returns a rectangle that has the specified horizontal edge and height. Depending on whether the width is positive or negative, the specified edge will be the upper or lower edge of the returned rectangle.

Parameters
horizontalEdge:Edge2D

the horizontal edge which will be contained in the returned rectangle

height:double

the returned rectangle's height

Returns:Rectangle2D

a rectangle

createForVerticalEdgeAndWidthback to summary
private static Rectangle2D createForVerticalEdgeAndWidth(Edge2D verticalEdge, double width)

Returns a rectangle that has the specified horizontal edge and width. Depending on whether the width is positive or negative, the specified edge will be the left or right edge of the returned rectangle.

Parameters
verticalEdge:Edge2D

the vertical edge which will be contained in the returned rectangle

width:double

the returned rectangle's height

Returns:Rectangle2D

a rectangle

createWithFixedRatioWithinBoundsback to summary
private static Rectangle2D createWithFixedRatioWithinBounds(Rectangle2D original, double ratio, Rectangle2D bounds)

Creates a new rectangle with the same center point and area as the specified original rectangle with the specified ratio and respecting the specified bounds (if not-null).

Parameters
original:Rectangle2D

the original rectangle

ratio:double

the new ratio

bounds:Rectangle2D

the bounds within which the new rectangle will be located; might be null

Returns:Rectangle2D

a new Rectangle2D with the same center point as the original and the specified ratio; it has the same area as the original unless this would violate the bounds; in this case it is as large as possible while still staying within the bounds

Exceptions
IllegalArgumentException:
if the original rectangle's center point is out of the bounds
fixRatioback to summary
public static Rectangle2D fixRatio(Rectangle2D original, double ratio)

Creates a new rectangle with the same center point and area as the specified original rectangle with the specified ratio.

Parameters
original:Rectangle2D

the original rectangle

ratio:double

the new ratio

Returns:Rectangle2D

a new Rectangle2D with the same center point as the original and the specified ratio; it has the same area as the original

Exceptions
NullPointerException:
if the original rectangle is null
fixRatioWithinBoundsback to summary
public static Rectangle2D fixRatioWithinBounds(Rectangle2D original, double ratio, Rectangle2D bounds)

Creates a new rectangle with the same center point and area (if possible) as the specified original rectangle with the specified ratio and respecting the specified bounds.

Parameters
original:Rectangle2D

the original rectangle

ratio:double

the new ratio

bounds:Rectangle2D

the bounds within which the new rectangle will be located

Returns:Rectangle2D

a new Rectangle2D with the same center point as the original and the specified ratio; it has the same area as the original unless this would violate the bounds; in this case it is as large as possible while still staying within the bounds

Exceptions
NullPointerException:
if the original or bounds rectangle is null
IllegalArgumentException:
if the original rectangle's center point is out of the bounds
forCenterAndAreaAndRatioback to summary
public static Rectangle2D forCenterAndAreaAndRatio(Point2D centerPoint, double area, double ratio)

Creates a new rectangle with the specified centerPoint, area and ratio.

Parameters
centerPoint:Point2D

the new rectangle's center point

area:double

the new rectangle's area

ratio:double

the new ratio

Returns:Rectangle2D

a new Rectangle2D with the specified centerPoint, area and ratio

Exceptions
IllegalArgumentException:
if the centerPoint is out of the bounds
forCenterAndAreaAndRatioWithinBoundsback to summary
public static Rectangle2D forCenterAndAreaAndRatioWithinBounds(Point2D centerPoint, double area, double ratio, Rectangle2D bounds)

Creates a new rectangle with the specified centerPoint, area (if possible) and ratio, respecting the specified bounds.

Parameters
centerPoint:Point2D

the new rectangle's center point

area:double

the new rectangle's area (if possible without violating the bounds)

ratio:double

the new ratio

bounds:Rectangle2D

the bounds within which the new rectangle will be located

Returns:Rectangle2D

a new Rectangle2D with the specified centerPoint and ratio; it has the specified area unless this would violate the bounds; in this case it is as large as possible while still staying within the bounds

Exceptions
IllegalArgumentException:
if the centerPoint is out of the bounds
forCenterAndSizeback to summary
public static Rectangle2D forCenterAndSize(Point2D centerPoint, double width, double height)

Creates a new rectangle with the specified center and the specified width and height.

Parameters
centerPoint:Point2D

the center point o the new rectangle

width:double

the width of the new rectangle

height:double

the height of the new rectangle

Returns:Rectangle2D

a rectangle with the specified center and size

forDiagonalCornersback to summary
public static Rectangle2D forDiagonalCorners(Point2D oneCorner, Point2D diagonalCorner)

Creates a new rectangle with the two specified corners. The two corners will be interpreted as being diagonal of each other.

Parameters
oneCorner:Point2D

one corner

diagonalCorner:Point2D

another corner, diagonal from the first

Returns:Rectangle2D

the Rectangle2D which is defined by the two corners

forDiagonalCornersAndRatioback to summary
public static Rectangle2D forDiagonalCornersAndRatio(Point2D fixedCorner, Point2D diagonalCorner, double ratio)

Creates a new rectangle with the two specified corners. The two corners will be interpreted as being diagonal of each other. The returned rectangle will have the specified fixedCorner as its corner. The other one will either be on the same x- or y-parallel as the diagonalCorner but will be such that the rectangle has the specified ratio.

Parameters
fixedCorner:Point2D

one corner

diagonalCorner:Point2D

another corner, diagonal from the first

ratio:double

the ratio the returned rectangle must have; must be non-negative

Returns:Rectangle2D

the Rectangle2D which is defined by the fixedCorner, the x- or y-parallel of the diagonalCorner and the ratio

forEdgeAndOpposingPointback to summary
public static Rectangle2D forEdgeAndOpposingPoint(Edge2D edge, Point2D point)

Returns a rectangle that has the specified edge and has its opposing edge on the parallel axis defined by the specified point's X or Y coordinate (depending on the edge's orientation).

Parameters
edge:Edge2D

the edge which will be contained in the returned rectangle

point:Point2D

the point whose X or Y coordinate defines the other edge

Returns:Rectangle2D

a rectangle

forEdgeAndOpposingPointAndRatioWithinBoundsback to summary
public static Rectangle2D forEdgeAndOpposingPointAndRatioWithinBounds(Edge2D edge, Point2D point, double ratio, Rectangle2D bounds)

Returns a rectangle that is principally defined by the specified edge and point. It should have the specified edge as one of its own and its parallel edge should contain the point. While this would already well-define the rectangle (compare forEdgeAndOpposingPoint) the additionally specified ratio and bounds have precedence over these arguments:
The returned rectangle will have the ratio and will be within the bounds. If the bounds make it possible, the specified point will lie on the edge parallel to the specified one. In order to maintain the ratio, this will make it necessary to not use the specified edge but instead one with a different length. The new edge will have the same center point as the specified one.
This results on the following behavior: As the point is moved closer to or further away from the edge, the resulting rectangle shrinks and grows while being anchored to the specified edge's center point and keeping the ratio. This is limited by the bounds.

Parameters
edge:Edge2D

the edge which defines the center point and orientation of one of the rectangle's edges; must be within the specified bounds

point:Point2D

the point to which the rectangle spans if ratio and bounds allow it

ratio:double

the ratio the new rectangle must have

bounds:Rectangle2D

the bounds within which the new rectangle must lie

Returns:Rectangle2D

a rectangle

forUpperLeftCornerAndSizeback to summary
public static Rectangle2D forUpperLeftCornerAndSize(Point2D upperLeft, double width, double height)

Creates a new rectangle with the specified upperLeft corner and the specified width and height.

Parameters
upperLeft:Point2D

one corner

width:double

the new rectangle's width

height:double

the new rectangle's height

Returns:Rectangle2D

the Rectangle2D which is defined by the specified upper left corner and width and height

fromBoundsback to summary
public static Rectangle2D fromBounds(Bounds bounds)

Returns a rectangle with the same coordinates as the specified bounds.

Parameters
bounds:Bounds

the Bounds for which the rectangle will be created

Returns:Rectangle2D

a Rectangle2D with the same minX-, minY-, maxX- and maxY-coordiantes as the specified bounds

getCenterPointback to summary
public static Point2D getCenterPoint(Rectangle2D rectangle)

Returns the center of the specified rectangle as a point.

Parameters
rectangle:Rectangle2D

the Rectangle2D whose center point will be returned

Returns:Point2D

the Point2D whose x/y coordinates lie at (min + max) / 2.

getMinCoordinateback to summary
private static double getMinCoordinate(double fixedCoordinate, double difference)

Returns the minimum coordinate such that a rectangle starting from that coordinate will contain the fixed coordinate as a corner.

Parameters
fixedCoordinate:double

the coordinate which must be a corner

difference:double

the difference in the computed coordinate

Returns:double

fixedCoordinate + difference; if difference < 0
fixedCoordinate; else

inRectangleback to summary
public static Point2D inRectangle(Rectangle2D rectangle, Point2D point)

Moves the specified point into the specified rectangle. If the point is already with the rectangle, it is returned. Otherwise the point in the rectangle which is closest to the specified one is returned.

Parameters
rectangle:Rectangle2D

the Rectangle2D into which the point should be moved

point:Point2D

the Point2D which is checked

Returns:Point2D

either the specified point or the Point2D which is closest to it while still being contained on the rectangle

intersectionback to summary
public static Rectangle2D intersection(Rectangle2D a, Rectangle2D b)

Returns the rectangle which represents the intersection of the two specified rectangles.

Parameters
a:Rectangle2D

a Rectangle2D

b:Rectangle2D

another Rectangle2D

Returns:Rectangle2D

a Rectangle2D which is the intersection of a and b; possible Rectangle2D#EMPTY.

lengthReductionToStayWithinBoundsback to summary
private static double lengthReductionToStayWithinBounds(Point2D centerPoint, double width, double height, Rectangle2D bounds)

Computes the factor by which the specified width and height must be multiplied to keep a rectangle with their ratio and the specified center point within the specified bounds.

Parameters
centerPoint:Point2D

the center point of the new rectangle

width:double

the original width which might be too large

height:double

the original height which might be too large

bounds:Rectangle2D

the bounds within which the new rectangle will be located

Returns:double

the factor with which the width and height must be multiplied to stay within the bounds; always in the closed interval [0; 1]

Exceptions
IllegalArgumentException:
if the centerPoint is out of the bounds; if width or height are not larger than zero
movePointIntoBoundsback to summary
private static Point2D movePointIntoBounds(Point2D point, Rectangle2D bounds)

Returns either the specified point if if the specified bounds contain it or a point whose X and/or Y coordinates are moved into the bounds.

Parameters
point:Point2D

the point to move into the bounds

bounds:Rectangle2D

the bounds into which the point will be moved

Returns:Point2D

either point or a new Point2D whose coordinates were changed so that it lies within the bounds

resizeEdgeForBoundsback to summary
private static Edge2D resizeEdgeForBounds(Edge2D edge, Rectangle2D bounds)

Returns an edge with the same center point and orientation as the specified edge. If necessary, its length is reduced to fit within the bounds.

Parameters
edge:Edge2D

the edge whose center point and orientation defines the returned edge's center point and orientation; the center point must be within the bounds or an IllegalArgumentException will be thrown

bounds:Rectangle2D

the bounds within which the returned edge must be contained

Returns:Edge2D

either the specified edge if it is with in the bounds or one with a corrected length

Exceptions
IllegalArgumentException:
if the edge's center point is out of bounds
resizeEdgeForDistanceAndRatioback to summary
private static Edge2D resizeEdgeForDistanceAndRatio(Edge2D edge, Point2D point, double ratio)

Returns an edge with the same center point and orientation as the specified edge. Its length has the specified ratio to the distance of the edge and the specified point.

Parameters
edge:Edge2D

the edge whose center point and orientation defines the returned edge's center point and orientation

point:Point2D

the point to which the distance is measured

ratio:double

the ratio between the distance to the point and the returned edge's length

Returns:Edge2D

an Edge2D