SkRRect Reference === # RRect # Class SkRRect ## Constant SkRRect related constants are defined by enum, enum class, #define, const, and constexpr.
Topic Description
Corner corner radii order
Type specialization of Round Rect geometry
kComplex Type non-zero width and height with arbitrary radii
kEmpty Type zero width or height
kLastType largest Type value
kLowerLeft Corner index of bottom-left corner radii
kLowerRight Corner index of bottom-right corner radii
kNinePatch Type non-zero width and height with axis-aligned radii
kOval Type non-zero width and height filled with radii
kRect Type non-zero width and height, and zeroed radii
kSimple Type non-zero width and height with equal radii
kSizeInMemory incomplete
kUpperLeft Corner index of top-left corner radii
kUpperRight Corner index of top-right corner radii
## Related_Function SkRRect global, struct, and class related member functions share a topic.
Topic Description
Type specialization of Round Rect geometry
The SkRRect class represents a rounded rect with a potentially different radii for each corner. It does not have a constructor so must be initialized with one of the initialization functions (e.g., setEmpty, setRectRadii, etc.) This class allows implementing CSS properties that describe rounded corners. A rectangle may have up to eight radii, one for each axis on each of its four corners. If either corner's radii are zero, the corner is square. Negative radii are treated as zero. If corner curves overlap, they are proportionally reduced to fit. ## Overview
Topic Description
Constants enum and enum class, and their const values
Constructors functions that construct SkRRect
Functions global and class member functions
Operators operator overloading methods
Related Functions similar member functions grouped together
## Constructor SkRRect can be constructed or initialized by these functions, including C++ class constructors.
Topic Description
MakeEmpty creates with zeroed bounds and corner radii
MakeOval creates Oval to fit bounds
MakeRect copies bounds and zeroes corner radii
MakeRectXY creates rounded rectangle
SkRRect() creates with zeroed bounds and corner radii
SkRRect(const SkRRect& rrect) copies bounds and corner radii
makeOffset offsets bounds and radii
## Operator SkRRect operators inline class member functions with arithmetic equivalents.
Topic Description
operator!=(const SkRRect& a, const SkRRect& b) returns true if members are unequal
operator=(const SkRRect& rrect) copies bounds and corner radii
operator==(const SkRRect& a, const SkRRect& b) returns true if members are equal
## Member Function SkRRect member functions read and modify the structure properties.
Topic Description
MakeEmpty creates with zeroed bounds and corner radii
MakeOval creates Oval to fit bounds
MakeRect copies bounds and zeroes corner radii
MakeRectXY creates rounded rectangle
contains returns true if Rect is inside
dump sends text representation to standard output
dumpHex sends text representation using hexadecimal to standard output
getBounds returns bounds
getSimpleRadii returns corner radii for simple types
getType returns Type
height returns span in y
inset insets bounds and radii
isComplex returns true if not empty, rect, oval, simple, or nine-patch
isEmpty returns true if width or height are zero
isNinePatch returns true if not empty, rect, oval or simple; and radii are axis-aligned
isOval returns true if not empty, axes radii are equal, radii fill bounds
isRect returns true if not empty, and one radius at each corner is zero
isSimple returns true if not empty, rect or oval; and axes radii are equal
isValid incomplete
makeOffset offsets bounds and radii
offset offsets bounds and radii
outset outsets bounds and radii
radii returns x-axis and y-axis radii for one corner
readFromMemory incomplete
rect returns bounds
setEmpty zeroes width, height, and corner radii
setNinePatch replaces with rounded rectangle
setOval replaces with Oval to fit bounds
setRect sets rect bounds with zeroed corners
setRectRadii replaces with rounded rectangle
setRectXY replaces with rounded rectangle
transform scales and offsets into copy
type returns Type
width returns span in x
writeToMemory incomplete
## SkRRect
SkRRect()
Initializes bounds at (0, 0), the origin, with zero width and height. Initializes corner radii to (0, 0), and sets type of kEmpty Type. ### Return Value empty Round Rect ### Example
### See Also setEmpty isEmpty --- ## SkRRect
SkRRect(const SkRRect& rrect)
Initializes to copy of rrect bounds and corner radii. ### Parameters
rrect bounds and corner to copy
### Return Value copy of rrect ### Example
### See Also operator=(const SkRRect& rrect) MakeRect --- ## operator=
SkRRect& operator=(const SkRRect& rrect)
Copies rrect bounds and corner radii. ### Parameters
rrect bounds and corner to copy
### Return Value copy of rrect ### Example
### See Also SkRRect(const SkRRect& rrect) MakeRect --- ## Type ## Enum SkRRect::Type
    enum Type {
        kEmpty Type,
        kRect Type,
        kOval Type,
        kSimple Type,
        kNinePatch Type,
        kComplex Type,
        kLastType = kComplex Type,
    };
