Rect
- class Rect
- Rectholds four float coordinates describing the upper and lower bounds of a rectangle.- Rectmay be created from outer bounds or from position, width, and height.- Rectdescribes 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.- Example: - rect = skia.Rect(0, 0, 180, 120) rect = skia.Rect((0, 0, 180, 120)) # Convert from tuple print(rect.width(), rect.height()) left, top, right, bottom = tuple(rect) # Convert to tuple - Methods - Intersects(a: skia.Rect, b: skia.Rect) -> bool - MakeEmpty() -> skia.Rect - MakeIWH(w: int, h: int) -> skia.Rect - MakeLTRB(l: float, t: float, r: float, b: float) -> skia.Rect - MakeSize(size: skia.Size) -> skia.Rect - MakeWH(w: float, h: float) -> skia.Rect - MakeXYWH(x: float, y: float, w: float, h: float) -> skia.Rect - asScalars(self: skia.Rect) -> memoryview - bottom(self: skia.Rect) -> float - centerX(self: skia.Rect) -> float - centerY(self: skia.Rect) -> float - dump(self: skia.Rect, asHex: bool = False) -> None - dumpHex(self: skia.Rect) -> None - height(self: skia.Rect) -> float - inset(self: skia.Rect, dx: float, dy: float) -> None - intersects(self: skia.Rect, r: skia.Rect) -> bool - isEmpty(self: skia.Rect) -> bool - isFinite(self: skia.Rect) -> bool - isSorted(self: skia.Rect) -> bool - join(self: skia.Rect, r: skia.Rect) -> None - joinNonEmptyArg(self: skia.Rect, r: skia.Rect) -> None - joinPossiblyEmptyRect(self: skia.Rect, r: skia.Rect) -> None - left(self: skia.Rect) -> float - makeInset(self: skia.Rect, dx: float, dy: float) -> skia.Rect - makeOutset(self: skia.Rect, dx: float, dy: float) -> skia.Rect - makeSorted(self: skia.Rect) -> skia.Rect - offsetTo(self: skia.Rect, newX: float, newY: float) -> None - outset(self: skia.Rect, dx: float, dy: float) -> None - right(self: skia.Rect) -> float - round(self: skia.Rect) -> skia.IRect - roundIn(self: skia.Rect) -> skia.IRect - roundOut(self: skia.Rect) -> skia.IRect - setBounds(self: skia.Rect, points: list[skia.Point]) -> None - setBoundsCheck(self: skia.Rect, points: list[skia.Point]) -> bool - setBoundsNoCheck(self: skia.Rect, points: list[skia.Point]) -> None - setEmpty(self: skia.Rect) -> None - setIWH(self: skia.Rect, width: int, height: int) -> None - setLTRB(self: skia.Rect, left: float, top: float, right: float, bottom: float) -> None - setWH(self: skia.Rect, width: float, height: float) -> None - setXYWH(self: skia.Rect, x: float, y: float, width: float, height: float) -> None - sort(self: skia.Rect) -> None - toQuad(self: skia.Rect) -> list[skia.Point] - top(self: skia.Rect) -> float - width(self: skia.Rect) -> float - x(self: skia.Rect) -> float - y(self: skia.Rect) -> float - Attributes - larger y-axis bounds - smaller x-axis bounds - larger x-axis bounds - smaller y-axis bounds 
Methods
- static Rect.Intersects(a: skia.Rect, b: skia.Rect) bool
- Returns true if a intersects b. - Returns false if either a or b is empty, or do not intersect. 
- static Rect.Make(*args, **kwargs)
- Overloaded function. - Make(size: skia.ISize) -> skia.Rect 
- Make(irect: skia.IRect) -> skia.Rect - Returns constructed - Rectset to irect, promoting integers to scalar.- Does not validate input; fLeft may be greater than fRight, fTop may be greater than fBottom. - irect:
- integer unsorted bounds 
- return:
- irect members converted to Scalar 
 
 
- static Rect.MakeEmpty() skia.Rect
- Returns constructed - Rectset to (0, 0, 0, 0).- Many other rectangles are empty; if left is equal to or greater than right, or if top is equal to or greater than bottom. Setting all members to zero is a convenience, but does not designate a special empty rectangle. - Returns:
- bounds (0, 0, 0, 0) 
 
