Point

Point represents a point in the plane, defined by its x and y coordinates.

Attribute / Method

Description

Point.distance_to()

calculate distance to point or rect

Point.transform()

transform point with a matrix

Point.abs_unit

same as unit, but positive coordinates

Point.unit

point coordinates divided by abs(point)

Point.x

the X-coordinate

Point.y

the Y-coordinate

Class API

class Point
__init__(self)
__init__(self, x, y)
__init__(self, point)
__init__(self, sequence)

Overloaded constructors.

Without parameters, Point(0, 0) will be created.

With another point specified, a new copy will be crated, “sequence” must be Python sequence object of 2 floats (see Using Python Sequences as Arguments in PyMuPDF).

Parameters
  • x (float) – x coordinate of the point

  • y (float) – y coordinate of the point

distance_to(x[, unit])

Calculates the distance to x, which may be a Rect, IRect or Point. The distance is given in units of either px (pixels, default), in (inches), mm (millimeters) or cm (centimeters).

Note

If x is a rectangle, the distance is calculated to the finite version of it.

Parameters
  • x (Rect or IRect or Point) – the object to which the distance is calculated.

  • unit (str) – the unit to be measured in. One of px, in, cm, mm.

Returns

distance to object x.

Return type

float

transform(m)

Applies matrix m to the point and replaces it with the result.

Parameters

m (Matrix) – The matrix to be applied.

Return type

Point

unit

Result of dividing each coordinate by abs(point), the distance of the point to (0,0). This is a vector of length 1 pointing in the same direction as the point does. Its x, resp. y values are equal to the cosine, resp. sine of the angle this vector (and the point itself) has with the x axis.

_images/img-point-unit.jpg
Type

Point

abs_unit

Same as unit above, replacing the coordinates with their absolute values.

Type

Point

x

The x coordinate

Type

float

y

The y coordinate

Type

float

Remark

This class adheres to the sequence protocol, so components can be manipulated via their index. Also refer to Using Python Sequences as Arguments in PyMuPDF.

Point Algebra

For a general background, see chapter Operator Algebra for Geometry Objects.

Examples

This should illustrate some basic uses:

>>> fitz.Point(1, 2) * fitz.Matrix(90)
fitz.Point(-2.0, 1.0)
>>>
>>> fitz.Point(1, 2) * 3
fitz.Point(3.0, 6.0)
>>>
>>> fitz.Point(1, 2) + 3
fitz.Point(4.0, 5.0)
>>>
>>> fitz.Point(25, 30) + fitz.Point(1, 2)
fitz.Point(26.0, 32.0)
>>> fitz.Point(25, 30) + (1, 2)
fitz.Point(26.0, 32.0)
>>>
>>> fitz.Point([1, 2])
fitz.Point(1.0, 2.0)
>>>
>>> -fitz.Point(1, 2)
fitz.Point(-1.0, -2.0)
>>>
>>> abs(fitz.Point(25, 30))
39.05124837953327
>>>
>>> fitz.Point(1, 2) / (1, 2, 3, 4, 5, 6)
fitz.Point(2.0, -2.0)