Rectangle#
- class Rectangle(*args, **kwargs)#
A GdkRectangle
data type for representing rectangles.
GdkRectangle
is identical to cairo_rectangle_t
. Together with Cairo’s
cairo_region_t
data type, these are the central types for representing
sets of pixels.
The intersection of two rectangles can be computed with
intersect
; to find the union of two rectangles use
union
.
The cairo_region_t
type provided by Cairo is usually used for managing
non-rectangular clipping of graphical operations.
The Graphene library has a number of other data types for regions and volumes in 2D and 3D.
Methods#
- class Rectangle
- contains_point(x: int, y: int) bool #
Returns
True
ifrect
contains the point described byx
andy
.- Parameters:
x – X coordinate
y – Y coordinate
- equal(rect2: Rectangle) bool #
Checks if the two given rectangles are equal.
- Parameters:
rect2 – a
GdkRectangle
- intersect(src2: Rectangle) tuple[bool, Rectangle] #
Calculates the intersection of two rectangles.
It is allowed for
dest
to be the same as eithersrc1
orsrc2
. If the rectangles do not intersect,dest
’s width and height is set to 0 and its x and y values are undefined. If you are only interested in whether the rectangles intersect, but not in the intersecting area itself, passNone
fordest
.- Parameters:
src2 – a
GdkRectangle
- union(src2: Rectangle) Rectangle #
Calculates the union of two rectangles.
The union of rectangles
src1
andsrc2
is the smallest rectangle which includes bothsrc1
andsrc2
within it. It is allowed fordest
to be the same as eithersrc1
orsrc2
.Note that this function does not ignore ‘empty’ rectangles (ie. with zero width or height).
- Parameters:
src2 – a
GdkRectangle