Package icyllis.arc3d.core
Class Rect2f
java.lang.Object
icyllis.arc3d.core.Rect2f
- All Implemented Interfaces:
Rect2fc
- Direct Known Subclasses:
Op
The
Rect2f
holds four float coordinates describing the upper and
lower bounds of a rectangle. (left, top, right, bottom). These fields can
be accessed directly. Use width() and height() to retrieve the rectangle's
width and height.
Rect may be created from outer bounds or from position, width, and height. Rect describes an area; if its right is less than or equal to its left, or if its bottom is less than or equal to its top, it is considered empty.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionRect2f()
Create a new empty rectangle.Rect2f
(float left, float top, float right, float bottom) Create a new rectangle with the specified coordinates.Create a new rectangle, initialized with the values in the specified rectangle (which is left unmodified).Create a new rectangle, initialized with the values in the specified rectangle (which is left unmodified). -
Method Summary
Modifier and TypeMethodDescriptionfinal void
adjust
(float left, float top, float right, float bottom) Adjusts the rectangle on all sides specified by the values.final void
Adjusts the rectangle on all sides specified by the values.final void
Adjusts the rectangle on all sides specified by the values.final float
bottom()
Return the rectangle's bottom.final float
centerX()
final float
centerY()
final boolean
contains
(float x, float y) Returns true if (x,y) is inside the rectangle.final boolean
contains
(float left, float top, float right, float bottom) Returns true if the 4 specified sides of a rectangle are inside or equal to this rectangle.final boolean
Returns true if the specified rectangle r is inside or equal to this rectangle.final boolean
Returns true if the specified rectangle r is inside or equal to this rectangle.static Rect2fc
empty()
Returns a read-only empty rect.boolean
Returns true if all members in a: Left, Top, Right, and Bottom; are equal to the corresponding members in b.final float
final float
int
hashCode()
final float
height()
final void
inset
(float dx, float dy) Inset the rectangle by (dx,dy).final void
inset
(float left, float top, float right, float bottom) Insets the rectangle on all sides specified by the insets.final void
Insets the rectangle on all sides specified by the dimensions of theinsets
rectangle.final void
Insets the rectangle on all sides specified by the dimensions of theinsets
rectangle.final boolean
intersect
(float left, float top, float right, float bottom) If the rectangle specified by left,top,right,bottom intersects this rectangle, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle.final boolean
If the specified rectangle intersects this rectangle, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle.final boolean
If rectangles a and b intersect, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle.final boolean
If the specified rectangle intersects this rectangle, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle.final void
intersectNoCheck
(float left, float top, float right, float bottom) If the specified rectangle intersects this rectangle, set this rectangle to that intersection, otherwise set this rectangle to the empty rectangle.final void
If the specified rectangle intersects this rectangle, set this rectangle to that intersection, otherwise set this rectangle to the empty rectangle.final void
If the specified rectangle intersects this rectangle, set this rectangle to that intersection, otherwise set this rectangle to the empty rectangle.final boolean
intersects
(float left, float top, float right, float bottom) Returns true if this rectangle intersects the specified rectangle.final boolean
Returns true if this rectangle intersects the specified rectangle.static boolean
intersects
(Rect2fc a, Rect2fc b) Returns true if the two specified rectangles intersect.final boolean
Returns true if this rectangle intersects the specified rectangle.final boolean
isEmpty()
Returns true if left is equal to or greater than right, or if top is equal to or greater than bottom.final boolean
isFinite()
Returns true if all values in the rectangle are finite.final boolean
isSorted()
Returns true if left is equal to or less than right, or if top is equal to or less than bottom.final void
join
(float x, float y) Update this rectangle to enclose itself and the [x,y] coordinate.final void
join
(float left, float top, float right, float bottom) Update this rectangle to enclose itself and the specified rectangle.final void
Update this rectangle to enclose itself and the specified rectangle.final void
Update this rectangle to enclose itself and the specified rectangle.final void
joinNoCheck
(float left, float top, float right, float bottom) Update this rectangle to enclose itself and the specified rectangle.final void
Update this rectangle to enclose itself and the specified rectangle.final void
Update this rectangle to enclose itself and the specified rectangle.final float
left()
Returns the rectangle's left.final void
offset
(float dx, float dy) Offset the rectangle by adding dx to its left and right coordinates, and adding dy to its top and bottom coordinates.final void
offsetTo
(float newLeft, float newTop) Offset the rectangle to a specific (left, top) position, keeping its width and height the same.final void
outset
(float dx, float dy) Outset the rectangle by (dx,dy).static boolean
rectsOverlap
(Rect2fc a, Rect2fc b) Returns true if the rectangles have a nonzero area of overlap.static boolean
Returns true if the rectangles overlap or share an edge or corner.final float
right()
Return the rectangle's right.final void
Set the dst rectangle by rounding this rectangle's coordinates to their nearest integer values.final void
Set the dst integer Rect by rounding this rectangle's coordinates to their nearest integer values.final void
Set the dst rectangle by rounding "in" this rectangle, choosing the ceiling of top and left, and the floor of right and bottom.final void
Set the dst integer Rect by rounding "in" this rectangle, choosing the ceiling of top and left, and the floor of right and bottom.final void
Set the dst rectangle by rounding "out" this rectangle, choosing the floor of top and left, and the ceiling of right and bottom.final void
Set the dst integer Rect by rounding "out" this rectangle, choosing the floor of top and left, and the ceiling of right and bottom.final void
set
(float left, float top, float right, float bottom) Set the rectangle's coordinates to the specified values.final void
Copy the coordinates from src into this rectangle.final void
Copy the coordinates from src into this rectangle.final boolean
setBounds
(float[] pts, int offset, int count) Sets to bounds of pts array with count points.final void
setBoundsNoCheck
(float[] pts, int offset, int count) Sets to bounds of pts array with count points.final void
setEmpty()
Set the rectangle to (0,0,0,0)final void
sort()
Swap top/bottom or left/right if there are flipped (i.e.void
Copy the coordinates from this into r.void
Stores the coordinates from this into dst.static boolean
final float
top()
Return the rectangle's top.toString()
final float
width()
final float
x()
Returns the rectangle's left.final float
y()
Return the rectangle's top.
-
Field Details
-
mLeft
public float mLeft -
mTop
public float mTop -
mRight
public float mRight -
mBottom
public float mBottom
-
-
Constructor Details
-
Rect2f
public Rect2f()Create a new empty rectangle. All coordinates are initialized to 0. -
Rect2f
public Rect2f(float left, float top, float right, float bottom) Create a new rectangle with the specified coordinates. Note: no range checking is performed, so the caller should ensure that left invalid input: '<'= right and top invalid input: '<'= bottom.- Parameters:
left
- the X coordinate of the left side of the rectangletop
- the Y coordinate of the top of the rectangleright
- the X coordinate of the right side of the rectanglebottom
- the Y coordinate of the bottom of the rectangle
-
Rect2f
Create a new rectangle, initialized with the values in the specified rectangle (which is left unmodified).- Parameters:
r
- the rectangle whose coordinates are copied into the new rectangle
-
Rect2f
Create a new rectangle, initialized with the values in the specified rectangle (which is left unmodified).- Parameters:
r
- the rectangle whose coordinates are copied into the new rectangle
-
-
Method Details
-
empty
Returns a read-only empty rect.- Returns:
- an empty rect
-
isEmpty
public final boolean isEmpty()Returns true if left is equal to or greater than right, or if top is equal to or greater than bottom. Call sort() to reverse rectangles with negative width() or height(). -
isSorted
public final boolean isSorted()Returns true if left is equal to or less than right, or if top is equal to or less than bottom. Call sort() to reverse rectangles with negative width() or height(). -
isFinite
public final boolean isFinite()Returns true if all values in the rectangle are finite. -
x
public final float x()Returns the rectangle's left. -
y
public final float y()Return the rectangle's top. -
left
public final float left()Returns the rectangle's left. -
top
public final float top()Return the rectangle's top. -
right
public final float right()Return the rectangle's right. -
bottom
public final float bottom()Return the rectangle's bottom. -
width
public final float width() -
height
public final float height() -
centerX
public final float centerX() -
centerY
public final float centerY() -
halfWidth
public final float halfWidth()- Returns:
- width()/2 without intermediate overflow or underflow.
-
halfHeight
public final float halfHeight()- Returns:
- height()/2 without intermediate overflow or underflow.
-
setEmpty
public final void setEmpty()Set the rectangle to (0,0,0,0) -
store
Copy the coordinates from this into r. -
store
Description copied from interface:Rect2fc
Stores the coordinates from this into dst. -
set
public final void set(float left, float top, float right, float bottom) Set the rectangle's coordinates to the specified values. Note: no range checking is performed, so it is up to the caller to ensure that left invalid input: '<'= right and top invalid input: '<'= bottom.- Parameters:
left
- the X coordinate of the left side of the rectangletop
- the Y coordinate of the top of the rectangleright
- the X coordinate of the right side of the rectanglebottom
- the Y coordinate of the bottom of the rectangle
-
set
Copy the coordinates from src into this rectangle.- Parameters:
src
- the rectangle whose coordinates are copied into this rectangle.
-
set
Copy the coordinates from src into this rectangle.- Parameters:
src
- the rectangle whose coordinates are copied into this rectangle.
-
setBounds
public final boolean setBounds(float[] pts, int offset, int count) Sets to bounds of pts array with count points. Returns false if pts array contains an infinity or NaN; in this case sets rect to (0, 0, 0, 0).- Parameters:
pts
- pts arrayoffset
- starting offsetcount
- number of points- Returns:
- true if all values are finite
-
setBoundsNoCheck
public final void setBoundsNoCheck(float[] pts, int offset, int count) Sets to bounds of pts array with count points. If pts array contains an infinity or NaN, all rect values are set to NaN.- Parameters:
pts
- pts arrayoffset
- starting offsetcount
- number of points
-
offset
public final void offset(float dx, float dy) Offset the rectangle by adding dx to its left and right coordinates, and adding dy to its top and bottom coordinates.- Parameters:
dx
- the amount to add to the rectangle's left and right coordinatesdy
- the amount to add to the rectangle's top and bottom coordinates
-
offsetTo
public final void offsetTo(float newLeft, float newTop) Offset the rectangle to a specific (left, top) position, keeping its width and height the same.- Parameters:
newLeft
- the new "left" coordinate for the rectanglenewTop
- the new "top" coordinate for the rectangle
-
inset
public final void inset(float dx, float dy) Inset the rectangle by (dx,dy). If dx is positive, then the sides are moved inwards, making the rectangle narrower. If dx is negative, then the sides are moved outwards, making the rectangle wider. The same holds true for dy and the top and bottom.- Parameters:
dx
- the amount to add(subtract) from the rectangle's left(right)dy
- the amount to add(subtract) from the rectangle's top(bottom)
-
outset
public final void outset(float dx, float dy) Outset the rectangle by (dx,dy).- Parameters:
dx
- the amount to subtract(add) from the rectangle's left(right)dy
- the amount to subtract(add) from the rectangle's top(bottom)
-
inset
public final void inset(float left, float top, float right, float bottom) Insets the rectangle on all sides specified by the insets.- Parameters:
left
- the amount to add from the rectangle's lefttop
- the amount to add from the rectangle's topright
- the amount to subtract from the rectangle's rightbottom
- the amount to subtract from the rectangle's bottom
-
inset
Insets the rectangle on all sides specified by the dimensions of theinsets
rectangle.- Parameters:
insets
- the rectangle specifying the insets on all side.
-
inset
Insets the rectangle on all sides specified by the dimensions of theinsets
rectangle.- Parameters:
insets
- the rectangle specifying the insets on all side.
-
adjust
public final void adjust(float left, float top, float right, float bottom) Adjusts the rectangle on all sides specified by the values.- Parameters:
left
- the amount to add from the rectangle's lefttop
- the amount to add from the rectangle's topright
- the amount to add from the rectangle's rightbottom
- the amount to add from the rectangle's bottom
-
adjust
Adjusts the rectangle on all sides specified by the values.- Parameters:
adjusts
- the rectangle specifying the adjusts on all side.
-
adjust
Adjusts the rectangle on all sides specified by the values.- Parameters:
adjusts
- the rectangle specifying the adjusts on all side.
-
contains
public final boolean contains(float x, float y) Returns true if (x,y) is inside the rectangle. The left and top are considered to be inside, while the right and bottom are not. This means that for a (x,y) to be contained: left invalid input: '<'= x invalid input: '<' right and top invalid input: '<'= y invalid input: '<' bottom. An empty rectangle never contains any point.- Specified by:
contains
in interfaceRect2fc
- Parameters:
x
- the X coordinate of the point being tested for containmenty
- the Y coordinate of the point being tested for containment- Returns:
- true if (x,y) are contained by the rectangle, where containment means left invalid input: '<'= x invalid input: '<' right and top invalid input: '<'= y invalid input: '<' bottom
-
contains
public final boolean contains(float left, float top, float right, float bottom) Returns true if the 4 specified sides of a rectangle are inside or equal to this rectangle. i.e. is this rectangle a superset of the specified rectangle. An empty rectangle never contains another rectangle.- Specified by:
contains
in interfaceRect2fc
- Parameters:
left
- the left side of the rectangle being tested for containmenttop
- the top of the rectangle being tested for containmentright
- the right side of the rectangle being tested for containmentbottom
- the bottom of the rectangle being tested for containment- Returns:
- true if the 4 specified sides of a rectangle are inside or equal to this rectangle
-
contains
Returns true if the specified rectangle r is inside or equal to this rectangle. An empty rectangle never contains another rectangle. -
contains
Returns true if the specified rectangle r is inside or equal to this rectangle. An empty rectangle never contains another rectangle. -
subtract
-
intersect
public final boolean intersect(float left, float top, float right, float bottom) If the rectangle specified by left,top,right,bottom intersects this rectangle, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle. Note: To just test for intersection, useintersects(Rect2fc, Rect2fc)
.- Parameters:
left
- the left side of the rectangle being intersected with this rectangletop
- the top of the rectangle being intersected with this rectangleright
- the right side of the rectangle being intersected with this rectangle.bottom
- the bottom of the rectangle being intersected with this rectangle.- Returns:
- true if the specified rectangle and this rectangle intersect (and this rectangle is then set to that intersection) else return false and do not change this rectangle.
-
intersect
If the specified rectangle intersects this rectangle, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle. To just test for intersection, use intersects().- Parameters:
r
- the rectangle being intersected with this rectangle.- Returns:
- true if the specified rectangle and this rectangle intersect (and this rectangle is then set to that intersection) else return false and do not change this rectangle.
-
intersect
If the specified rectangle intersects this rectangle, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle. To just test for intersection, use intersects().- Parameters:
r
- the rectangle being intersected with this rectangle.- Returns:
- true if the specified rectangle and this rectangle intersect (and this rectangle is then set to that intersection) else return false and do not change this rectangle.
-
intersectNoCheck
public final void intersectNoCheck(float left, float top, float right, float bottom) If the specified rectangle intersects this rectangle, set this rectangle to that intersection, otherwise set this rectangle to the empty rectangle.- See Also:
-
intersectNoCheck
If the specified rectangle intersects this rectangle, set this rectangle to that intersection, otherwise set this rectangle to the empty rectangle.- See Also:
-
intersectNoCheck
If the specified rectangle intersects this rectangle, set this rectangle to that intersection, otherwise set this rectangle to the empty rectangle.- See Also:
-
intersect
If rectangles a and b intersect, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle. To just test for intersection, use intersects().- Parameters:
a
- the first rectangle being intersected withb
- the second rectangle being intersected with- Returns:
- true if the two specified rectangles intersect. If they do, set this rectangle to that intersection. If they do not, return false and do not change this rectangle.
-
intersects
public final boolean intersects(float left, float top, float right, float bottom) Returns true if this rectangle intersects the specified rectangle. In no event is this rectangle modified. To record the intersection, use intersect().- Specified by:
intersects
in interfaceRect2fc
- Parameters:
left
- the left side of the rectangle being tested for intersectiontop
- the top of the rectangle being tested for intersectionright
- the right side of the rectangle being tested for intersectionbottom
- the bottom of the rectangle being tested for intersection- Returns:
- true if the specified rectangle intersects this rectangle. In no event is this rectangle modified.
-
intersects
Returns true if this rectangle intersects the specified rectangle. In no event is this rectangle modified. To record the intersection, use intersect().- Specified by:
intersects
in interfaceRect2fc
- Parameters:
r
- the rectangle being tested for intersection- Returns:
- true if the specified rectangle intersects this rectangle. In no event is this rectangle modified.
-
intersects
Returns true if this rectangle intersects the specified rectangle. In no event is this rectangle modified. To record the intersection, use intersect().- Specified by:
intersects
in interfaceRect2fc
- Parameters:
r
- the rectangle being tested for intersection- Returns:
- true if the specified rectangle intersects this rectangle. In no event is this rectangle modified.
-
intersects
Returns true if the two specified rectangles intersect. In no event are either of the rectangles modified. To record the intersection, useintersect(Rect2fc)
orintersect(Rect2fc, Rect2fc)
.- Parameters:
a
- the first rectangle being tested for intersectionb
- the second rectangle being tested for intersection- Returns:
- true if the two specified rectangles intersect. In no event are either of the rectangles modified.
-
rectsOverlap
Returns true if the rectangles have a nonzero area of overlap. It assumed that rects can be infinitely small but not "inverted". -
rectsTouchOrOverlap
Returns true if the rectangles overlap or share an edge or corner. It assumed that rects can be infinitely small but not "inverted". -
round
Set the dst integer Rect by rounding this rectangle's coordinates to their nearest integer values. -
roundIn
Set the dst integer Rect by rounding "in" this rectangle, choosing the ceiling of top and left, and the floor of right and bottom. -
roundOut
Set the dst integer Rect by rounding "out" this rectangle, choosing the floor of top and left, and the ceiling of right and bottom. -
round
Set the dst rectangle by rounding this rectangle's coordinates to their nearest integer values. -
roundIn
Set the dst rectangle by rounding "in" this rectangle, choosing the ceiling of top and left, and the floor of right and bottom. -
roundOut
Set the dst rectangle by rounding "out" this rectangle, choosing the floor of top and left, and the ceiling of right and bottom. -
join
public final void join(float left, float top, float right, float bottom) Update this rectangle to enclose itself and the specified rectangle. If the specified rectangle is empty, nothing is done. If this rectangle is empty it is set to the specified rectangle.- Parameters:
left
- the left edge being unioned with this rectangletop
- the top edge being unioned with this rectangleright
- the right edge being unioned with this rectanglebottom
- the bottom edge being unioned with this rectangle
-
join
Update this rectangle to enclose itself and the specified rectangle. If the specified rectangle is empty, nothing is done. If this rectangle is empty it is set to the specified rectangle.- Parameters:
r
- the rectangle being unioned with this rectangle
-
join
Update this rectangle to enclose itself and the specified rectangle. If the specified rectangle is empty, nothing is done. If this rectangle is empty it is set to the specified rectangle.- Parameters:
r
- the rectangle being unioned with this rectangle
-
joinNoCheck
public final void joinNoCheck(float left, float top, float right, float bottom) Update this rectangle to enclose itself and the specified rectangle. If the specified rectangle is empty, nothing is done. If this rectangle is empty it is set to the specified rectangle. No check is performed to see if either rectangle is empty.- Parameters:
left
- the left edge being unioned with this rectangletop
- the top edge being unioned with this rectangleright
- the right edge being unioned with this rectanglebottom
- the bottom edge being unioned with this rectangle
-
joinNoCheck
Update this rectangle to enclose itself and the specified rectangle. If the specified rectangle is empty, nothing is done. If this rectangle is empty it is set to the specified rectangle. No check is performed to see if either rectangle is empty.- Parameters:
r
- the rectangle being unioned with this rectangle
-
joinNoCheck
Update this rectangle to enclose itself and the specified rectangle. If the specified rectangle is empty, nothing is done. If this rectangle is empty it is set to the specified rectangle. No check is performed to see if either rectangle is empty.- Parameters:
r
- the rectangle being unioned with this rectangle
-
join
public final void join(float x, float y) Update this rectangle to enclose itself and the [x,y] coordinate.- Parameters:
x
- The x coordinate of the point to add to the rectangley
- The y coordinate of the point to add to the rectangle
-
sort
public final void sort()Swap top/bottom or left/right if there are flipped (i.e. left > right and/or top > bottom). This can be called if the edges are computed separately, and may have crossed over each other. If the edges are already correct (i.e. left invalid input: '<'= right and top invalid input: '<'= bottom) then nothing is done. -
hashCode
public int hashCode() -
equals
Returns true if all members in a: Left, Top, Right, and Bottom; are equal to the corresponding members in b.a and b are not equal if either contain NaN. a and b are equal if members contain zeroes with different signs.
-
toString
-