Quad¶
Represents a four-sided mathematical shape (also called “quadrilateral” or “tetragon”) in the plane, defined as a sequence of four Point objects ul, ur, ll, lr (conveniently called upper left, upper right, lower left, lower right).
In (Py) MuPDF, only quads with four 90-degree angles and non-empty areas are of actual interest.
Such “interesting” quads can be obtained as results of text search methods (Page.searchFor()
), and they are used to define text marker annotations (see e.g. Page.addSquigglyAnnot()
and friends).
Note
If m
is a rotation, scale or a translation Matrix, and rect
is a rectangle, then the four points rect.tl * m
, rect.tr * m
, rect.bl * m
, and rect.br * m
are the corners of a rectangular quad. This is not in general true – examples are shear matrices which produce parallelograms.
Note
This class provides an attribute to calculate the envelopping rectangle. Vice versa, rectangles now have the attribute Rect.quad
, resp. IRect.quad
to obtain their respective tetragon versions.
Methods / Attributes |
Short Description |
---|---|
transform with a matrix |
|
upper left point |
|
upper right point |
|
lower left point |
|
lower right point |
|
true if corners define an empty area |
|
true if all angles are 90 degrees |
|
smallest containing Rect |
|
the longest width value |
|
the longest height value |
Class API
-
class
Quad
¶ -
__init__
(self)¶
-
__init__
(self, ul, ur, ll, lr)
-
__init__
(self, quad)
-
__init__
(self, sequence) Overloaded constructors:
ul
,ur
,ll
,lr
stand for Point objects (the 4 corners), “sequence” is a Python sequence type with 4 Point objects.If “quad” is specified, the constructor creates a new copy of it.
Without parameters, a quad consisting of 4 copies of
Point(0, 0)
is created.
-
transform
(matrix)¶ Modify the quadrilateral by transforming each of its corners with a matrix.
-
rect
¶ The smallest rectangle containing the quad, represented by the blue area in the following picture.
- Type
-
isEmpty
¶ True if enclosed area is zero, i.e. all points are on the same line. If this is false, the quad may still not look like a rectangle (but more like a triangle, trapezoid, etc.).
- Type
bool
-
isRectangular
¶ True if all angles are 90 degrees. This also implies that the area is not empty.
- Type
bool
-
width
¶ The maximum length of the top and the bottom side.
- Type
float
-
height
¶ The maximum length of the left and the right side.
- Type
float
-
Remark¶
This class adheres to the sequence protocol, so components can be dealt with via their indices, too. Also refer to Using Python Sequences as Arguments in PyMuPDF.
We are still in process to extend algebraic operations to quads. Multiplication and division with / by numbers and matrices are already defined. Addition, subtraction and any unary operations may follow when we see an actual need.