IRect#

IRect 是一个矩形边界框,非常类似于 Rect,不同之处在于所有角坐标都是整数。IRect 用于指定像素区域,例如在渲染时接收图像数据。除此之外,关于矩形的空性和有效性等考虑也适用于此类。方法和属性名称相同,并且在许多情况下通过重复使用相应的 Rect 对应项来实现。

属性 / 方法

简短描述

IRect.contains()

检查是否包含另一个对象

IRect.get_area()

计算矩形面积

IRect.intersect()

与另一个矩形的公共部分

IRect.intersects()

检查是否存在非空交集

IRect.morph()

使用点和矩阵进行变换

IRect.torect()

转换为另一个矩形的矩阵

IRect.norm()

欧几里得范数

IRect.normalize()

使矩形有限

IRect.bottom_left

左下角点,别名 bl

IRect.bottom_right

右下角点,别名 br

IRect.height

矩形的高度

IRect.is_empty

矩形是否为空

IRect.is_infinite

矩形是否是无限的

IRect.rect

相应的 Rect

IRect.top_left

左上角点,别名 tl

IRect.top_right

右上角点,别名 tr

IRect.quad

从矩形角点构造的 Quad

IRect.width

矩形的宽度

IRect.x0

左上角的 X 坐标

IRect.x1

右下角的 X 坐标

IRect.y0

左上角的 Y 坐标

IRect.y1

右下角的 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_likepoint_like 或数字。如果 x 是一个空矩形,始终返回真。相反,如果矩形为空,则始终返回 False,如果 x 不是空矩形并且不是数字。如果 x 是数字,将检查其是否为四个组件之一。x in irectirect.contains(x) 是等效的。

参数:

x (IRectRectPoint 或 int) – 要检查的对象。

返回类型:

bool

intersects(r)#

检查矩形与 rect_like “r” 是否包含一个公共的非空 IRect。如果任一矩形是无限的或为空,则始终返回 False

参数:

r (rect_like) – 要检查的矩形。

返回类型:

bool

torect(rect)#
  • 新增于 v1.19.3

计算将此矩形转换为给定矩形的矩阵。参见 Rect.torect()

参数:

rect (rect_like) – 目标矩形。不得为空或无限。

返回类型:

Matrix

返回:

一个矩阵 mat,使得 self * mat = rect。例如,可以用于在页面坐标和像素图坐标之间进行转换。

morph(fixpoint, matrix)#
  • 新增于 v1.17.0

在使用固定点应用矩阵后返回一个新的四边形(quad)。

参数:
  • fixpoint (point_like) – 固定点。

  • matrix (matrix_like) – 矩阵。

返回:

一个新的 Quad。这是同名四边形方法的封装。如果是无限的,将返回无限四边形。

norm()#
  • 新增于 v1.16.0

返回矩形的欧几里得范数,将矩形视为由四个数字组成的向量。

normalize()#

使矩形变为有限。通过调整矩形的角点来完成此操作。完成后,右下角将确实位于左上角的南东方向。更多细节请参见 Rect

top_left#
tl#

等同于 Point(x0, y0)

Type:

Point

top_right#
tr#

等同于 Point(x1, y0)

Type:

Point

bottom_left#
bl#

等同于 Point(x0, y1)

Type:

Point

bottom_right#
br#

等同于 Point(x1, y1)

Type:

Point

rect#

与矩形具有相同坐标的 Rect,坐标为浮动点。

Type:

Rect

quad#

四边形 Quad(irect.tl, irect.tr, irect.bl, irect.br)

Type:

Quad

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

备注

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

IRect.contains()

checks containment of another object

IRect.get_area()

calculate rectangle area

IRect.intersect()

common part with another rectangle

IRect.intersects()

checks for non-empty intersection

IRect.morph()

transform with a point and a matrix

IRect.torect()

matrix that transforms to another rectangle

IRect.norm()

the Euclidean norm

IRect.normalize()

makes a rectangle finite

IRect.bottom_left

bottom left point, synonym bl

IRect.bottom_right

bottom right point, synonym br

IRect.height

height of the rectangle

IRect.is_empty

whether rectangle is empty

IRect.is_infinite

whether rectangle is infinite

IRect.rect

the Rect equivalent

IRect.top_left

top left point, synonym tl

IRect.top_right

top_right point, synonym tr

IRect.quad

Quad made from rectangle corners

IRect.width

width of the rectangle

IRect.x0

X-coordinate of the top left corner

IRect.x1

X-coordinate of the bottom right corner

IRect.y0

Y-coordinate of the top left corner

IRect.y1

Y-coordinate of the bottom right corner

Class API

备注


本软件按原样提供,不作任何明示或暗示担保。本软件根据许可分发,除非根据该许可条款明确授权,否则不得复制、修改或分发。请参阅 artifex.com 上的许可信息,或联系 Artifex Software Inc., 39 Mesa Street, Suite 108A, San Francisco CA 94129, United States 了解更多信息。