- static Rect.MakeIWH(w: int, h: int) skia.Rect
- Returns constructed - Rectset to integer values (0, 0, w, h).- Does not validate input; w or h may be negative. - Use to avoid a compiler warning that input may lose precision when stored. Use - IRectfor an exact integer rectangle.
- static Rect.MakeLTRB(l: float, t: float, r: float, b: float) skia.Rect
- Returns constructed - Rectset to (l, t, r, b).- Does not sort input; - Rectmay result in fLeft greater than fRight, or fTop greater than fBottom.- Parameters:
- l – Scalar stored in fLeft 
- t – Scalar stored in fTop 
- r – Scalar stored in fRight 
- b – Scalar stored in fBottom 
 
- Returns:
- bounds (l, t, r, b) 
 
- static Rect.MakeSize(size: skia.Size) skia.Rect
- Returns constructed - Rectset to (0, 0, size.width(), size.height()).- Does not validate input; size.width() or size.height() may be negative. - Parameters:
- size – Scalar values for - Rectwidth and height
- Returns:
- bounds (0, 0, size.width(), size.height()) 
 
- static Rect.MakeWH(w: float, h: float) skia.Rect
- Returns constructed - Rectset to- Scalarvalues (0, 0, w, h).- Does not validate input; w or h may be negative. - Passing integer values may generate a compiler warning since - Rectcannot represent 32-bit integers exactly. Use- IRectfor an exact integer rectangle.
- static Rect.MakeXYWH(x: float, y: float, w: float, h: float) skia.Rect
- Returns constructed - Rectset to (x, y, x + w, y + h).- Does not validate input; w or h may be negative. - Parameters:
- x – stored in fLeft 
- y – stored in fTop 
- w – added to x and stored in fRight 
- h – added to y and stored in fBottom 
 
- Returns:
- bounds at (x, y) with width w and height h 
 
- Rect.__init__(*args, **kwargs)
- Overloaded function. - __init__(self: skia.Rect) -> None - Returns constructed - Rectset to (0, 0, 0, 0).- Many other rectangles are empty; if left is equal to or greater than right, or if top is equal to or greater than bottom. Setting all members to zero is a convenience, but does not designate a special empty rectangle. - return:
- bounds (0, 0, 0, 0) 
 
- __init__(self: skia.Rect, w: float, h: float) -> None 
- __init__(self: skia.Rect, l: float, t: float, r: float, b: float) -> None 
- __init__(self: skia.Rect, size: skia.ISize) -> None 
- __init__(self: skia.Rect, irect: skia.IRect) -> None - Returns constructed - Rectset to irect, promoting integers to scalar.- Does not validate input; fLeft may be greater than fRight, fTop may be greater than fBottom. - irect:
- integer unsorted bounds 
- return:
- irect members converted to Scalar 
 
- __init__(self: skia.Rect, t: tuple) -> None 
 
- Rect.asScalars(self: skia.Rect) memoryview
- Returns pointer to first scalar in - Rect, to treat it as an array with four entries.- Returns:
- pointer to fLeft 
 
- Rect.bottom(self: skia.Rect) float
- Returns bottom edge of SkRect, if sorted. - Call - isEmpty()to see if SkRect may be invalid, and- sort()to reverse fTop and fBottom if needed.- Returns:
- fBottom 
 
- Rect.centerX(self: skia.Rect) float
- Returns average of left edge and right edge. - Result does not change if SkRect is sorted. Result may overflow to infinity if - Rectis far from the origin.- Returns:
- midpoint on x-axis 
 
- Rect.centerY(self: skia.Rect) float
- Returns average of top edge and bottom edge. - Result does not change if - Rectis sorted.- Returns:
- midpoint on y-axis 
 
