IRect

class IRect

IRect holds four 32-bit integer coordinates describing the upper and lower bounds of a rectangle.

IRect may be created from outer bounds or from position, width, and height. IRect 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:

irect = skia.IRect(0, 0, 180, 120)
irect = skia.IRect((0, 0, 180, 120))  # Convert from tuple
print(irect.width(), irect.height())
left, top, right, bottom = tuple(irect)  # Convert to tuple

Methods

Intersects

Returns true if a intersects b.

MakeEmpty

Returns constructed IRect set to (0, 0, 0, 0).

MakeLTRB

Returns constructed IRect set to (l, t, r, b).

MakeSize

Returns constructed IRect set to (0, 0, size.width(), size.height()).

MakeWH

Returns constructed IRect set to (0, 0, w, h).

MakeXYWH

Returns constructed IRect set to: (x, y, x + w, y + h).

__init__

__init__(*args, **kwargs) Overloaded function.

adjust

Adjusts IRect by adding dL to fLeft, dT to fTop, dR to fRight, and dB to fBottom.

bottom

Returns bottom edge of IRect, if sorted.

contains

Overloaded function.

containsNoEmptyCheck

Returns true if IRect contains construction.

height

Returns span on the y-axis.

height64

Returns span on the y-axis.

inset

Insets IRect by (dx,dy).

intersect

Overloaded function.

isEmpty

Returns true if width() or height() are zero or negative.

isEmpty64

Returns true if fLeft is equal to or greater than fRight, or if fTop is equal to or greater than fBottom.

join

Sets IRect to the union of itself and r.

left

Returns left edge of IRect, if sorted.

makeInset

Returns IRect, inset by (dx, dy).

makeOffset

Overloaded function.

makeOutset

Returns IRect, outset by (dx, dy).

makeSorted

Returns IRect with fLeft and fRight swapped if fLeft is greater than fRight; and with fTop and fBottom swapped if fTop is greater than fBottom.

offset

Overloaded function.

offsetTo

Offsets IRect so that fLeft equals newX, and fTop equals newY.

outset

Outsets IRect by (dx, dy).

right

Returns right edge of IRect, if sorted.

setEmpty

Sets IRect to (0, 0, 0, 0).

setLTRB

Sets IRect to (left, top, right, bottom).

setWH

setXYWH

Sets IRect to: (x, y, x + width, y + height).

size

Returns spans on the x-axis and y-axis.

sort

Swaps fLeft and fRight if fLeft is greater than fRight; and swaps fTop and fBottom if fTop is greater than fBottom.

top

Returns top edge of IRect, if sorted.

topLeft

width

Returns span on the x-axis.

width64

Returns span on the x-axis.

x

Returns left edge of IRect, if sorted.

y

Returns top edge of IRect, if sorted.

Attributes

fBottom

larger y-axis bounds

fLeft

smaller x-axis bounds

fRight

larger x-axis bounds

fTop

smaller y-axis bounds

Methods

static IRect.Intersects(a: skia.IRect, b: skia.IRect) bool

Returns true if a intersects b.

Returns false if either a or b is empty, or do not intersect.

Parameters
  • aIRect to intersect

  • bIRect to intersect

Returns

true if a and b have area in common

static IRect.MakeEmpty() skia.IRect

Returns constructed IRect 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 IRect.MakeLTRB(l: int, t: int, r: int, b: int) skia.IRect

Returns constructed IRect set to (l, t, r, b).

Does not sort input; IRect may result in fLeft greater than fRight, or fTop greater than fBottom.

Parameters
  • l – integer stored in fLeft

  • t – integer stored in fTop

  • r – integer stored in fRight

  • b – integer stored in fBottom

Returns

bounds (l, t, r, b)

static IRect.MakeSize(size: skia.ISize) skia.IRect

Returns constructed IRect set to (0, 0, size.width(), size.height()).

Does not validate input; size.width() or size.height() may be negative.

Parameters

size – values for IRect width and height

