- java.lang.Object
-
- impl.org.controlsfx.tools.rectangle.Rectangles2D
-
public class Rectangles2D extends Object
Usability methods for rectangles.
-
-
Constructor Summary
Constructors Constructor Description Rectangles2D()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancontains(Rectangle2D rectangle, Edge2D edge)Indicates whether the specified rectangle contains the specified edge.static Rectangle2DfixRatio(Rectangle2D original, double ratio)Creates a new rectangle with the same center point and area as the specifiedoriginalrectangle with the specifiedratio.static Rectangle2DfixRatioWithinBounds(Rectangle2D original, double ratio, Rectangle2D bounds)Creates a new rectangle with the same center point and area (if possible) as the specifiedoriginalrectangle with the specifiedratioand respecting the specifiedbounds.static Rectangle2DforCenterAndAreaAndRatio(Point2D centerPoint, double area, double ratio)Creates a new rectangle with the specifiedcenterPoint,areaandratio.static Rectangle2DforCenterAndAreaAndRatioWithinBounds(Point2D centerPoint, double area, double ratio, Rectangle2D bounds)Creates a new rectangle with the specifiedcenterPoint,area(if possible) andratio, respecting the specifiedbounds.static Rectangle2DforCenterAndSize(Point2D centerPoint, double width, double height)Creates a new rectangle with the specified center and the specified width and height.static Rectangle2DforDiagonalCorners(Point2D oneCorner, Point2D diagonalCorner)Creates a new rectangle with the two specified corners.static Rectangle2DforDiagonalCornersAndRatio(Point2D fixedCorner, Point2D diagonalCorner, double ratio)Creates a new rectangle with the two specified corners.static Rectangle2DforEdgeAndOpposingPoint(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).static Rectangle2DforEdgeAndOpposingPointAndRatioWithinBounds(Edge2D edge, Point2D point, double ratio, Rectangle2D bounds)Returns a rectangle that is principally defined by the specified edge and point.static Rectangle2DforUpperLeftCornerAndSize(Point2D upperLeft, double width, double height)Creates a new rectangle with the specifiedupperLeftcorner and the specifiedwidthandheight.static Rectangle2DfromBounds(Bounds bounds)Returns a rectangle with the same coordinates as the specified bounds.static Point2DgetCenterPoint(Rectangle2D rectangle)Returns the center of the specified rectangle as a point.static Point2DinRectangle(Rectangle2D rectangle, Point2D point)Moves the specified point into the specified rectangle.static Rectangle2Dintersection(Rectangle2D a, Rectangle2D b)Returns the rectangle which represents the intersection of the two specified rectangles.
-
-
-
Method Detail
-
contains
public static boolean contains(Rectangle2D rectangle, Edge2D edge)
Indicates whether the specified rectangle contains the specified edge.- Parameters:
rectangle- the rectangle to checkedge- the edge to check- Returns:
trueif both end points of the edge arecontainedin the rectangle
-
inRectangle
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- theRectangle2Dinto which the point should be movedpoint- thePoint2Dwhich is checked- Returns:
- either the specified
pointor thePoint2Dwhich is closest to it while still being contained on therectangle
-
getCenterPoint
public static Point2D getCenterPoint(Rectangle2D rectangle)
Returns the center of the specified rectangle as a point.- Parameters:
rectangle- theRectangle2Dwhose center point will be returned- Returns:
- the
Point2Dwhose x/y coordinates lie at(min + max) / 2.
-
intersection
public static Rectangle2D intersection(Rectangle2D a, Rectangle2D b)
Returns the rectangle which represents the intersection of the two specified rectangles.- Parameters:
a- aRectangle2Db- anotherRectangle2D- Returns:
- a
Rectangle2Dwhich is the intersection ofaandb; possibleRectangle2D.EMPTY.
-
forDiagonalCorners
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- one cornerdiagonalCorner- another corner, diagonal from the first- Returns:
- the
Rectangle2Dwhich is defined by the two corners
-
forUpperLeftCornerAndSize
public static Rectangle2D forUpperLeftCornerAndSize(Point2D upperLeft, double width, double height)
Creates a new rectangle with the specifiedupperLeftcorner and the specifiedwidthandheight.- Parameters:
upperLeft- one cornerwidth- the new rectangle's widthheight- the new rectangle's height- Returns:
- the
Rectangle2Dwhich is defined by the specified upper left corner and width and height
-
forDiagonalCornersAndRatio
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 specifiedfixedCorneras its corner. The other one will either be on the same x- or y-parallel as thediagonalCornerbut will be such that the rectangle has the specifiedratio.- Parameters:
fixedCorner- one cornerdiagonalCorner- another corner, diagonal from the firstratio- the ratio the returned rectangle must have; must be non-negative- Returns:
- the
Rectangle2Dwhich is defined by thefixedCorner, the x- or y-parallel of thediagonalCornerand theratio
-
forCenterAndSize
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- the center point o the new rectanglewidth- the width of the new rectangleheight- the height of the new rectangle- Returns:
- a rectangle with the specified center and size
-
fixRatio
public static Rectangle2D fixRatio(Rectangle2D original, double ratio)
Creates a new rectangle with the same center point and area as the specifiedoriginalrectangle with the specifiedratio.- Parameters:
original- the original rectangleratio- the new ratio- Returns:
- a new
Rectangle2Dwith the same center point as theoriginaland the specifiedratio; it has the same area as theoriginal - Throws:
NullPointerException- if theoriginalrectangle is null
-
fixRatioWithinBounds
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 specifiedoriginalrectangle with the specifiedratioand respecting the specifiedbounds.- Parameters:
original- the original rectangleratio- the new ratiobounds- the bounds within which the new rectangle will be located- Returns:
- a new
Rectangle2Dwith the same center point as theoriginaland the specifiedratio; it has the same area as theoriginalunless this would violate the bounds; in this case it is as large as possible while still staying within the bounds - Throws:
NullPointerException- if theoriginalorboundsrectangle is nullIllegalArgumentException- if theoriginalrectangle's center point is out of the bounds
-
forCenterAndAreaAndRatio
public static Rectangle2D forCenterAndAreaAndRatio(Point2D centerPoint, double area, double ratio)
Creates a new rectangle with the specifiedcenterPoint,areaandratio.- Parameters:
centerPoint- the new rectangle's center pointarea- the new rectangle's arearatio- the new ratio- Returns:
- a new
Rectangle2Dwith the specifiedcenterPoint,areaandratio - Throws:
IllegalArgumentException- if thecenterPointis out of thebounds
-
forCenterAndAreaAndRatioWithinBounds
public static Rectangle2D forCenterAndAreaAndRatioWithinBounds(Point2D centerPoint, double area, double ratio, Rectangle2D bounds)
Creates a new rectangle with the specifiedcenterPoint,area(if possible) andratio, respecting the specifiedbounds.- Parameters:
centerPoint- the new rectangle's center pointarea- the new rectangle's area (if possible without violating the bounds)ratio- the new ratiobounds- the bounds within which the new rectangle will be located- Returns:
- a new
Rectangle2Dwith the specifiedcenterPointandratio; it has the specifiedareaunless this would violate thebounds; in this case it is as large as possible while still staying within the bounds - Throws:
IllegalArgumentException- if thecenterPointis out of thebounds
-
forEdgeAndOpposingPoint
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- the edge which will be contained in the returned rectanglepoint- the point whose X or Y coordinate defines the other edge- Returns:
- a rectangle
-
forEdgeAndOpposingPointAndRatioWithinBounds
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 (compareforEdgeAndOpposingPoint) 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- the edge which defines the center point and orientation of one of the rectangle's edges; must be within the specifiedboundspoint- the point to which the rectangle spans if ratio and bounds allow itratio- the ratio the new rectangle must havebounds- the bounds within which the new rectangle must lie- Returns:
- a rectangle
-
fromBounds
public static Rectangle2D fromBounds(Bounds bounds)
Returns a rectangle with the same coordinates as the specified bounds.- Parameters:
bounds- theBoundsfor which the rectangle will be created- Returns:
- a
Rectangle2Dwith the same minX-, minY-, maxX- and maxY-coordiantes as the specified bounds
-
-