- Rect.contains(*args, **kwargs)
- Overloaded function. - contains(self: skia.Rect, x: float, y: float) -> bool 
- contains(self: skia.Rect, r: skia.Rect) -> bool 
- contains(self: skia.Rect, r: skia.IRect) -> bool 
 
- Rect.dump(self: skia.Rect, asHex: bool = False) None
- Writes text representation of - Rectto standard output.- Set asHex to true to generate exact binary representations of floating point numbers. - Parameters:
- asHex – true if Scalar values are written as hexadecimal 
 
- Rect.dumpHex(self: skia.Rect) None
- Writes text representation of - Rectto 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 - Rect.- Use instead of dump() when submitting 
- Rect.inset(self: skia.Rect, dx: float, dy: float) None
- Insets - Rectby (dx, dy).- If dx is positive, makes - Rectnarrower. If dx is negative, makes- Rectwider. If dy is positive, makes- Rectshorter. If dy is negative, makes- Recttaller.- Parameters:
- dx – added to fLeft and subtracted from fRight 
- dy – added to fTop and subtracted from fBottom 
 
 
- Rect.intersect(*args, **kwargs)
- Overloaded function. - intersect(self: skia.Rect, r: skia.Rect) -> bool 
- intersect(self: skia.Rect, a: skia.Rect, b: skia.Rect) -> bool 
 
- Rect.intersects(self: skia.Rect, r: skia.Rect) bool
- Returns true if - Rectintersects r.- Returns false if either r or - Rectis empty, or do not intersect.
- Rect.isEmpty(self: skia.Rect) bool
- Returns true if fLeft is equal to or greater than fRight, or if fTop is equal to or greater than fBottom. - Call - sort()to reverse rectangles with negative- width()or- height().
- Rect.isFinite(self: skia.Rect) bool
- Returns true if all values in the rectangle are finite: SK_ScalarMin or larger, and SK_ScalarMax or smaller. - Returns:
- true if no member is infinite or NaN 
 
- Rect.isSorted(self: skia.Rect) bool
- Returns true if fLeft is equal to or less than fRight, or if fTop is equal to or less than fBottom. - Call - sort()to reverse rectangles with negative- width()or- height().
- Rect.join(self: skia.Rect, r: skia.Rect) None
- Sets - Rectto the union of itself and r.- Has no effect if r is empty. Otherwise, if - Rectis empty, sets- Rectto r.- Parameters:
- r – expansion - Rect
 
- Rect.joinNonEmptyArg(self: skia.Rect, r: skia.Rect) None
- Sets - Rectto the union of itself and r.- Asserts if r is empty and SK_DEBUG is defined. If - Rectis empty, sets- Rectto r.- May produce incorrect results if r is empty. - Parameters:
- r – expansion - Rect
 
- Rect.joinPossiblyEmptyRect(self: skia.Rect, r: skia.Rect) None
- Sets - Rectto the union of itself and the construction.- May produce incorrect results if - Rector r is empty.- Parameters:
- r – expansion - Rect
 
- Rect.left(self: skia.Rect) float
- Returns left edge of SkRect, if sorted. - Call - isSorted()to see if SkRect is valid. Call- sort()to reverse fLeft and fRight if needed.- Returns:
- fLeft 
 
- Rect.makeInset(self: skia.Rect, dx: float, dy: float) skia.Rect
- Returns - Rect, inset by (dx, dy).- If dx is negative, - Rectreturned is wider. If dx is positive,- Rectreturned is narrower. If dy is negative,- Rectreturned is taller. If dy is positive,- Rectreturned is shorter.- Parameters:
- dx – added to fLeft and subtracted from fRight 
- dy – added to fTop and subtracted from fBottom 
 
- Returns:
- Rectinset symmetrically left and right, top and bottom
 