Returns

bounds (0, 0, size.width(), size.height())

static IRect.MakeWH(w: int, h: int) skia.IRect

Returns constructed IRect set to (0, 0, w, h).

Does not validate input; w or h may be negative.

Parameters
  • w – width of constructed IRect

  • h – height of constructed IRect

Returns

bounds (0, 0, w, h)

static IRect.MakeXYWH(x: int, y: int, w: int, h: int) skia.IRect

Returns constructed IRect 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

IRect.__init__(*args, **kwargs)

__init__(*args, **kwargs) Overloaded function.

  1. __init__(self: skia.IRect) -> None

    Creates IRect 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)

  2. __init__(self: skia.IRect, w: int, h: int) -> None

    Returns constructed IRect set to (0, 0, w, h).

    Does not validate input; w or h may be negative.

    w

    width of constructed IRect

    h

    height of constructed IRect

    return

    bounds (0, 0, w, h)

  3. __init__(self: skia.IRect, l: int, t: int, r: int, b: int) -> None

    Creates IRect set to: (x, y, x + w, y + h).

    Does not validate input; w or h may be negative.

    l

    integer stored in fLeft

    t

    integer stored in fTop

    r

    integer stored in fRight

    b

    integer stored in fBottom

    return

    bounds (l, t, r, b)

  4. __init__(self: skia.IRect, t: tuple) -> None

IRect.adjust(self: skia.IRect, dL: int, dT: int, dR: int, dB: int) None

Adjusts IRect by adding dL to fLeft, dT to fTop, dR to fRight, and dB to fBottom.

If dL is positive, narrows IRect on the left. If negative, widens it on the left. If dT is positive, shrinks IRect on the top. If negative, lengthens it on the top. If dR is positive, narrows IRect on the right. If negative, widens it on the right. If dB is positive, shrinks IRect on the bottom. If negative, lengthens it on the bottom.

The resulting IRect is not checked for validity. Thus, if the resulting IRect left is greater than right, the IRect will be considered empty. Call sort() after this call if that is not the desired behavior.

Parameters
  • dL – offset added to fLeft

  • dT – offset added to fTop

  • dR – offset added to fRight

  • dB – offset added to fBottom

IRect.bottom(self: skia.IRect) int

Returns bottom edge of IRect, if sorted.

Call isEmpty() to see if IRect may be invalid, and sort() to reverse fTop and fBottom if needed.

Returns fBottom

IRect.contains(*args, **kwargs)

Overloaded function.

  1. contains(self: skia.IRect, x: int, y: int) -> bool

    Returns true if: fLeft <= x < fRight && fTop <= y < fBottom.

    Returns false if IRect is empty.

    Considers input to describe constructed IRect: (x, y, x + 1, y + 1) and returns true if constructed area is completely enclosed by IRect area.

    x

    test IPoint x-coordinate

    y

    test IPoint y-coordinate

    return

    true if (x, y) is inside IRect

  2. contains(self: skia.IRect, r: skia.IRect) -> bool

    Returns true if IRect contains r.

    Returns false if IRect is empty or r is empty.

    IRect contains r when IRect area completely includes r area.

    r

    IRect contained

    return

    true if all sides of IRect are outside r

  3. contains(self: skia.IRect, r: SkRect) -> bool

    Returns true if IRect contains r.

    Returns false if IRect is empty or r is empty.

    IRect contains r when IRect area completely includes r area.

    r

    Rect contained

    return

    true if all sides of IRect are outside r

IRect.containsNoEmptyCheck(self: skia.IRect, r: skia.IRect) bool

Returns true if IRect contains construction.

Asserts if IRect is empty or construction is empty, and if SK_DEBUG is defined.

Return is undefined if IRect is empty or construction is empty.

Parameters

rIRect contained

Returns

true if all sides of IRect are outside r

IRect.height(self: skia.IRect) int

Returns span on the y-axis.

