Class RoundRect
- Direct Known Subclasses:
SimpleShape
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
Modifier and TypeFieldDescriptionstatic final int
static final int
Type describes possible specializations of RoundRect.static final int
Type describes possible specializations of RoundRect.static final int
Type describes possible specializations of RoundRect.static final int
Type describes possible specializations of RoundRect.static final int
Type describes possible specializations of RoundRect.static final int
Type describes possible specializations of RoundRect.static final int
Type describes possible specializations of RoundRect.static final int
protected float
protected float
The rectangular bounds, seeRect2f
.protected final float[]
The corner radii, upper-left, upper-right, lower-right, lower-left, in that order.protected float
protected float
protected int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal float
bottom()
Return the rectangle's bottom.final float
centerX()
final float
centerY()
boolean
Returns true if all members in a: Left, Top, Right, Bottom, and Radii; are equal to the corresponding members in b.void
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
Returns bounds.float
Returns top-left corner radii.float
Returns top-left corner radii.int
getType()
final float
final float
int
hashCode()
final float
height()
Returns span on the y-axis.boolean
boolean
boolean
isEmpty()
boolean
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
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
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
Sets to rounded rectangle with the same radii for all four corners.void
store
(long p) final float
top()
Return the rectangle's top.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.
-
Field Details
-
kSizeOf
@Internal public static final int kSizeOf- See Also:
-
kAlignOf
@Internal public static final int kAlignOf- See Also:
-
kEmpty_Type
public static final int kEmpty_TypeType 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:
-
kRect_Type
public static final int kRect_TypeType 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:
-
kEllipse_Type
public static final int kEllipse_TypeType 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:
-
kSimple_Type
public static final int kSimple_TypeType 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:
-
kNineSlice_Type
public static final int kNineSlice_TypeType 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:
-
kComplex_Type
public static final int kComplex_TypeType 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:
-
kLast_Type
public static final int kLast_TypeType 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:
-
mLeft
protected float mLeftThe rectangular bounds, seeRect2f
. -
mTop
protected float mTop -
mRight
protected float mRight -
mBottom
protected float mBottom -
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
Initializes to copy of other bounds and corner radii. -
RoundRect
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
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
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
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
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-axiscy
- ellipse center on the y-axisradiusX
- x-axis radius of ellipseradiusY
- y-axis radius of ellipse
-
setRectXY
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 rectangleradiusX
- x-axis radius of cornersradiusY
- 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 cornersradiusY
- 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 rectangleleftRad
- left-top and left-bottom x-axis radiustopRad
- left-top and right-top y-axis radiusrightRad
- right-top and right-bottom x-axis radiusbottomRad
- 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 radiustopRad
- left-top and right-top y-axis radiusrightRad
- right-top and right-bottom x-axis radiusbottomRad
- left-bottom and right-bottom y-axis radius
-
getRect
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
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 togetRect(icyllis.arc3d.core.Rect2f)
. -
isValid
public boolean isValid() -
hashCode
public int hashCode() -
equals
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.
-
toString
-