IRect#
IRect 是一个矩形边界框,非常类似于 Rect,不同之处在于所有角坐标都是整数。IRect 用于指定像素区域,例如在渲染时接收图像数据。除此之外,关于矩形的空性和有效性等考虑也适用于此类。方法和属性名称相同,并且在许多情况下通过重复使用相应的 Rect 对应项来实现。
属性 / 方法 |
简短描述 |
---|---|
检查是否包含另一个对象 |
|
计算矩形面积 |
|
与另一个矩形的公共部分 |
|
检查是否存在非空交集 |
|
使用点和矩阵进行变换 |
|
转换为另一个矩形的矩阵 |
|
欧几里得范数 |
|
使矩形有限 |
|
左下角点,别名 bl |
|
右下角点,别名 br |
|
矩形的高度 |
|
矩形是否为空 |
|
矩形是否是无限的 |
|
相应的 Rect |
|
左上角点,别名 tl |
|
右上角点,别名 tr |
|
从矩形角点构造的 Quad |
|
矩形的宽度 |
|
左上角的 X 坐标 |
|
右下角的 X 坐标 |
|
左上角的 Y 坐标 |
|
右下角的 Y 坐标 |
Class API
- class IRect#
- __init__(self)#
- __init__(self, x0, y0, x1, y1)#
- __init__(self, irect)#
- __init__(self, sequence)#
重载构造函数。请参阅下面的示例以及 Rect 类的示例。
如果指定了另一个 irect,将创建一个 新副本。
如果指定了 sequence,它必须是一个包含 4 个数字的 Python 序列类型(参见 在 PyMuPDF 中使用 Python 序列作为参数)。非整数数字将被截断,非数字值将引发异常。
其他参数表示整数坐标。
- get_area([unit])#
计算矩形的面积,如果没有参数,则等于 abs(IRect)。像空矩形一样,无限矩形的面积也为零。
- 参数:
unit (str) – 指定所需的单位:分别为 “px”(像素,默认)、”in”(英寸)、”cm”(厘米)或 “mm”(毫米)。
- 返回类型:
float
- intersect(ir)#
计算当前矩形与 ir 的交集(公共矩形区域),并将其替换当前矩形。如果任一矩形为空,则结果也为空。如果任一矩形是无限的,则取另一个矩形作为结果——如果两个矩形都是无限的,则结果也是无限的。
- 参数:
ir (rect_like) – 第二个矩形。
- contains(x)#
检查 x 是否包含在矩形内。x 可以是
rect_like
、point_like
或数字。如果 x 是一个空矩形,始终返回真。相反,如果矩形为空,则始终返回 False,如果 x 不是空矩形并且不是数字。如果 x 是数字,将检查其是否为四个组件之一。x in irect 和 irect.contains(x) 是等效的。
- intersects(r)#
检查矩形与
rect_like
“r” 是否包含一个公共的非空 IRect。如果任一矩形是无限的或为空,则始终返回 False。- 参数:
r (rect_like) – 要检查的矩形。
- 返回类型:
bool
- torect(rect)#
新增于 v1.19.3
计算将此矩形转换为给定矩形的矩阵。参见
Rect.torect()
。- 参数:
rect (rect_like) – 目标矩形。不得为空或无限。
- 返回类型:
- 返回:
一个矩阵
mat
,使得self * mat = rect
。例如,可以用于在页面坐标和像素图坐标之间进行转换。
- morph(fixpoint, matrix)#
新增于 v1.17.0
在使用固定点应用矩阵后返回一个新的四边形(quad)。
- 参数:
fixpoint (point_like) – 固定点。
matrix (matrix_like) – 矩阵。
- 返回:
一个新的 Quad。这是同名四边形方法的封装。如果是无限的,将返回无限四边形。
- norm()#
新增于 v1.16.0
返回矩形的欧几里得范数,将矩形视为由四个数字组成的向量。
- top_left#
- top_right#
- bottom_left#
- bottom_right#
- width#
包含边界框的宽度。等于 abs(x1 - x0)。
- Type:
int
- height#
包含边界框的高度。等于 abs(y1 - y0)。
- Type:
int
- x0#
左上角的 X 坐标。
- Type:
int
- y0#
左上角的 Y 坐标。
- Type:
int
- x1#
右下角的 X 坐标。
- Type:
int
- y1#
右下角的 Y 坐标。
- Type:
int
- is_infinite#
如果矩形是无限的,则为 True,否则为 False。
- Type:
bool
- is_empty#
如果矩形是空的,则为 True,否则为 False。
- Type:
bool
备注
该类遵循 Python 序列协议,因此组件也可以通过索引访问。另请参见 在 PyMuPDF 中使用 Python 序列作为参数。
矩形可以与算术运算符一起使用 – 参见 几何对象的运算符代数 章节。
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 re-using the respective Rect counterparts.
Attribute / Method |
Short Description |
---|---|
checks containment of another object |
|
calculate rectangle area |
|
common part with another rectangle |
|
checks for non-empty 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 |
|
X-coordinate of the top left corner |
|
X-coordinate of the bottom right corner |
|
Y-coordinate of the top left corner |
|
Y-coordinate of the bottom right corner |
Class API
备注
This class adheres to the Python sequence protocol, so components can be accessed via their index, too. Also refer to 在 PyMuPDF 中使用 Python 序列作为参数.
Rectangles can be used with arithmetic operators – see chapter 几何对象的运算符代数.