This does not check if IRect is sorted, or if result fits in 32-bit signed integer; result may be negative.

Returns

fBottom minus fTop

IRect.height64(self: skia.IRect) int

Returns span on the y-axis.

This does not check if IRect is sorted, so the result may be negative. This is safer than calling height() since height() might overflow in its calculation.

Returns

fBottom minus fTop cast to int64_t

IRect.inset(self: skia.IRect, dx: int, dy: int) None

Insets IRect by (dx,dy).

If dx is positive, makes IRect narrower. If dx is negative, makes IRect wider. If dy is positive, makes IRect shorter. If dy is negative, makes IRect taller.

Parameters
  • dx – offset added to fLeft and subtracted from fRight

  • dy – offset added to fTop and subtracted from fBottom

IRect.intersect(*args, **kwargs)

Overloaded function.

  1. intersect(self: skia.IRect, r: skia.IRect) -> bool

    Returns true if IRect intersects r, and sets IRect to intersection.

    Returns false if IRect does not intersect r, and leaves IRect unchanged.

    Returns false if either r or IRect is empty, leaving IRect unchanged.

    r

    limit of result

    return

    true if r and IRect have area in common

  2. intersect(self: skia.IRect, a: skia.IRect, b: skia.IRect) -> bool

    Returns true if a intersects b, and sets IRect to intersection.

    Returns false if a does not intersect b, and leaves IRect unchanged.

    Returns false if either a or b is empty, leaving IRect unchanged.

    a

    IRect to intersect

    b

    IRect to intersect

    return

    true if a and b have area in common

IRect.isEmpty(self: skia.IRect) bool

Returns true if width() or height() are zero or negative.

Returns

true if width() or height() are zero or negative

IRect.isEmpty64(self: skia.IRect) 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 width64() or height64().

Returns

true if width64() or height64() are zero or negative

IRect.join(self: skia.IRect, r: skia.IRect) None

Sets IRect to the union of itself and r.

Has no effect if r is empty. Otherwise, if IRect is empty, sets IRect to r.

Parameters

r – expansion IRect

IRect.left(self: skia.IRect) int

Returns left edge of IRect, if sorted.

Call sort() to reverse fLeft and fRight if needed.

Returns

fLeft

IRect.makeInset(self: skia.IRect, dx: int, dy: int) skia.IRect

Returns IRect, inset by (dx, dy).

If dx is negative, IRect returned is wider. If dx is positive, IRect returned is narrower. If dy is negative, IRect returned is taller. If dy is positive, IRect returned is shorter.

Parameters
  • dx – offset added to fLeft and subtracted from fRight

  • dy – offset added to fTop and subtracted from fBottom

Returns

IRect inset symmetrically left and right, top and bottom

IRect.makeOffset(*args, **kwargs)

Overloaded function.

  1. makeOffset(self: skia.IRect, dx: int, dy: int) -> skia.IRect

    Returns IRect offset by (dx, dy).

    If dx is negative, IRect returned is moved to the left. If dx is positive, IRect returned is moved to the right. If dy is negative, IRect returned is moved upward. If dy is positive, IRect returned is moved downward.

    dx

    offset added to fLeft and fRight

    dy

    offset added to fTop and fBottom

    return

    IRect offset by dx and dy, with original width and height

  2. makeOffset(self: skia.IRect, offset: skia.IPoint) -> skia.IRect

    Returns IRect offset by (offset.x(), offset.y()).

    If offset.x() is negative, IRect returned is moved to the left. If offset.x() is positive, IRect returned is moved to the right. If offset.y() is negative, IRect returned is moved upward. If offset.y() is positive, IRect returned is moved downward.

    offset

    translation vector

    return

    IRect translated by offset, with original width and height

IRect.makeOutset(self: skia.IRect, dx: int, dy: int) skia.IRect

Returns IRect, outset by (dx, dy).

If dx is negative, IRect returned is narrower. If dx is positive, IRect returned is wider. If dy is negative, IRect returned is shorter. If dy is positive, IRect returned is taller.

