pdftools_toolbox.geometry.real.affine_transform

Classes

AffineTransform

class pdftools_toolbox.geometry.real.affine_transform.AffineTransform[source]

Bases: Structure

Variables:
  • a (c_double) – This is the ‘a’ element in the affine transformation matrix [a b 0; c d 0; e f 1]

  • b (c_double) – This is the ‘b’ element in the affine transformation matrix [a b 0; c d 0; e f 1]

  • c (c_double) – This is the ‘c’ element in the affine transformation matrix [a b 0; c d 0; e f 1]

  • d (c_double) – This is the ‘d’ element in the affine transformation matrix [a b 0; c d 0; e f 1]

  • e (c_double) – This is the ‘e’ element in the affine transformation matrix [a b 0; c d 0; e f 1]

  • f (c_double) – This is the ‘f’ element in the affine transformation matrix [a b 0; c d 0; e f 1]

translate(tx: float, ty: float) None[source]

Translate.

Translations are specified as [1 0 0 1 tx ty], where tx and ty are the distances to translate the origin of the coordinate system in the horizontal and vertical dimensions, respectively.

Parameters:
  • tx (float) – horizontal translation

  • ty (float) – vertical translation

Raises:

StateError – If the affine transform is singular, e.g. default initialized. (Use pdftools_toolbox.geometry.real.affine_transform.AffineTransform.identity as an initial value.)

scale(sx: float, sy: float) None[source]

Scale.

Scaling is obtained by [sx 0 0 sy 0 0]. This scales the coordinates so that 1 unit in the horizontal and vertical dimensions of the new coordinate system is the same size as sx and sy units, respectively, in the previous coordinate system.

Parameters:
  • sx (float) – horizontal scale factor

  • sy (float) – vertical scale factor

Raises:

StateError – If the affine transform is singular, e.g. default initialized. (Use pdftools_toolbox.geometry.real.affine_transform.AffineTransform.identity as an initial value.)

rotate(angle: float, center: Point | None) None[source]

Rotate.

Rotations are produced by [cos(a) sin(a) -sin(a) cos(a) 0 0], which has the effect of rotating the coordinate system axes by an angle “a” in counterclockwise direction around the origin.

If the given center is not None, then the rotation is performed around the given center point, which is equivalent to the following sequence:

Parameters:
Raises:

StateError – If the affine transform is singular, e.g. default initialized. (Use pdftools_toolbox.geometry.real.affine_transform.AffineTransform.identity as an initial value.)

skew(alpha: float, beta: float) None[source]

Skew.

Skew is specified by [1 tan a tan b 1 0 0], which skews the x axis by an angle a and the y axis by an angle b.

Parameters:
  • alpha (float) – angle a in degrees

  • beta (float) – angle b in degrees

Raises:
  • StateError – If the affine transform is singular, e.g. default initialized. (Use pdftools_toolbox.geometry.real.affine_transform.AffineTransform.identity as an initial value.)

  • ValueError – if any of the given angles is too close to 90 + k*180 degrees for k = …, -2, -1, 0, 1, 2, …

concatenate(other: AffineTransform) None[source]

Concatenate transform with other transform.

Concatenating a transform with an other transform is equivalent to left-multiplying the transform’s matrix with with the other transform’s matrix.

Parameters:

other (pdftools_toolbox.geometry.real.affine_transform.AffineTransform) – the transform to be concatenated to this transform

Raises:
  • StateError – If the affine transform is singular, e.g. default initialized. (Use pdftools_toolbox.geometry.real.affine_transform.AffineTransform.identity as an initial value.)

  • ValueError – If the other affine transform is singular, e.g. default initialized. (Use pdftools_toolbox.geometry.real.affine_transform.AffineTransform.identity as an initial value.)

invert() None[source]

Invert the transform

A transform usually maps from the transformed coordinate system to the untransformed coordinate system. Use this method to create the reverse transform.

Raises:

StateError – If the affine transform is singular, e.g. default initialized. (Use pdftools_toolbox.geometry.real.affine_transform.AffineTransform.identity as an initial value.)

transform_point(original: Point) Point[source]

Transforms the given point.

Parameters:

original (pdftools_toolbox.geometry.real.point.Point) – the point to be transformed

Returns:

the transformed point

Return type:

pdftools_toolbox.geometry.real.point.Point

Raises:

StateError – If the affine transform is singular, e.g. default initialized. (Use pdftools_toolbox.geometry.real.affine_transform.AffineTransform.identity as an initial value.)

a

Structure/Union member

b

Structure/Union member

c

Structure/Union member

d

Structure/Union member

e

Structure/Union member

f

Structure/Union member

transform_rectangle(original: Rectangle) Quadrilateral[source]

Transform the given rectangle

For a general affine transformation, the returned pdftools_toolbox.geometry.real.quadrilateral.Quadrilateral is a parallelogram.

Parameters:

original (pdftools_toolbox.geometry.real.rectangle.Rectangle) – the rectangle to be transformed

Returns:

the transformed rectangle. For a general affine transform this is a parallelogram.

Return type:

pdftools_toolbox.geometry.real.quadrilateral.Quadrilateral

Raises:

StateError – if the affine transform is singular, e.g. default initialized. (Use pdftools_toolbox.geometry.real.affine_transform.AffineTransform.identity as an initial value.)

transform_quadrilateral(original: Quadrilateral) Quadrilateral[source]

Transform a given quadrilateral

If the input quadrilateral is a parallelogram, then the output is also a parallelogram.

Parameters:

original (pdftools_toolbox.geometry.real.quadrilateral.Quadrilateral) – the quadrilateral to be transformed

Returns:

the transformed quadrilateral. If the input is a parallelogram then the output is also a parallelogram.

Return type:

pdftools_toolbox.geometry.real.quadrilateral.Quadrilateral

Raises:

StateError – if the affine transform is singular, e.g. default initialized. (Use pdftools_toolbox.geometry.real.affine_transform.AffineTransform.identity as an initial value.)

static get_identity() AffineTransform[source]

The identity transform

Returns:

pdftools_toolbox.geometry.real.affine_transform.AffineTransform