IRect#
IRect is a rectangular bounding box, very similar to Rect, except that all corner coordinates are integers. IRect is used to specify an area of pixels, e.g. to receive image data during rendering. Otherwise, e.g. considerations concerning emptiness and validity of rectangles also apply to this class. Methods and attributes have the same names, and in many cases are implemented by reusing the respective Rect counterparts.
Attribute / Method 
Short Description 

checks containment of another object 

calculate rectangle area 

common part with another rectangle 

checks for nonempty intersection 

transform with a point and a matrix 

matrix that transforms to another rectangle 

the Euclidean norm 

makes a rectangle finite 

bottom left point, synonym bl 

bottom right point, synonym br 

height of the rectangle 

whether rectangle is empty 

whether rectangle is infinite 

the Rect equivalent 

top left point, synonym tl 

top_right point, synonym tr 

Quad made from rectangle corners 

width of the rectangle 

Xcoordinate of the top left corner 

Xcoordinate of the bottom right corner 

Ycoordinate of the top left corner 

Ycoordinate of the bottom right corner 
Class API
 class IRect#
 __init__(self)#
 __init__(self, x0, y0, x1, y1)#
 __init__(self, irect)#
 __init__(self, sequence)#
Overloaded constructors. Also see examples below and those for the Rect class.
If another irect is specified, a new copy will be made.
If sequence is specified, it must be a Python sequence type of 4 numbers (see Using Python Sequences as Arguments in PyMuPDF). Noninteger numbers will be truncated, nonnumeric values will raise an exception.
The other parameters mean integer coordinates.
 get_area([unit])#
Calculates the area of the rectangle and, with no parameter, equals abs(IRect). Like an empty rectangle, the area of an infinite rectangle is also zero.
 Parameters:
unit (str) – Specify required unit: respective squares of “px” (pixels, default), “in” (inches), “cm” (centimeters), or “mm” (millimeters).
 Return type:
float
 intersect(ir)#
The intersection (common rectangular area) of the current rectangle and ir is calculated and replaces the current rectangle. If either rectangle is empty, the result is also empty. If either rectangle is infinite, the other one is taken as the result – and hence also infinite if both rectangles were infinite.
 Parameters:
ir (rect_like) – Second rectangle.
 contains(x)#
Checks whether x is contained in the rectangle. It may be
rect_like
,point_like
or a number. If x is an empty rectangle, this is always true. Conversely, if the rectangle is empty this is always False, if x is not an empty rectangle and not a number. If x is a number, it will be checked to be one of the four components. x in irect and irect.contains(x) are equivalent.
 intersects(r)#
Checks whether the rectangle and the
rect_like
“r” contain a common nonempty IRect. This will always be False if either is infinite or empty. Parameters:
r (rect_like) – the rectangle to check.
 Return type:
bool
 torect(rect)#
New in version 1.19.3
Compute the matrix which transforms this rectangle to a given one. See
Rect.torect()
. Parameters:
rect (rect_like) – the target rectangle. Must not be empty or infinite.
 Return type:
 Returns:
a matrix
mat
such thatself * mat = rect
. Can for example be used to transform between the page and the pixmap coordinates.
 morph(fixpoint, matrix)#
New in version 1.17.0
Return a new quad after applying a matrix to it using a fixed point.
 Parameters:
fixpoint (point_like) – the fixed point.
matrix (matrix_like) – the matrix.
 Returns:
a new Quad. This a wrapper of the samenamed quad method. If infinite, the infinite quad is returned.
 norm()#
New in version 1.16.0
Return the Euclidean norm of the rectangle treated as a vector of four numbers.
 normalize()#
Make the rectangle finite. This is done by shuffling rectangle corners. After this, the bottom right corner will indeed be southeastern to the top left one. See Rect for a more details.
 top_left#
 top_right#
 bottom_left#
 bottom_right#
 width#
Contains the width of the bounding box. Equals abs(x1  x0).
 Type:
int
 height#
Contains the height of the bounding box. Equals abs(y1  y0).
 Type:
int
 x0#
Xcoordinate of the left corners.
 Type:
int
 y0#
Ycoordinate of the top corners.
 Type:
int
 x1#
Xcoordinate of the right corners.
 Type:
int
 y1#
Ycoordinate of the bottom corners.
 Type:
int
 is_infinite#
True if rectangle is infinite, False otherwise.
 Type:
bool
 is_empty#
True if rectangle is empty, False otherwise.
 Type:
bool
Note
This class adheres to the Python sequence protocol, so components can be accessed via their index, too. Also refer to Using Python Sequences as Arguments in PyMuPDF.
Rectangles can be used with arithmetic operators – see chapter Operator Algebra for Geometry Objects.
This software is provided ASIS with no warranty, either express or implied. This software is distributed under license and may not be copied, modified or distributed except as expressly authorized under the terms of that license. Refer to licensing information at artifex.com or contact Artifex Software Inc., 39 Mesa Street, Suite 108A, San Francisco CA 94129, United States for further information.