Package icyllis.arc3d.core
Class Rect2i
java.lang.Object
icyllis.arc3d.core.Rect2i
- All Implemented Interfaces:
Rect2ic
The
Rect2i
holds four integer 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.
Note that the right and bottom coordinates are exclusive. This means a
Rect2i
being drawn untransformed onto a Canvas
will
draw into the column and row described by its left and top coordinates,
but not those of its bottom and right.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionRect2i()
Create a new rectangle with all coordinates initialized to 0.Rect2i
(int left, int top, int right, int 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
(int left, int top, int right, int bottom) Adjusts the rectangle on all sides specified by the values.final void
Adjusts the rectangle on all sides specified by the values.final int
bottom()
Return the rectangle's bottom.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
contains
(int x, int y) Returns true if (x,y) is inside the rectangle.final boolean
contains
(int left, int top, int right, int 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 Rect2ic
empty()
Returns a read-only empty rect.boolean
int
hashCode()
final int
height()
final void
inset
(int dx, int dy) Inset the rectangle by (dx,dy).final void
inset
(int left, int top, int right, int 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 boolean
intersect
(int left, int top, int right, int 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 void
intersectNoCheck
(int left, int top, int right, int 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 boolean
intersects
(int left, int top, int right, int bottom) Returns true if this rectangle intersects the specified rectangle.final boolean
Returns true if this rectangle intersects the specified rectangle.static boolean
intersects
(Rect2ic a, Rect2ic b) Returns true if the two specified rectangles intersect.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
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
(int x, int y) Update this Rect to enclose itself and the [x,y] coordinate.final void
join
(int left, int top, int right, int bottom) Update this Rect to enclose itself and the specified rectangle.final void
Update this Rect to enclose itself and the specified rectangle.final void
joinNoCheck
(int left, int top, int right, int bottom) Update this Rect to enclose itself and the specified rectangle.final void
Update this Rect to enclose itself and the specified rectangle.final int
left()
Returns the rectangle's left.final void
offset
(int dx, int 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
(int newLeft, int newTop) Offset the rectangle to a specific (left, top) position, keeping its width and height the same.final int
right()
Return the rectangle's right.final void
set
(int left, int top, int right, int bottom) Set the rectangle's coordinates to the specified values.final void
Copy the coordinates from src into this rectangle.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
Copy the coordinates from this into r.static boolean
final int
top()
Return the rectangle's top.toString()
final int
width()
final int
x()
Returns the rectangle's left.final int
y()
Return the rectangle's top.
-
Field Details
-
mLeft
public int mLeft -
mTop
public int mTop -
mRight
public int mRight -
mBottom
public int mBottom
-
-
Constructor Details
-
Rect2i
public Rect2i()Create a new rectangle with all coordinates initialized to 0. -
Rect2i
public Rect2i(int left, int top, int right, int 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
-
Rect2i
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
-
Rect2i
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(). -
x
public final int x()Returns the rectangle's left. -
y
public final int y()Return the rectangle's top. -
left
public final int left()Returns the rectangle's left. -
top
public final int top()Return the rectangle's top. -
right
public final int right()Return the rectangle's right. -
bottom
public final int bottom()Return the rectangle's bottom. -
width
public final int width() -
height
public final int height() -
setEmpty
public final void setEmpty()Set the rectangle to (0,0,0,0) -
store
Copy the coordinates from this into r. -
store
Copy the coordinates from this into r. -
set
public final void set(int left, int top, int right, int 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.
-
offset
public final void offset(int dx, int 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(int newLeft, int 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(int dx, int 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)
-
inset
public final void inset(int left, int top, int right, int 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.
-
adjust
public final void adjust(int left, int top, int right, int 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.
-
contains
public final boolean contains(int x, int 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 interfaceRect2ic
- 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 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 interfaceRect2ic
- 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(int left, int top, int right, int 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.- 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
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.- 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. -
subtract
-
intersect
public final boolean intersect(int left, int top, int right, int 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(Rect2ic, Rect2ic)
.- 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.
-
intersectNoCheck
public final void intersectNoCheck(int left, int top, int right, int 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:
-
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(int left, int top, int right, int bottom) Returns true if this rectangle intersects the specified rectangle. In no event is this rectangle modified. To record the intersection, use intersect().- 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 interfaceRect2ic
- 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(Rect2ic)
orintersect(Rect2ic, Rect2ic)
.- 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.
-
join
public final void join(int left, int top, int right, int bottom) Update this Rect 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 Rect 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(int left, int top, int right, int bottom) Update this Rect 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 Rect 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(int x, int y) Update this Rect 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. -
equals
-
hashCode
public int hashCode() -
toString
-