- Rect.makeOffset(*args, **kwargs)
- Overloaded function. - makeOffset(self: skia.Rect, dx: float, dy: float) -> skia.Rect - Returns - Rectoffset by (dx, dy).- If dx is negative, - Rectreturned is moved to the left. If dx is positive,- Rectreturned is moved to the right. If dy is negative,- Rectreturned is moved upward. If dy is positive,- Rectreturned is moved downward.- dx:
- added to fLeft and fRight 
- dy:
- added to fTop and fBottom 
- return:
- Rectoffset on axes, with original width and height
 
- makeOffset(self: skia.Rect, v: skia.Point) -> skia.Rect 
 
- Rect.makeOutset(self: skia.Rect, dx: float, dy: float) skia.Rect
- Returns - Rect, outset by (dx, dy).- If dx is negative, - Rectreturned is narrower. If dx is positive,- Rectreturned is wider. If dy is negative,- Rectreturned is shorter. If dy is positive,- Rectreturned is taller.- Parameters:
- dx – subtracted to fLeft and added from fRight 
- dy – subtracted to fTop and added from fBottom 
 
- Returns:
- Rectoutset symmetrically left and right, top and bottom
 
- Rect.makeSorted(self: skia.Rect) skia.Rect
- Returns - Rectwith fLeft and fRight swapped if fLeft is greater than fRight; and with fTop and fBottom swapped if fTop is greater than fBottom.- Result may be empty; and - width()and- height()will be zero or positive.- Returns:
- sorted - Rect
 
- Rect.offset(*args, **kwargs)
- Overloaded function. - offset(self: skia.Rect, dx: float, dy: float) -> None - Offsets - Rectby adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.- If dx is negative, moves - Rectto the left. If dx is positive, moves- Rectto the right. If dy is negative, moves- Rectupward. If dy is positive, moves- Rectdownward.- dx:
- offset added to fLeft and fRight 
- dy:
- offset added to fTop and fBottom 
 
- offset(self: skia.Rect, delta: skia.Point) -> None - Offsets - Rectby adding delta.fX to fLeft, fRight; and by adding delta.fY to fTop, fBottom.- If delta.fX is negative, moves - Rectto the left. If delta.fX is positive, moves- Rectto the right. If delta.fY is negative, moves- Rectupward. If delta.fY is positive, moves- Rectdownward.- param delta:
- added to - Rect
 
 
- Rect.offsetTo(self: skia.Rect, newX: float, newY: float) None
- Offsets - Rectso that fLeft equals newX, and fTop equals newY.- width and height are unchanged. 
- Rect.outset(self: skia.Rect, dx: float, dy: float) None
- Outsets - Rectby (dx, dy).- If dx is positive, makes - Rectwider. If dx is negative, makes- Rectnarrower. If dy is positive, makes- Recttaller. If dy is negative, makes- Rectshorter.- Parameters:
- dx – subtracted to fLeft and added from fRight 
- dy – subtracted to fTop and added from fBottom 
 
 
- Rect.right(self: skia.Rect) float
- Returns right edge of SkRect, if sorted. - Call - isSorted()to see if SkRect is valid. Call- sort()to reverse fLeft and fRight if needed.- Returns:
- fRight 
 
- Rect.round(self: skia.Rect) skia.IRect
- Returns - IRectby adding 0.5 and discarding the fractional portion of- Rectmembers, using (- SkScalarRoundToInt(fLeft),- SkScalarRoundToInt(fTop),- SkScalarRoundToInt(fRight),- SkScalarRoundToInt(fBottom)).- Returns:
- rounded - IRect
 
- Rect.roundIn(self: skia.Rect) skia.IRect
- Sets - Rectby rounding up fLeft and fTop; and discarding the fractional portion of fRight and fBottom, using (- SkScalarCeilToInt(fLeft),- SkScalarCeilToInt(fTop),- SkScalarFloorToInt(fRight),- SkScalarFloorToInt(fBottom)).
- Rect.roundOut(self: skia.Rect) skia.IRect
- Sets - IRectby discarding the fractional portion of fLeft and fTop; and rounding up fRight and fBottom, using (- SkScalarFloorToInt(fLeft),- SkScalarFloorToInt(fTop),- SkScalarCeilToInt(fRight),- SkScalarCeilToInt(fBottom)).- Returns:
- rounded - IRect
 
