Package icyllis.arc3d.core

# Class Rect2i

java.lang.Object
icyllis.arc3d.core.Rect2i

All Implemented Interfaces:
  `Rect2ic`

public non-sealed class Rect2i extends Object implements 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

  Fields
  Modifier and Type
  Field
  Description
  `int`
  `mBottom`
  `int`
  `mLeft`
  `int`
  `mRight`
  `int`
  `mTop`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Rect2i()`
  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.
  `Rect2i(Rect2fc r)`
  Create a new rectangle, initialized with the values in the specified rectangle (which is left unmodified).
  `Rect2i(Rect2ic r)`
  Create a new rectangle, initialized with the values in the specified rectangle (which is left unmodified).

- ## Method Summary

  Modifier and Type
  Method
  Description
  `final void`
  `adjust(int left, int top, int right, int bottom)`
  Adjusts the rectangle on all sides specified by the values.
  `final void`
  `adjust(Rect2ic adjusts)`
  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`
  `contains(Rect2fc r)`
  Returns true if the specified rectangle r is inside or equal to this rectangle.
  `final boolean`
  `contains(Rect2ic r)`
  Returns true if the specified rectangle r is inside or equal to this rectangle.
  `static Rect2ic`
  `empty()`
  Returns a read-only empty rect.
  `boolean`
  `equals(Object o)`
  `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`
  `inset(Rect2ic insets)`
  Insets the rectangle on all sides specified by the dimensions of the `insets` 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`
  `intersect(Rect2ic r)`
  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`
  `intersect(Rect2ic a, Rect2ic b)`
  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`
  `intersectNoCheck(Rect2ic r)`
  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`
  `intersects(Rect2ic r)`
  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`
  `join(Rect2ic r)`
  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`
  `joinNoCheck(Rect2ic r)`
  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`
  `set(Rect2ic src)`
  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`
  `store(Rect2f dst)`
  Copy the coordinates from this into r.
  `void`
  `store(Rect2i dst)`
  Copy the coordinates from this into r.
  `static boolean`
  `subtract(Rect2ic a, Rect2ic b, Rect2i out)`
  `final int`
  `top()`
  Return the rectangle's top.
  `String`
  `toString()`
  `final int`
  `width()`
  `final int`
  `x()`
  Returns the rectangle's left.
  `final int`
  `y()`
  Return the rectangle's top.

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## 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 rectangle
      `top` - the Y coordinate of the top of the rectangle
      `right` - the X coordinate of the right side of the rectangle
      `bottom` - the Y coordinate of the bottom of the rectangle

  - ### Rect2i

    public Rect2i(@Nonnull Rect2ic r)
    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

    public Rect2i(@Nonnull Rect2fc r)
    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

    @Nonnull public static Rect2ic 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().
    Specified by:
      `isEmpty` in interface `Rect2ic`
    Returns:
      true if width() or height() are zero or negative

  - ### 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().
    Specified by:
      `isSorted` in interface `Rect2ic`
    Returns:
      true if width() or height() are zero or positive

  - ### x

    public final int x()
    Returns the rectangle's left.
    Specified by:
      `x` in interface `Rect2ic`

  - ### y

    public final int y()
    Return the rectangle's top.
    Specified by:
      `y` in interface `Rect2ic`

  - ### left

    public final int left()
    Returns the rectangle's left.
    Specified by:
      `left` in interface `Rect2ic`

  - ### top

    public final int top()
    Return the rectangle's top.
    Specified by:
      `top` in interface `Rect2ic`

  - ### right

    public final int right()
    Return the rectangle's right.
    Specified by:
      `right` in interface `Rect2ic`

  - ### bottom

    public final int bottom()
    Return the rectangle's bottom.
    Specified by:
      `bottom` in interface `Rect2ic`

  - ### width

    public final int width()
    Specified by:
      `width` in interface `Rect2ic`
    Returns:
      the rectangle's width. This does not check for a valid rectangle (i.e. left invalid input: '<'= right) so the result may be negative.

  - ### height

    public final int height()
    Specified by:
      `height` in interface `Rect2ic`
    Returns:
      the rectangle's height. This does not check for a valid rectangle (i.e. top invalid input: '<'= bottom) so the result may be negative.

  - ### setEmpty

    public final void setEmpty()
    Set the rectangle to (0,0,0,0)

  - ### store

    public void store(@Nonnull Rect2i dst)
    Copy the coordinates from this into r.
    Specified by:
      `store` in interface `Rect2ic`
    Parameters:
      `dst` - the rectangle to store

  - ### store

    public void store(@Nonnull Rect2f dst)
    Copy the coordinates from this into r.
    Specified by:
      `store` in interface `Rect2ic`
    Parameters:
      `dst` - the rectangle to store

  - ### 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 rectangle
      `top` - the Y coordinate of the top of the rectangle
      `right` - the X coordinate of the right side of the rectangle
      `bottom` - the Y coordinate of the bottom of the rectangle

  - ### set

    public final void set(@Nonnull Rect2ic src)
    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 coordinates
      `dy` - 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 rectangle
      `newTop` - 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 left
      `top` - the amount to add from the rectangle's top
      `right` - the amount to subtract from the rectangle's right
      `bottom` - the amount to subtract from the rectangle's bottom

  - ### inset

    public final void inset(@Nonnull Rect2ic insets)
    Insets the rectangle on all sides specified by the dimensions of the `insets` 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 left
      `top` - the amount to add from the rectangle's top
      `right` - the amount to add from the rectangle's right
      `bottom` - the amount to add from the rectangle's bottom

  - ### adjust

    public final void adjust(@Nonnull Rect2ic adjusts)
    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 interface `Rect2ic`
    Parameters:
      `x` - the X coordinate of the point being tested for containment
      `y` - 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 interface `Rect2ic`
    Parameters:
      `x` - the X coordinate of the point being tested for containment
      `y` - 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 containment
      `top` - the top of the rectangle being tested for containment
      `right` - the right side of the rectangle being tested for containment
      `bottom` - 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

    public final boolean contains(Rect2ic r)
    Returns true if the specified rectangle r is inside or equal to this rectangle. An empty rectangle never contains another rectangle.
    Specified by:
      `contains` in interface `Rect2ic`
    Parameters:
      `r` - the rectangle being tested for containment.
    Returns:
      true if the specified rectangle r is inside or equal to this 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 containment
      `top` - the top of the rectangle being tested for containment
      `right` - the right side of the rectangle being tested for containment
      `bottom` - 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

    public final boolean contains(Rect2fc r)
    Returns true if the specified rectangle r is inside or equal to this rectangle. An empty rectangle never contains another rectangle.
    Specified by:
      `contains` in interface `Rect2ic`
    Parameters:
      `r` - the rectangle being tested for containment.
    Returns:
      true if the specified rectangle r is inside or equal to this rectangle

  - ### subtract

    public static boolean subtract(Rect2ic a, Rect2ic b, Rect2i out)

  - ### 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, use `intersects(Rect2ic, Rect2ic)`.
    Parameters:
      `left` - the left side of the rectangle being intersected with this rectangle
      `top` - the top of the rectangle being intersected with this rectangle
      `right` - 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

    public final boolean intersect(Rect2ic r)
    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:
      - `but without checking if the rects overlap.`

  - ### intersectNoCheck

    public final void intersectNoCheck(Rect2ic r)
    If the specified rectangle intersects this rectangle, set this rectangle to that intersection, otherwise set this rectangle to the empty rectangle.
    See Also:
      - `but without checking if the rects overlap.`

  - ### intersect

    public final boolean intersect(Rect2ic a, Rect2ic b)
    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 with
      `b` - 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 intersection
      `top` - the top of the rectangle being tested for intersection
      `right` - the right side of the rectangle being tested for intersection
      `bottom` - 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

    public final boolean intersects(Rect2ic r)
    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 interface `Rect2ic`
    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

    public static boolean intersects(Rect2ic a, Rect2ic b)
    Returns true if the two specified rectangles intersect. In no event are either of the rectangles modified. To record the intersection, use `intersect(Rect2ic)` or `intersect(Rect2ic, Rect2ic)`.
    Parameters:
      `a` - the first rectangle being tested for intersection
      `b` - 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 rectangle
      `top` - the top edge being unioned with this rectangle
      `right` - the right edge being unioned with this rectangle
      `bottom` - the bottom edge being unioned with this rectangle

  - ### join

    public final void join(Rect2ic r)
    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 rectangle
      `top` - the top edge being unioned with this rectangle
      `right` - the right edge being unioned with this rectangle
      `bottom` - the bottom edge being unioned with this rectangle

  - ### joinNoCheck

    public final void joinNoCheck(Rect2ic r)
    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 rectangle
      `y` - 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

    public boolean equals(Object o)
    Overrides:
      `equals` in class `Object`

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`