Type describes possible specializations of Round Rect. Each Type is exclusive; a Round Rect may only have one type. The enum members become progressively less restrictive; larger values of Type have more degrees of freedom than smaller values. ### Constants
Const Value Description
SkRRect::kEmpty_Type #Line # zero width or height ## Round Rect has zero width or height. All radii are zero.
SkRRect::kRect_Type #Line # non-zero width and height, and zeroed radii ## Round Rect has width and height. All radii are zero.
SkRRect::kOval_Type #Line # non-zero width and height filled with radii ## Round Rect has width and height. All four x-radii are equal, and at least half the width. All four y-radii are equal, and at least half the height.
SkRRect::kSimple_Type #Line # non-zero width and height with equal radii ## Round Rect has width and height. All four x-radii are equal and greater than zero, and all four y-radii are equal and greater than zero. Either x-radii are less than half the width, or y-radii is less than half the height, or both.
SkRRect::kNinePatch_Type #Line # non-zero width and height with axis-aligned radii ## Round Rect has width and height. Left x-radii are equal, top y-radii are equal, right x-radii are equal, and bottom y-radii are equal. The radii do not describe a rect, oval, or simple type. The centers of the corner ellipses form an axis-aligned rectangle that divides the Round Rect into nine rectangular patches; an interior rectangle, four edges, and four corners.
SkRRect::kComplex_Type #Line # non-zero width and height with arbitrary radii ## both radii are non-zero.
SkRRect::kLastType = kComplex_Type largest Type value
### Example
### See Also Rect Path ## getType
Type getType() const
Returns Type, one of: kEmpty Type, kRect Type, kOval Type, kSimple Type, kNinePatch Type, kComplex Type. ### Return Value Type ### Example
rrect2 is not a Rect; inset has made it empty.
### See Also Type type --- ## type
Type type() const
Returns Type, one of: kEmpty Type, kRect Type, kOval Type, kSimple Type, kNinePatch Type, kComplex Type. ### Return Value Type ### Example
inset has made rrect2 empty.
### See Also Type getType --- ## isEmpty
inline bool isEmpty() const
Returns true if rect.fLeft is equal to rect.fRight, or if rect.fTop is equal to rect.fBottom. ### Return Value true if width or height are zero ### Example
### See Also SkRect::isEmpty height width --- ## isRect
inline bool isRect() const
Returns true if not empty, and if either x or y radius at each corner is zero. ### Return Value true if not empty, and one radius at each corner is zero ### Example
### See Also isEmpty radii --- ## isOval
inline bool isOval() const
Returns true if not empty, if all x-axis radii are equal, if all y-axis radii are equal, x-axis radii are at least half the width, and y-axis radii are at least half the height. ### Return Value true if has identical geometry to Oval ### Example
The first radii are scaled down proportionately until both x-axis and y-axis fit within the bounds. After scaling, x-axis radius is smaller than half the width; left round rect is not an oval. The second radii are equal to half the dimensions; right round rect is an oval.
### See Also isEmpty isSimple SkCanvas::drawOval --- ## isSimple
inline bool isSimple() const
Returns true if not empty, if all x-axis radii are equal but not zero, if all y-axis radii are equal but not zero; and x-axis radius is less than half width, or y-axis radius is less than half height. ### Return Value true if not empty, rect or oval; and axes radii are equal ### Example
### See Also isEmpty isRect isOval isNinePatch --- ## isNinePatch
inline bool isNinePatch() const
Returns true if isEmpty, isRect, isOval, and isSimple return false; and if left x-axis radii are equal, right x-axis radii are equal, top y-axis radii are equal, and bottom y-axis radii are equal. ### Return Value true if not empty, rect, oval or simple; and radii are axis-aligned ### Example
### See Also isEmpty isRect isOval isSimple isComplex --- ## isComplex
inline bool isComplex() const
Returns true if isEmpty, isRect, isOval, isSimple, and isNinePatch return false. If true: width and height are greater than zero, at least one corner radii are both greater than zero; left x-axis radii are not equal, or right x-axis radii are not equal, or top y-axis radii are not equal, or bottom y-axis radii are not equal. ### Return Value true if not empty, rect, oval, simple, or nine-patch ### Example
### See Also isEmpty isRect isOval isSimple isNinePatch --- ## width
SkScalar width() const
Returns span on the x-axis. This does not check if result fits in 32-bit float; result may be infinity. ### Return Value bounds().fRight minus bounds().fLeft ### Example
SkRRect::MakeRect sorts its input, so width is always zero or larger.
#### Example Output ~~~~ unsorted width: 5 large width: inf ~~~~
### See Also SkRect::width height getBounds --- ## height
SkScalar height() const
Returns span on the y-axis. This does not check if result fits in 32-bit float; result may be infinity. ### Return Value bounds().fBottom minus bounds().fTop ### Example
SkRRect::MakeRect sorts its input, so height is always zero or larger.
#### Example Output ~~~~ unsorted height: 5 large height: inf ~~~~
### See Also SkRect.height width getBounds --- ## getSimpleRadii
SkVector getSimpleRadii() const
Returns top-left corner x-radii. If type returns kEmpty Type, kRect Type, kOval Type, or kSimple Type, returns a value representative of all corner radii. If type returns kNinePatch Type or kComplex Type, at least one of the remaining three corners has a different value. ### Return Value corner radii for simple types ### Example
### See Also radii getBounds getType isSimple --- ## setEmpty
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. ### Example
Nothing blue is drawn because rrect is set to empty.
### See Also MakeEmpty setRect --- ## setRect
void setRect(const SkRect& 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
### Example
### See Also MakeRect setRectXY --- ## MakeEmpty
static SkRRect MakeEmpty()
Initializes bounds at (0, 0), the origin, with zero width and height. Initializes corner radii to (0, 0), and sets type of kEmpty Type. ### Return Value empty Round Rect ### Example
### See Also SkRRect() SkRect::MakeEmpty --- ## MakeRect
static SkRRect MakeRect(const SkRect& r)
Initializes to copy of r bounds and zeroes corner radii. ### Parameters
r bounds to copy
### Return Value copy of r ### Example
### See Also setRect MakeOval MakeRectXY --- ## MakeOval
static SkRRect MakeOval(const SkRect& oval)
Sets bounds to oval, x-axis radii to half oval.width, and all y-axis radii to half oval.height. If rect is empty, sets to kEmpty Type. Otherwise, sets to kOval Type. ### Parameters
oval bounds of Oval
### Return Value Oval ### Example
### See Also setOval MakeRect MakeRectXY --- ## MakeRectXY
static SkRRect MakeRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad)
Sets to rounded rectangle with the same radii for all four corners. If rect is empty, sets to kEmpty Type. Otherwise, if xRad and yRad are zero, sets to kRect Type. Otherwise, if xRad is at least half rect.width and yRad is at least half rect.height, sets to kOval Type. Otherwise, sets to kSimple Type. ### Parameters
rect bounds of rounded rectangle
xRad x-axis radius of corners
yRad y-axis radius of corners
### Return Value rounded rectangle ### Example
### See Also setRectXY --- ## setOval
void setOval(const SkRect& oval)
Sets bounds to oval, x-axis radii to half oval.width, and all y-axis radii to half oval.height. If rect is empty, sets to kEmpty Type. Otherwise, sets to kOval Type. ### Parameters
oval bounds of Oval
### Example
### See Also MakeOval --- ## setRectXY
void setRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad)
Sets to rounded rectangle with the same radii for all four corners. If rect is empty, sets to kEmpty Type. Otherwise, if xRad or yRad is zero, sets to kRect Type. Otherwise, if xRad is at least half rect.width and yRad is at least half rect.height, sets to kOval Type. Otherwise, sets to kSimple Type. ### Parameters
rect bounds of rounded rectangle
xRad x-axis radius of corners
yRad y-axis radius of corners
### Example
### See Also MakeRectXY SkPath::addRoundRect[2] --- ## setNinePatch
void setNinePatch(const SkRect& rect, SkScalar leftRad, SkScalar topRad, SkScalar rightRad,
                  SkScalar 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 kOval Type. Otherwise, if leftRad and rightRad are equal, and topRad and bottomRad are equal, sets to kSimple Type. Otherwise, sets to kNinePatch 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
### Example
### See Also setRectRadii --- ## setRectRadii
void setRectRadii(const SkRect& rect, const SkVector radii[4])
Sets bounds to rect. Sets radii array for individual control of all for corners. If rect is empty, sets to kEmpty Type. Otherwise, if one of each corner radii are zero, sets to kRect Type. Otherwise, if all x-axis radii are equal and at least half rect.width, and all y-axis radii are equal at least half rect.height, sets to kOval Type. Otherwise, if all x-axis radii are equal, and all y-axis radii are equal, sets to kSimple Type. Otherwise, sets to kNinePatch Type. ### Parameters
rect bounds of rounded rectangle
radii corner x-axis and y-axis radii
### Example
### See Also setNinePatch SkPath::addRoundRect[2] --- ## Enum SkRRect::Corner
    enum Corner {
        kUpperLeft Corner,
        kUpperRight Corner,
        kLowerRight Corner,
        kLowerLeft Corner,
    };
The radii are stored: top-left, top-right, bottom-right, bottom-left. ### Constants
Const Value Description
SkRRect::kUpperLeft_Corner 0 index of top-left corner radii
SkRRect::kUpperRight_Corner 1 index of top-right corner radii
SkRRect::kLowerRight_Corner 2 index of bottom-right corner radii
SkRRect::kLowerLeft_Corner 3 index of bottom-left corner radii
### Example
### See Also radii ## rect
const SkRect& rect() const
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. ### Return Value bounding box ### Example
#### Example Output ~~~~ left bounds: (nan) 0 left bounds: (inf) 0 left bounds: (100) 60 left bounds: (50) 50 left bounds: (25) 25 ~~~~
### See Also getBounds --- ## radii
SkVector radii(Corner corner) const
Returns Scalar pair for radius of curve on x-axis and y-axis for one corner. Both radii may be zero. If not zero, both are positive and finite. ### Parameters
corner one of: kUpperLeft Corner, kUpperRight Corner, kLowerRight Corner, kLowerLeft Corner
### Return Value x-axis and y-axis radii for one corner ### Example
Finite values are scaled proportionately to fit; other values are set to zero. Scaled values cannot be larger than 25, half the bounding rect width. Small scaled values are halved to scale in proportion to the y-axis corner radius, which is twice the bounds height.
#### Example Output ~~~~ left corner: (nan) 0 left corner: (inf) 0 left corner: (100) 25 left corner: (50) 25 left corner: (25) 12.5 ~~~~
### See Also Corner --- ## getBounds
const SkRect& getBounds() const
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 rect. ### Return Value bounding box ### Example
### See Also rect --- ## operator==
bool operator==(const SkRRect& a, const SkRRect& b)
Returns true if bounds and radii in a are equal to bounds and radii in b. a and b are not equal if either contain NaN. a and b are equal if members contain zeroes width different signs. ### Parameters
a Rect bounds and radii to compare
b Rect bounds and radii to compare
### Return Value true if members are equal ### Example
### See Also operator!=(const SkRRect& a, const SkRRect& b) --- ## operator!=
bool operator!=(const SkRRect& a, const SkRRect& b)
Returns true if bounds and radii in a are not equal to bounds and radii in b. a and b are not equal if either contain NaN. a and b are equal if members contain zeroes width different signs. ### Parameters
a Rect bounds and radii to compare
b Rect bounds and radii to compare
### Return Value true if members are not equal ### Example
### See Also operator==(const SkRRect& a, const SkRRect& b) --- ## inset
void inset(SkScalar dx, SkScalar dy, SkRRect* dst) const
Calls inset on the bounds, and adjust the radii to reflect what happens. If the corner is sharp (no curvature), leave it alone, otherwise we grow/shrink the radii by the amount of the inset. If a given radius becomes negative, it is pinned to 0. If the inset amount is larger than the width/height then the rrect collapses to a degenerate line or point. If the inset is sufficiently negative to cause the bounds to become infinite then the result is a default initialized rrect. It is valid for dst == this. ### Parameters
dx added to rect.fLeft, and subtracted from rect.fRight
dy added to rect.fTop, and subtracted from rect.fBottom
dst insets bounds and radii
### Example
### See Also outset[2] offset makeOffset ---
void inset(SkScalar dx, SkScalar dy)
### Parameters
dx added to rect.fLeft, and subtracted from rect.fRight
dy added to rect.fTop, and subtracted from rect.fBottom
### Example
### See Also outset[2] offset makeOffset --- ## outset
void outset(SkScalar dx, SkScalar dy, SkRRect* dst) const
Call outset on the bounds, and adjust the radii to reflect what happens in stroking. If the corner is sharp (no curvature), leave it alone, otherwise we grow/shrink the radii by the amount of the inset. If a given radius becomes negative, it is pinned to 0. It is valid for dst == this. ### Parameters
dx subtracted from rect.fLeft, and added to rect.fRight
dy subtracted from rect.fTop, and added to rect.fBottom
dst outset bounds and radii
### Example
### See Also inset[2] offset makeOffset ---
void outset(SkScalar dx, SkScalar dy)
### Parameters
dx subtracted from rect.fLeft, and added to rect.fRight
dy subtracted from rect.fTop, and added to rect.fBottom
### Example
### See Also inset[2] offset makeOffset --- ## offset
void offset(SkScalar dx, SkScalar dy)
Translates the rrect by (dx, dy). ### Parameters
dx offset added to rect.fLeft and rect.fRight
dy offset added to rect.fTop and rect.fBottom
### Example
### See Also makeOffset inset[2] outset[2] --- ## makeOffset
SkRRect SK_WARN_UNUSED_RESULT makeOffset(SkScalar dx, SkScalar dy) const
### Parameters
dx offset added to rect.fLeft and rect.fRight
dy offset added to rect.fTop and rect.fBottom
### Return Value Round Rect bounds offset by (dx, dy), with unchanged corner radii ### Example
### See Also offset inset[2] outset[2] --- ## contains
bool contains(const SkRect& rect) const
Returns true if rect is inside the bounds and corner radii, and if Round Rect and rect are not empty. ### Parameters
rect area tested for containment
### Return Value true if Round Rect contains rect ### Example
### See Also SkRect::contains[2][3] --- ## isValid
bool isValid() const
### Return Value incomplete ### Example
### See Also incomplete --- ### Constants
Const Value Description
SkRRect::kSizeInMemory 48 ### Example
incomplete
## writeToMemory
size_t writeToMemory(void* buffer) const
Write the rrect into the specified buffer. This is guaranteed to always write kSizeInMemory bytes, and that value is guaranteed to always be a multiple of 4. Return kSizeInMemory. ### Parameters
buffer incomplete
### Return Value incomplete ### Example
### See Also incomplete --- ## readFromMemory
size_t readFromMemory(const void* buffer, size_t length)
Reads the rrect from the specified buffer. If the specified buffer is large enough, this will read kSizeInMemory bytes, and that value is guaranteed to always be a multiple of 4. ### Parameters
buffer memory to read from
length amount of memory available in the buffer
### Return Value number of bytes read (must be a multiple of 4) or 0 if there was not enough memory available ### Example
### See Also incomplete --- ## transform
bool transform(const SkMatrix& matrix, SkRRect* dst) const
Transforms by Round Rect by matrix, storing result in dst. Returns true if Round Rect transformed can be represented by another Round Rect. Returns false if matrix contains transformations other than scale and translate. Asserts in debug builds if Round Rect equals dst. ### Parameters
matrix SkMatrix specifying the transform
dst SkRRect to store the result
### Return Value true if transformation succeeded. ### Example
### See Also incomplete --- ## dump
void dump(bool asHex) const
Writes text representation of Round Rect to standard output. Set asHex true to generate exact binary representations of floating point numbers. ### Parameters
asHex true if SkScalar values are written as hexadecimal
### Example
#### Example Output ~~~~ SkRect::MakeLTRB(0.857143f, 0.666667f, 0.857143f, 0.666667f); const SkPoint corners[] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, }; SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */ SkBits2Float(0x3f2aaaab), /* 0.666667 */ SkBits2Float(0x3f5b6db7), /* 0.857143 */ SkBits2Float(0x3f2aaaab) /* 0.666667 */); const SkPoint corners[] = { { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */ { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */ { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */ { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */ }; ~~~~
### See Also dumpHex SkRect::dump[2] SkPath::dump[2] SkPathMeasure::dump ---
void dump() const
Writes text representation of Round Rect to standard output. The representation may be directly compiled as C++ code. Floating point values are written with limited precision; it may not be possible to reconstruct original Round Rect from output. ### Example
#### Example Output ~~~~ SkRect::MakeLTRB(0.857143f, 0.666667f, 0.857143f, 0.666667f); const SkPoint corners[] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, }; rrect is not equal to copy ~~~~
### See Also dumpHex SkRect::dump[2] SkPath::dump[2] SkPathMeasure::dump --- ## dumpHex
void dumpHex() const
Writes text representation of Round Rect to standard output. The representation may be directly compiled as C++ code. Floating point values are written in hexadecimal to preserve their exact bit pattern. The output reconstructs the original Round Rect. ### Example
#### Example Output ~~~~ SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */ SkBits2Float(0x3f2aaaab), /* 0.666667 */ SkBits2Float(0x3f5b6db7), /* 0.857143 */ SkBits2Float(0x3f2aaaab) /* 0.666667 */); const SkPoint corners[] = { { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */ { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */ { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */ { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */ }; rrect is equal to copy ~~~~
### See Also dump[2] SkRect::dumpHex SkPath::dumpHex ---