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).

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), and in several draw methods (like Page.DrawQuad() / Shape.DrawQuad(), Page.DrawOval()/ Shape.DrawQuad()).

Note

  • If the corners of a rectangle are transformed with a rotation, scale or translation Matrix, then the resulting quad is rectangular (= congruent to a rectangle), i.e. all of its corners again enclose angles of 90 degrees. Property Quad.IsRectangular checks whether a quad can be thought of being the result of such an operation.

  • This is not true for all matrices: e.g. shear matrices produce parallelograms, and non-invertible matrices deliver “degenerate” tetragons like triangles or lines.

  • Attribute Quad.Rect obtains the enveloping rectangle. Vice versa, rectangles now have attributes Rect.Quad, resp. IRect.quad to obtain their respective tetragon versions.

Methods / Attributes

Short Description

Quad.Transform()

Transform with a matrix

Quad.Morph()

Transform with a point and matrix

Quad.UpperLeft

Upper left point

Quad.UpperRight

Upper right point

Quad.LowerLeft

Lower left point

Quad.LowerRight

Lower right point

Quad.IsConvex

True if quad is a convex set

Quad.IsEmpty

True if quad is an empty set

Quad.IsRectangular

True if quad is congruent to a rectangle

Quad.Rect

Smallest containing Rect

Quad.Width

The longest width value

Quad.Height

The longest height value

Class API

class Quad#
Quad()#
Quad(Point ul, Point ur, Point ll, Point lr)#
Quad(Quad quad)#

Overloaded constructors: “ul”, “ur”, “ll”, “lr” stand for Point objects (the four corners), “sequence” is a sequence with four 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 matrix)#

Modify the quadrilateral by transforming each of its corners with a matrix.

Parameters:

matrix (Matrix) – the matrix.

Morph(Point p, Matrix m)#

“Morph” the quad with a matrix-like using a point-like as fixed point.

Parameters:
Returns:

a new quad (no operation if this is the infinite quad).

Rect#

The smallest rectangle containing the quad, represented by the blue area in the following picture.

../_images/img-quads.jpg
Type:

Rect

UpperLeft#

Upper left point.

Type:

Point

UpperRight#

Upper right point.

Type:

Point

LowerLeft#

Lower left point.

Type:

Point

LowerRight#

Lower right point.

Type:

Point

IsConvex#

Checks if for any two points of the quad, all points on their connecting line also belong to the quad.

../_images/img-convexity.png
Type:

bool

IsEmpty#

true if enclosed area is zero, which means that at least three of the four corners are on the same line. If this is false, the quad may still be degenerate or not look like a tetragon at all (triangles, parallelograms, trapezoids, …).

Type:

bool

IsRectangular#

true if all corner angles are 90 degrees. This implies that the quad is convex and 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