Parameters
  • dx – offset subtracted to fLeft and added from fRight

  • dy – offset subtracted to fTop and added from fBottom

Returns

IRect outset symmetrically left and right, top and bottom

IRect.makeSorted(self: skia.IRect) skia.IRect

Returns IRect 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() and height() will be zero or positive.

Returns

sorted IRect

IRect.offset(*args, **kwargs)

Overloaded function.

  1. offset(self: skia.IRect, dx: int, dy: int) -> None

    Offsets IRect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.

    If dx is negative, moves IRect returned to the left. If dx is positive, moves IRect returned to the right. If dy is negative, moves IRect returned upward. If dy is positive, moves IRect returned downward.

    dx

    offset added to fLeft and fRight

    dy

    offset added to fTop and fBottom

  2. offset(self: skia.IRect, delta: skia.IPoint) -> None

    Offsets IRect by adding delta.fX to fLeft, fRight; and by adding delta.fY to fTop, fBottom.

    If delta.fX is negative, moves IRect returned to the left. If delta.fX is positive, moves IRect returned to the right. If delta.fY is negative, moves IRect returned upward. If delta.fY is positive, moves IRect returned downward.

    delta

    offset added to IRect

IRect.offsetTo(self: skia.IRect, newX: int, newY: int) None

Offsets IRect so that fLeft equals newX, and fTop equals newY.

width and height are unchanged.

Parameters
  • newX – stored in fLeft, preserving width()

  • newY – stored in fTop, preserving height()

IRect.outset(self: skia.IRect, dx: int, dy: int) None

Outsets IRect by (dx, dy).

If dx is positive, makes IRect wider. If dx is negative, makes IRect narrower. If dy is positive, makes IRect taller. If dy is negative, makes IRect shorter.

Parameters
  • dx – subtracted to fLeft and added from fRight

  • dy – subtracted to fTop and added from fBottom

IRect.right(self: skia.IRect) int

Returns right edge of IRect, if sorted.

Call sort() to reverse fLeft and fRight if needed.

Returns

fRight

IRect.setEmpty(self: skia.IRect) None

Sets IRect 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.

IRect.setLTRB(self: skia.IRect, left: int, top: int, right: int, bottom: int) None

Sets IRect 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

IRect.setWH(self: skia.IRect, width: int, height: int) None
IRect.setXYWH(self: skia.IRect, x: int, y: int, width: int, height: int) None

Sets IRect 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

IRect.size(self: skia.IRect) skia.ISize

Returns spans on the x-axis and y-axis.

IRect.sort(self: skia.IRect) 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.

IRect.top(self: skia.IRect) int

Returns top edge of IRect, if sorted.

Call isEmpty() to see if IRect may be invalid, and sort() to reverse fTop and fBottom if needed.

Returns

fTop

IRect.topLeft(self: skia.IRect) skia.IPoint
IRect.width(self: skia.IRect) int

Returns span on the x-axis.

This does not check if IRect is sorted, or if result fits in 32-bit signed integer; result may be negative.

Returns

fRight minus fLeft

IRect.width64(self: skia.IRect) int

Returns span on the x-axis.

This does not check if IRect is sorted, so the result may be negative. This is safer than calling width() since width() might overflow in its calculation.

Returns

fRight minus fLeft cast to int64_t

IRect.x(self: skia.IRect) int

Returns left edge of IRect, if sorted.

Call isEmpty() to see if IRect is valid, and sort() to reverse fLeft and fRight if needed.

Returns

fLeft

IRect.y(self: skia.IRect) int

Returns top edge of IRect, if sorted.

Call isEmpty() to see if IRect is invalid, and sort() to reverse fTop and fBottom if needed.

Returns

fTop

Attributes

IRect.fBottom

larger y-axis bounds

IRect.fLeft

smaller x-axis bounds

IRect.fRight

larger x-axis bounds

IRect.fTop

smaller y-axis bounds