Region

Region — Representing a pixel-aligned area

class Region()

class cairo.Region(rectangle: RectangleInt | List[RectangleInt])

Region is a simple graphical data type representing an area of integer-aligned rectangles. They are often used on raster surfaces to track areas of interest, such as change or clip areas.

New in version 1.11.0.

__init__(rectangle: RectangleInt | List[RectangleInt]) None
Parameters:

rectangle_int – a rectangle or a list of rectangle

Allocates a new empty region object or a region object with the containing rectangle(s).

copy() Region
Returns:

A newly allocated Region.

Allocates a new Region object copying the area from original.

get_extents() RectangleInt
Returns:

The bounding rectangle of region

num_rectangles() int
Returns:

The number of rectangles contained in region

get_rectangle(nth: int) RectangleInt
Parameters:

nth – a number indicating which rectangle should be returned

Returns:

The nth rectangle from the region

is_empty() bool
Returns:

Whether region is empty

contains_point(x: int, y: int) bool
Parameters:
  • x – The x coordinate of a point

  • y – The y coordinate of a point

Returns:

Whether (x , y) is contained in the region

contains_rectangle(rectangle: RectangleInt) RegionOverlap
Parameters:

rectangle – a region

Returns:

region overlap

Checks whether rectangle is inside, outside or partially contained in region

equal(region: Region) bool
Parameters:

region – a region

Returns:

Whether both regions contained the same coverage

translate(dx: int, dy: int) None
Parameters:
  • dx – Amount to translate in the x direction

  • dy – Amount to translate in the y direction

Translates region by (dx , dy ).

intersect(other: Region | RectangleInt) Region
Parameters:

other – region or rectangle

Returns:

The intersection of the region and the passed region or rectangle

subtract(other: Region | RectangleInt) Region
Parameters:

other – region or rectangle

Returns:

The result of the subtraction of the region and the passed region or rectangle

union(other: Region | RectangleInt) Region
Parameters:

other – region or rectangle

Returns:

The union of the region and the passed region or rectangle

xor(other: Region | RectangleInt) Region
Parameters:

other – region or rectangle

Returns:

The exclusive difference of the region and the passed region or rectangle

class RectangleInt()

class cairo.RectangleInt(x: int = 0, y: int = 0, width: int = 0, height: int = 0)

RectangleInt is a data structure for holding a rectangle with integer coordinates.

New in version 1.11.0.

__init__(x: int = 0, y: int = 0, width: int = 0, height: int = 0) None
Parameters:
  • x – X coordinate of the left side of the rectangle.

  • y – Y coordinate of the top side of the rectangle.

  • width – Width of the rectangle.

  • height – Height of the rectangle.

Allocates a new RectangleInt object.

height: int = Ellipsis
width: int = Ellipsis
x: int = Ellipsis
y: int = Ellipsis