Rect
- class Rect
Rect
holds four float coordinates describing the upper and lower bounds of a rectangle.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.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
Returns true if a intersects b.
Overloaded function.
Returns constructed
Rect
set to (0, 0, 0, 0).Returns constructed
Rect
set to integer values (0, 0, w, h).Returns constructed
Rect
set to (l, t, r, b).Returns constructed
Rect
set to (0, 0, size.width(), size.height()).Returns constructed
Rect
set toScalar
values (0, 0, w, h).Returns constructed
Rect
set to (x, y, x + w, y + h).Overloaded function.
Returns pointer to first scalar in
Rect
, to treat it as an array with four entries.Returns bottom edge of SkRect, if sorted.
Returns average of left edge and right edge.
Returns average of top edge and bottom edge.
Overloaded function.
Writes text representation of
Rect
to standard output.Writes text representation of
Rect
to standard output.Returns span on the y-axis.
Insets
Rect
by (dx, dy).Overloaded function.
Returns true if
Rect
intersects r.Returns true if fLeft is equal to or greater than fRight, or if fTop is equal to or greater than fBottom.
Returns true if all values in the rectangle are finite: SK_ScalarMin or larger, and SK_ScalarMax or smaller.
Returns true if fLeft is equal to or less than fRight, or if fTop is equal to or less than fBottom.
Sets
Rect
to the union of itself and r.Sets
Rect
to the union of itself and r.Sets
Rect
to the union of itself and the construction.Returns left edge of SkRect, if sorted.
Returns
Rect
, inset by (dx, dy).Overloaded function.
Returns
Rect
, outset by (dx, dy).Returns
Rect
with fLeft and fRight swapped if fLeft is greater than fRight; and with fTop and fBottom swapped if fTop is greater than fBottom.Overloaded function.
Offsets
Rect
so that fLeft equals newX, and fTop equals newY.Outsets
Rect
by (dx, dy).Returns right edge of SkRect, if sorted.
Returns
IRect
by adding 0.5 and discarding the fractional portion ofRect
members, using (SkScalarRoundToInt(fLeft)
,SkScalarRoundToInt(fTop)
,SkScalarRoundToInt(fRight)
,SkScalarRoundToInt(fBottom)
).Sets
Rect
by rounding up fLeft and fTop; and discarding the fractional portion of fRight and fBottom, using (SkScalarCeilToInt(fLeft)
,SkScalarCeilToInt(fTop)
,SkScalarFloorToInt(fRight)
,SkScalarFloorToInt(fBottom)
).Sets
IRect
by discarding the fractional portion of fLeft and fTop; and rounding up fRight and fBottom, using (SkScalarFloorToInt(fLeft)
,SkScalarFloorToInt(fTop)
,SkScalarCeilToInt(fRight)
,SkScalarCeilToInt(fBottom)
).Overloaded function.
Sets to bounds of
Point
array with count entries.Sets to bounds of
Point
array with count entries.Sets to bounds of
Point
pts array with count entries.Sets
Rect
to (0, 0, 0, 0).Sets
Rect
to (left, top, right, bottom).Sets
Rect
to (0, 0, width, height).Sets
Rect
to (x, y, x + width, y + height).Swaps fLeft and fRight if fLeft is greater than fRight; and swaps fTop and fBottom if fTop is greater than fBottom.
Returns four points in quad that enclose
Rect
ordered as: top-left, top-right, bottom-right, bottom-left.Returns top edge of SkRect, if sorted.
Returns span on the x-axis.
Returns left edge of
Rect
, if sorted.Returns top edge of SkRect, if sorted.
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
Rect
set 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
Rect
set 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
Rect
set 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
IRect
for an exact integer rectangle.
- static Rect.MakeLTRB(l: float, t: float, r: float, b: float) skia.Rect
Returns constructed
Rect
set to (l, t, r, b).Does not sort input;
Rect
may 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
Rect
set to (0, 0, size.width(), size.height()).Does not validate input; size.width() or size.height() may be negative.
- Parameters:
size – Scalar values for
Rect
width and height- Returns:
bounds (0, 0, size.width(), size.height())
- static Rect.MakeWH(w: float, h: float) skia.Rect
Returns constructed
Rect
set toScalar
values (0, 0, w, h).Does not validate input; w or h may be negative.
Passing integer values may generate a compiler warning since
Rect
cannot represent 32-bit integers exactly. UseIRect
for an exact integer rectangle.
- static Rect.MakeXYWH(x: float, y: float, w: float, h: float) skia.Rect
Returns constructed
Rect
set 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
Rect
set 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
Rect
set 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, andsort()
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
Rect
is 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
Rect
is 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
Rect
to 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
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
Rect
.Use instead of dump() when submitting
- Rect.inset(self: skia.Rect, dx: float, dy: float) None
Insets
Rect
by (dx, dy).If dx is positive, makes
Rect
narrower. If dx is negative, makesRect
wider. If dy is positive, makesRect
shorter. If dy is negative, makesRect
taller.- 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
Rect
intersects r.Returns false if either r or
Rect
is 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 negativewidth()
orheight()
.
- 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 negativewidth()
orheight()
.
- Rect.join(self: skia.Rect, r: skia.Rect) None
Sets
Rect
to the union of itself and r.Has no effect if r is empty. Otherwise, if
Rect
is empty, setsRect
to r.- Parameters:
r – expansion
Rect
- Rect.joinNonEmptyArg(self: skia.Rect, r: skia.Rect) None
Sets
Rect
to the union of itself and r.Asserts if r is empty and SK_DEBUG is defined. If
Rect
is empty, setsRect
to r.May produce incorrect results if r is empty.
- Parameters:
r – expansion
Rect
- Rect.joinPossiblyEmptyRect(self: skia.Rect, r: skia.Rect) None
Sets
Rect
to the union of itself and the construction.May produce incorrect results if
Rect
or 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. Callsort()
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,
Rect
returned is wider. If dx is positive,Rect
returned is narrower. If dy is negative,Rect
returned is taller. If dy is positive,Rect
returned is shorter.- Parameters:
dx – added to fLeft and subtracted from fRight
dy – added to fTop and subtracted from fBottom
- Returns:
Rect
inset symmetrically left and right, top and bottom
- Rect.makeOffset(*args, **kwargs)
Overloaded function.
makeOffset(self: skia.Rect, dx: float, dy: float) -> skia.Rect
Returns
Rect
offset by (dx, dy).If dx is negative,
Rect
returned is moved to the left. If dx is positive,Rect
returned is moved to the right. If dy is negative,Rect
returned is moved upward. If dy is positive,Rect
returned is moved downward.- dx:
added to fLeft and fRight
- dy:
added to fTop and fBottom
- return:
Rect
offset 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,
Rect
returned is narrower. If dx is positive,Rect
returned is wider. If dy is negative,Rect
returned is shorter. If dy is positive,Rect
returned is taller.- Parameters:
dx – subtracted to fLeft and added from fRight
dy – subtracted to fTop and added from fBottom
- Returns:
Rect
outset symmetrically left and right, top and bottom
- Rect.makeSorted(self: skia.Rect) skia.Rect
Returns
Rect
with 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()
andheight()
will be zero or positive.- Returns:
sorted
Rect
- Rect.offset(*args, **kwargs)
Overloaded function.
offset(self: skia.Rect, dx: float, dy: float) -> None
Offsets
Rect
by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.If dx is negative, moves
Rect
to the left. If dx is positive, movesRect
to the right. If dy is negative, movesRect
upward. If dy is positive, movesRect
downward.- dx:
offset added to fLeft and fRight
- dy:
offset added to fTop and fBottom
offset(self: skia.Rect, delta: skia.Point) -> None
Offsets
Rect
by adding delta.fX to fLeft, fRight; and by adding delta.fY to fTop, fBottom.If delta.fX is negative, moves
Rect
to the left. If delta.fX is positive, movesRect
to the right. If delta.fY is negative, movesRect
upward. If delta.fY is positive, movesRect
downward.- param delta:
added to
Rect
- Rect.offsetTo(self: skia.Rect, newX: float, newY: float) None
Offsets
Rect
so that fLeft equals newX, and fTop equals newY.width and height are unchanged.
- Rect.outset(self: skia.Rect, dx: float, dy: float) None
Outsets
Rect
by (dx, dy).If dx is positive, makes
Rect
wider. If dx is negative, makesRect
narrower. If dy is positive, makesRect
taller. If dy is negative, makesRect
shorter.- 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. Callsort()
to reverse fLeft and fRight if needed.- Returns:
fRight
- Rect.round(self: skia.Rect) skia.IRect
Returns
IRect
by adding 0.5 and discarding the fractional portion ofRect
members, using (SkScalarRoundToInt(fLeft)
,SkScalarRoundToInt(fTop)
,SkScalarRoundToInt(fRight)
,SkScalarRoundToInt(fBottom)
).- Returns:
rounded
IRect
- Rect.roundIn(self: skia.Rect) skia.IRect
Sets
Rect
by 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
IRect
by 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
Point
array with count entries.If count is zero or smaller, or if
Point
array 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 –
Point
array
- Rect.setBoundsCheck(self: skia.Rect, points: list[skia.Point]) bool
Sets to bounds of
Point
array with count entries.Returns false if count is zero or smaller, or if
Point
array contains an infinity or NaN; in these cases setsRect
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.
- Rect.setBoundsNoCheck(self: skia.Rect, points: list[skia.Point]) None
Sets to bounds of
Point
pts array with count entries.If any
Point
in pts contains infinity or NaN, allRect
dimensions are set to NaN.- Parameters:
points –
Point
array
- Rect.setEmpty(self: skia.Rect) None
Sets
Rect
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.
- Rect.setLTRB(self: skia.Rect, left: float, top: float, right: float, bottom: float) None
Sets
Rect
to (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
Rect
to (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
Rect
to (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()
andheight()
will be zero or positive.
- Rect.toQuad(self: skia.Rect) list[skia.Point]
Returns four points in quad that enclose
Rect
ordered 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, andsort()
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
Rect
is 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