- Rect.set(*args, **kwargs)
- Overloaded function. - set(self: skia.Rect, src: skia.IRect) -> None 
- set(self: skia.Rect, p0: skia.Point, p1: skia.Point) -> None 
 
- Rect.setBounds(self: skia.Rect, points: list[skia.Point]) None
- Sets to bounds of - Pointarray with count entries.- If count is zero or smaller, or if - Pointarray contains an infinity or NaN, sets to (0, 0, 0, 0).- Result is either empty or sorted: fLeft is less than or equal to fRight, and fTop is less than or equal to fBottom. - Parameters:
- points – - Pointarray
 
- Rect.setBoundsCheck(self: skia.Rect, points: list[skia.Point]) bool
- Sets to bounds of - Pointarray with count entries.- Returns false if count is zero or smaller, or if - Pointarray contains an infinity or NaN; in these cases sets- Rectto (0, 0, 0, 0).- Result is either empty or sorted: fLeft is less than or equal to fRight, and fTop is less than or equal to fBottom. 
- Rect.setBoundsNoCheck(self: skia.Rect, points: list[skia.Point]) None
- Sets to bounds of - Pointpts array with count entries.- If any - Pointin pts contains infinity or NaN, all- Rectdimensions are set to NaN.- Parameters:
- points – - Pointarray
 
- Rect.setEmpty(self: skia.Rect) None
- Sets - Rectto (0, 0, 0, 0).- Many other rectangles are empty; if left is equal to or greater than right, or if top is equal to or greater than bottom. Setting all members to zero is a convenience, but does not designate a special empty rectangle. 
- Rect.setLTRB(self: skia.Rect, left: float, top: float, right: float, bottom: float) None
- Sets - Rectto (left, top, right, bottom).- left and right are not sorted; left is not necessarily less than right. top and bottom are not sorted; top is not necessarily less than bottom. - Parameters:
- left – stored in fLeft 
- top – stored in fTop 
- right – stored in fRight 
- bottom – stored in fBottom 
 
 
- Rect.setWH(self: skia.Rect, width: float, height: float) None
- Sets - Rectto (0, 0, width, height).- Does not validate input; width or height may be negative. - Parameters:
- width – stored in fRight 
- height – stored in fBottom 
 
 
- Rect.setXYWH(self: skia.Rect, x: float, y: float, width: float, height: float) None
- Sets - Rectto (x, y, x + width, y + height).- Does not validate input; width or height may be negative. - Parameters:
- x – stored in fLeft 
- y – stored in fTop 
- width – added to x and stored in fRight 
- height – added to y and stored in fBottom 
 
 
- Rect.sort(self: skia.Rect) None
- Swaps fLeft and fRight if fLeft is greater than fRight; and swaps fTop and fBottom if fTop is greater than fBottom. - Result may be empty; and - width()and- height()will be zero or positive.
- Rect.toQuad(self: skia.Rect) list[skia.Point]
- Returns four points in quad that enclose - Rectordered as: top-left, top-right, bottom-right, bottom-left.- Returns:
- corners of - Rect
 
- Rect.top(self: skia.Rect) float
- Returns top edge of SkRect, if sorted. - Call - isEmpty()to see if SkRect may be invalid, and- sort()to reverse fTop and fBottom if needed.- Returns:
- fTop 
 
- Rect.width(self: skia.Rect) float
- Returns span on the x-axis. - This does not check if - Rectis sorted, or if result fits in 32-bit float; result may be negative or infinity.- Returns:
- fRight minus fLeft 
 
Attributes
- Rect.fBottom
- larger y-axis bounds 
- Rect.fLeft
- smaller x-axis bounds 
- Rect.fRight
- larger x-axis bounds 
- Rect.fTop
- smaller y-axis bounds