File: irect.rst

package info (click to toggle)
pymupdf 1.17.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,956 kB
  • sloc: python: 3,967; sh: 38; makefile: 7
file content (207 lines) | stat: -rw-r--r-- 6,762 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
.. _IRect:

==========
IRect
==========

IRect is a rectangular bounding box similar to :ref:`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, many similarities exist, e.g. considerations concerning emptiness and finiteness of rectangles also apply to this class.

============================== ===========================================
**Attribute / Method**          **Short Description**
============================== ===========================================
:meth:`IRect.contains`         checks containment of another object
:meth:`IRect.getArea`          calculate rectangle area
:meth:`IRect.getRect`          return a :ref:`Rect` with same coordinates
:meth:`IRect.getRectArea`      calculate rectangle area
:meth:`IRect.intersect`        common part with another rectangle
:meth:`IRect.intersects`       checks for non-empty intersection
:meth:`IRect.morph`            transform with a point and a matrix
:meth:`IRect.norm`             the Euclidean norm
:meth:`IRect.normalize`        makes a rectangle finite
:attr:`IRect.bottom_left`      bottom left point, synonym *bl*
:attr:`IRect.bottom_right`     bottom right point, synonym *br*
:attr:`IRect.height`           height of the rectangle
:attr:`IRect.isEmpty`          whether rectangle is empty
:attr:`IRect.isInfinite`       whether rectangle is infinite
:attr:`IRect.rect`             equals result of method *getRect()*
:attr:`IRect.top_left`         top left point, synonym *tl*
:attr:`IRect.top_right`        top_right point, synonym *tr*
:attr:`IRect.quad`             :ref:`Quad` made from rectangle corners
:attr:`IRect.width`            width of the rectangle
:attr:`IRect.x0`               X-coordinate of the top left corner
:attr:`IRect.x1`               X-coordinate of the bottom right corner
:attr:`IRect.y0`               Y-coordinate of the top left corner
:attr:`IRect.y1`               Y-coordinate of the bottom right corner
============================== ===========================================

**Class API**

.. class:: IRect

   .. method:: __init__(self)

   .. method:: __init__(self, x0, y0, x1, y1)

   .. method:: __init__(self, irect)

   .. method:: __init__(self, sequence)

      Overloaded constructors. Also see examples below and those for the :ref:`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 :ref:`SequenceTypes`). Non-integer numbers will be truncated, non-numeric entries will raise an exception.

      The other parameters mean integer coordinates.

   .. method:: getRect()

      A convenience function returning a :ref:`Rect` with the same coordinates. Also available as attribute *rect*.

      :rtype: :ref:`Rect`

   .. method:: getRectArea([unit])

   .. method:: getArea([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.

      :arg str unit: Specify required unit: respective squares of "px" (pixels, default), "in" (inches), "cm" (centimeters), or "mm" (millimeters).

      :rtype: float

   .. method:: 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.

      :arg rect_like ir: Second rectangle.

   .. method:: contains(x)

      Checks whether *x* is contained in the rectangle. It may be :data:`rect_like`, :data:`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.

      :arg x: the object to check.
      :type x: :ref:`IRect` or :ref:`Rect` or :ref:`Point` or int

      :rtype: bool

   .. method:: intersects(r)

      Checks whether the rectangle and the :data:`rect_like` "r" contain a common non-empty :ref:`IRect`. This will always be *False* if either is infinite or empty.

      :arg rect_like r: the rectangle to check.

      :rtype: bool

   .. method:: morph(fixpoint, matrix)

      *(New in version 1.17.0)*
      
      Return a new quad after applying a matrix to it using a fixed point.

      :arg point_like fixpoint: the fixed point.
      :arg matrix_like matrix: the matrix.
      :returns: a new :ref:`Quad`. This a wrapper of the same-named quad method.

   .. method:: norm()

      *(New in version 1.16.0)*
      
      Return the Euclidean norm of the rectangle treated as a vector of four numbers.

   .. method:: normalize()

      Make the rectangle finite. This is done by shuffling rectangle corners. After this, the bottom right corner will indeed be south-eastern to the top left one. See :ref:`Rect` for a more details.

   .. attribute:: top_left

   .. attribute:: tl

      Equals *Point(x0, y0)*.

      :type: :ref:`Point`

   .. attribute:: top_right

   .. attribute:: tr

      Equals *Point(x1, y0)*.

      :type: :ref:`Point`

   .. attribute:: bottom_left

   .. attribute:: bl

      Equals *Point(x0, y1)*.

      :type: :ref:`Point`

   .. attribute:: bottom_right

   .. attribute:: br

      Equals *Point(x1, y1)*.

      :type: :ref:`Point`

   .. attribute:: quad

      The quadrilateral *Quad(irect.tl, irect.tr, irect.bl, irect.br)*.

      :type: :ref:`Quad`

   .. attribute:: width

      Contains the width of the bounding box. Equals *abs(x1 - x0)*.

      :type: int

   .. attribute:: height

      Contains the height of the bounding box. Equals *abs(y1 - y0)*.

      :type: int

   .. attribute:: x0

      X-coordinate of the left corners.

      :type: int

   .. attribute:: y0

      Y-coordinate of the top corners.

      :type: int

   .. attribute:: x1

      X-coordinate of the right corners.

      :type: int

   .. attribute:: y1

      Y-coordinate of the bottom corners.

      :type: int

   .. attribute:: isInfinite

      *True* if rectangle is infinite, *False* otherwise.

      :type: bool

   .. attribute:: isEmpty

      *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 :ref:`SequenceTypes`.
   * Rectangles can be used with arithmetic operators -- see chapter :ref:`Algebra`.