Package icyllis.arc3d.core

# Class RoundRect

java.lang.Object
icyllis.arc3d.core.RoundRect

Direct Known Subclasses:
  `SimpleShape`

public class RoundRect extends Object
Represents a rounded rectangle with a bounds and a pair of radii for each corner. Based on bounds and radii, this class may represent: a degenerate line, a rectangle with sharp corners, a rectangle with one or more rounded corners, a circle, or an ellipse.

This class allows implementing CSS properties that describe rounded corners. It may have up to eight different radii, one for each axis on each of its four corners, so the corners may be circular or elliptical.

This class may modify the provided parameters when initializing bounds and radii. If either axis radii is zero or less: radii are stored as zero; corner is square. If corner curves overlap, radii are proportionally reduced to fit within bounds.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `kAlignOf`
  `static final int`
  `kComplex_Type`
  Type describes possible specializations of RoundRect.
  `static final int`
  `kEllipse_Type`
  Type describes possible specializations of RoundRect.
  `static final int`
  `kEmpty_Type`
  Type describes possible specializations of RoundRect.
  `static final int`
  `kLast_Type`
  Type describes possible specializations of RoundRect.
  `static final int`
  `kNineSlice_Type`
  Type describes possible specializations of RoundRect.
  `static final int`
  `kRect_Type`
  Type describes possible specializations of RoundRect.
  `static final int`
  `kSimple_Type`
  Type describes possible specializations of RoundRect.
  `static final int`
  `kSizeOf`
  `protected float`
  `mBottom`
  `protected float`
  `mLeft`
  The rectangular bounds, see `Rect2f`.
  `protected final float[]`
  `mRadii`
  The corner radii, upper-left, upper-right, lower-right, lower-left, in that order.
  `protected float`
  `mRight`
  `protected float`
  `mTop`
  `protected int`
  `mType`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RoundRect()`
  Initializes bounds at (0, 0), the origin, with zero width and height.
  `RoundRect(Rect2fc other)`
  Initializes to copy of other bounds.
  `RoundRect(RoundRect other)`
  Initializes to copy of other bounds and corner radii.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `final float`
  `bottom()`
  Return the rectangle's bottom.
  `final float`
  `centerX()`
  `final float`
  `centerY()`
  `boolean`
  `equals(Object o)`
  Returns true if all members in a: Left, Top, Right, Bottom, and Radii; are equal to the corresponding members in b.
  `void`
  `getBounds(Rect2f dest)`
  Returns bounds.
  `float[]`
  `getRadii()`
  Returns the corner radii for all four corners, upper-left, upper-right, lower-right, lower-left, in that order.
  `final void`
  `getRect(Rect2f dest)`
  Returns bounds.
  `float`
  `getSimpleRadiusX()`
  Returns top-left corner radii.
  `float`
  `getSimpleRadiusY()`
  Returns top-left corner radii.
  `int`
  `getType()`
  `final float`
  `halfHeight()`
  `final float`
  `halfWidth()`
  `int`
  `hashCode()`
  `final float`
  `height()`
  Returns span on the y-axis.
  `boolean`
  `isComplex()`
  `boolean`
  `isEllipse()`
  `boolean`
  `isEmpty()`
  `boolean`
  `isNineSlice()`
  `boolean`
  `isRect()`
  `boolean`
  `isSimple()`
  `boolean`
  `isValid()`
  `final float`
  `left()`
  Returns the rectangle's left.
  `final float`
  `right()`
  Return the rectangle's right.
  `void`
  `set(long p)`
  `void`
  `set(RoundRect src)`
  Copy the values from src into this object.
  `void`
  `setEllipse(float left, float top, float right, float bottom)`
  Sets bounds to ellipse, x-axis radii to half ellipse.width(), and all y-axis radii to half ellipse.height().
  `void`
  `setEllipse(Rect2fc ellipse)`
  Sets bounds to ellipse, x-axis radii to half ellipse.width(), and all y-axis radii to half ellipse.height().
  `void`
  `setEllipseXY(float cx, float cy, float radiusX, float radiusY)`
  Sets to ellipse at (cx, cy), x-axis radii to radiusX, and all y-axis radii to radiusY.
  `void`
  `setEmpty()`
  Sets bounds to zero width and height at (0, 0), the origin.
  `void`
  `setNineSlice(float left, float top, float right, float bottom, float leftRad, float topRad, float rightRad, float bottomRad)`
  Sets bounds to rect.
  `void`
  `setNineSlice(Rect2fc rect, float leftRad, float topRad, float rightRad, float bottomRad)`
  Sets bounds to rect.
  `void`
  `setRect(float left, float top, float right, float bottom)`
  Sets bounds to sorted rect, and sets corner radii to zero.
  `void`
  `setRect(Rect2fc rect)`
  Sets bounds to sorted rect, and sets corner radii to zero.
  `void`
  `setRectXY(float left, float top, float right, float bottom, float radiusX, float radiusY)`
  Sets to rounded rectangle with the same radii for all four corners.
  `void`
  `setRectXY(Rect2fc rect, float radiusX, float radiusY)`
  Sets to rounded rectangle with the same radii for all four corners.
  `void`
  `store(long p)`
  `final float`
  `top()`
  Return the rectangle's top.
  `String`
  `toString()`
  `final float`
  `width()`
  Returns span on the x-axis.
  `final float`
  `x()`
  Returns the rectangle's left.
  `final float`
  `y()`
  Return the rectangle's top.

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

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

- ## Field Details

  - ### kSizeOf

    @Internal public static final int kSizeOf
    See Also:
      - Constant Field Values

  - ### kAlignOf

    @Internal public static final int kAlignOf
    See Also:
      - Constant Field Values

  - ### kEmpty_Type

    public static final int kEmpty_Type
    Type describes possible specializations of RoundRect. Each Type is exclusive; a RoundRect may only have one type.

    Type members become progressively less restrictive; larger values of Type have more degrees of freedom than smaller values.

    See Also:
      - Constant Field Values

  - ### kRect_Type

    public static final int kRect_Type
    Type describes possible specializations of RoundRect. Each Type is exclusive; a RoundRect may only have one type.

    Type members become progressively less restrictive; larger values of Type have more degrees of freedom than smaller values.

    See Also:
      - Constant Field Values

  - ### kEllipse_Type

    public static final int kEllipse_Type
    Type describes possible specializations of RoundRect. Each Type is exclusive; a RoundRect may only have one type.

    Type members become progressively less restrictive; larger values of Type have more degrees of freedom than smaller values.

    See Also:
      - Constant Field Values

  - ### kSimple_Type

    public static final int kSimple_Type
    Type describes possible specializations of RoundRect. Each Type is exclusive; a RoundRect may only have one type.

    Type members become progressively less restrictive; larger values of Type have more degrees of freedom than smaller values.

    See Also:
      - Constant Field Values

  - ### kNineSlice_Type

    public static final int kNineSlice_Type
    Type describes possible specializations of RoundRect. Each Type is exclusive; a RoundRect may only have one type.

    Type members become progressively less restrictive; larger values of Type have more degrees of freedom than smaller values.

    See Also:
      - Constant Field Values

  - ### kComplex_Type

    public static final int kComplex_Type
    Type describes possible specializations of RoundRect. Each Type is exclusive; a RoundRect may only have one type.

    Type members become progressively less restrictive; larger values of Type have more degrees of freedom than smaller values.

    See Also:
      - Constant Field Values

  - ### kLast_Type

    public static final int kLast_Type
    Type describes possible specializations of RoundRect. Each Type is exclusive; a RoundRect may only have one type.

    Type members become progressively less restrictive; larger values of Type have more degrees of freedom than smaller values.

    See Also:
      - Constant Field Values

  - ### mLeft

    protected float mLeft
    The rectangular bounds, see `Rect2f`.

  - ### mTop

    protected float mTop

  - ### mRight

    protected float mRight

  - ### mBottom

    protected float mBottom

  - ### mRadii

    @Size(8L) protected final float[] mRadii
    The corner radii, upper-left, upper-right, lower-right, lower-left, in that order.

  - ### mType

    protected int mType

- ## Constructor Details

  - ### RoundRect

    public RoundRect()
    Initializes bounds at (0, 0), the origin, with zero width and height. Initializes corner radii to (0, 0), and sets type of kEmpty_Type.

  - ### RoundRect

    public RoundRect(RoundRect other)
    Initializes to copy of other bounds and corner radii.

  - ### RoundRect

    public RoundRect(Rect2fc other)
    Initializes to copy of other bounds.

- ## Method Details

  - ### 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()
    Returns span on the x-axis. This does not check if result fits in 32-bit float; result may be infinity.
    Returns:
      rect().fRight minus rect().fLeft

  - ### height

    public final float height()
    Returns span on the y-axis. This does not check if result fits in 32-bit float; result may be infinity.
    Returns:
      rect().fBottom minus rect().fTop

  - ### centerX

    public final float centerX()
    Returns:
      the horizontal center of the rectangle. This does not check for a valid rectangle (i.e. left invalid input: '<'= right)

  - ### centerY

    public final float centerY()
    Returns:
      the vertical center of the rectangle. This does not check for a valid rectangle (i.e. top invalid input: '<'= bottom)

  - ### 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.

  - ### getType

    public int getType()

  - ### isEmpty

    public boolean isEmpty()

  - ### isRect

    public boolean isRect()

  - ### isEllipse

    public boolean isEllipse()

  - ### isSimple

    public boolean isSimple()

  - ### isNineSlice

    public boolean isNineSlice()

  - ### isComplex

    public boolean isComplex()

  - ### getSimpleRadiusX

    public float getSimpleRadiusX()
    Returns top-left corner radii. If type() returns kEmpty_Type, kRect_Type, kEllipse_Type, or kSimple_Type, returns a value representative of all corner radii. If type() returns kNineSlice_Type or kComplex_Type, at least one of the remaining three corners has a different value.
    Returns:
      corner radii for simple types

  - ### getSimpleRadiusY

    public float getSimpleRadiusY()
    Returns top-left corner radii. If type() returns kEmpty_Type, kRect_Type, kEllipse_Type, or kSimple_Type, returns a value representative of all corner radii. If type() returns kNineSlice_Type or kComplex_Type, at least one of the remaining three corners has a different value.
    Returns:
      corner radii for simple types

  - ### getRadii

    @Size(8L) public float[] getRadii()
    Returns the corner radii for all four corners, upper-left, upper-right, lower-right, lower-left, in that order. Note that the return value is an unmodifiable view (no copy).

  - ### set

    @Internal public void set(long p)

  - ### store

    @Internal public void store(long p)

  - ### set

    public void set(@Nonnull RoundRect src)
    Copy the values from src into this object.

  - ### setEmpty

    public void setEmpty()
    Sets bounds to zero width and height at (0, 0), the origin. Sets corner radii to zero and sets type to kEmpty_Type.

  - ### setRect

    public void setRect(Rect2fc rect)
    Sets bounds to sorted rect, and sets corner radii to zero. If set bounds has width and height, and sets type to kRect_Type; otherwise, sets type to kEmpty_Type.
    Parameters:
      `rect` - bounds to set

  - ### setRect

    public void setRect(float left, float top, float right, float bottom)
    Sets bounds to sorted rect, and sets corner radii to zero. If set bounds has width and height, and sets type to kRect_Type; otherwise, sets type to kEmpty_Type.

  - ### setEllipse

    public void setEllipse(Rect2fc ellipse)
    Sets bounds to ellipse, x-axis radii to half ellipse.width(), and all y-axis radii to half ellipse.height(). If ellipse bounds is empty, sets to kEmpty_Type. Otherwise, sets to kEllipse_Type.
    Parameters:
      `ellipse` - bounds of ellipse

  - ### setEllipse

    public void setEllipse(float left, float top, float right, float bottom)
    Sets bounds to ellipse, x-axis radii to half ellipse.width(), and all y-axis radii to half ellipse.height(). If ellipse bounds is empty, sets to kEmpty_Type. Otherwise, sets to kEllipse_Type.

  - ### setEllipseXY

    public void setEllipseXY(float cx, float cy, float radiusX, float radiusY)
    Sets to ellipse at (cx, cy), x-axis radii to radiusX, and all y-axis radii to radiusY. If ellipse bounds is empty, sets to kEmpty_Type. Otherwise, sets to kEllipse_Type.

    Due to floating-point errors, only this method can guarantee to produce 'circle' type, if radiusX and radiusY are equal.

    Parameters:
      `cx` - ellipse center on the x-axis
      `cy` - ellipse center on the y-axis
      `radiusX` - x-axis radius of ellipse
      `radiusY` - y-axis radius of ellipse

  - ### setRectXY

    public void setRectXY(Rect2fc rect, float radiusX, float radiusY)
    Sets to rounded rectangle with the same radii for all four corners. If rect is empty, sets to kEmpty_Type. Otherwise, if radiusX or radiusY is zero, sets to kRect_Type. Otherwise, if radiusX is at least half rect.width() and radiusY is at least half rect.height(), sets to kEllipse_Type. Otherwise, sets to kSimple_Type.
    Parameters:
      `rect` - bounds of rounded rectangle
      `radiusX` - x-axis radius of corners
      `radiusY` - y-axis radius of corners

  - ### setRectXY

    public void setRectXY(float left, float top, float right, float bottom, float radiusX, float radiusY)
    Sets to rounded rectangle with the same radii for all four corners. If rect is empty, sets to kEmpty_Type. Otherwise, if radiusX or radiusY is zero, sets to kRect_Type. Otherwise, if radiusX is at least half rect.width() and radiusY is at least half rect.height(), sets to kEllipse_Type. Otherwise, sets to kSimple_Type.
    Parameters:
      `radiusX` - x-axis radius of corners
      `radiusY` - y-axis radius of corners

  - ### setNineSlice

    public void setNineSlice(Rect2fc rect, float leftRad, float topRad, float rightRad, float bottomRad)
    Sets bounds to rect. Sets radii to (leftRad, topRad), (rightRad, topRad), (rightRad, bottomRad), (leftRad, bottomRad).

    If rect is empty, sets to kEmpty_Type. Otherwise, if leftRad and rightRad are zero, sets to kRect_Type. Otherwise, if topRad and bottomRad are zero, sets to kRect_Type. Otherwise, if leftRad and rightRad are equal and at least half rect.width(), and topRad and bottomRad are equal at least half rect.height(), sets to kEllipse_Type. Otherwise, if leftRad and rightRad are equal, and topRad and bottomRad are equal, sets to kSimple_Type. Otherwise, sets to kNineSlice_Type.

    Nine patch refers to the nine parts defined by the radii: one center rectangle, four edge patches, and four corner patches.

    Parameters:
      `rect` - bounds of rounded rectangle
      `leftRad` - left-top and left-bottom x-axis radius
      `topRad` - left-top and right-top y-axis radius
      `rightRad` - right-top and right-bottom x-axis radius
      `bottomRad` - left-bottom and right-bottom y-axis radius

  - ### setNineSlice

    public void setNineSlice(float left, float top, float right, float bottom, float leftRad, float topRad, float rightRad, float bottomRad)
    Sets bounds to rect. Sets radii to (leftRad, topRad), (rightRad, topRad), (rightRad, bottomRad), (leftRad, bottomRad).

    If rect is empty, sets to kEmpty_Type. Otherwise, if leftRad and rightRad are zero, sets to kRect_Type. Otherwise, if topRad and bottomRad are zero, sets to kRect_Type. Otherwise, if leftRad and rightRad are equal and at least half rect.width(), and topRad and bottomRad are equal at least half rect.height(), sets to kEllipse_Type. Otherwise, if leftRad and rightRad are equal, and topRad and bottomRad are equal, sets to kSimple_Type. Otherwise, sets to kNineSlice_Type.

    Nine patch refers to the nine parts defined by the radii: one center rectangle, four edge patches, and four corner patches.

    Parameters:
      `leftRad` - left-top and left-bottom x-axis radius
      `topRad` - left-top and right-top y-axis radius
      `rightRad` - right-top and right-bottom x-axis radius
      `bottomRad` - left-bottom and right-bottom y-axis radius

  - ### getRect

    public final void getRect(Rect2f dest)
    Returns bounds. Bounds may have zero width or zero height. Bounds right is greater than or equal to left; bounds bottom is greater than or equal to top. Result is identical to getBounds().

  - ### getBounds

    public void getBounds(Rect2f dest)
    Returns bounds. Bounds may have zero width or zero height. Bounds right is greater than or equal to left; bounds bottom is greater than or equal to top. Result is identical to `getRect(icyllis.arc3d.core.Rect2f)`.

  - ### isValid

    public boolean isValid()

  - ### hashCode

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

  - ### equals

    public boolean equals(Object o)
    Returns true if all members in a: Left, Top, Right, Bottom, and Radii; 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.

    Overrides:
      `equals` in class `Object`
    Parameters:
      `o` - rrect to compare
    Returns:
      true if members are equal

  - ### toString

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