package camlpdf

  1. Overview
  2. Docs

Affine Transformations in Two Dimensions

Types

type transform_op =
  1. | Scale of float * float * float * float
  2. | Rotate of float * float * float
  3. | Translate of float * float
  4. | ShearX of float * float * float
  5. | ShearY of float * float * float

A single transformation operation.

type transform = transform_op list

A list of transformations, the first at the end of the list (thus, to append another transformation, just cons to the beginning.)

type transform_matrix = {
  1. a : float;
  2. b : float;
  3. c : float;
  4. d : float;
  5. e : float;
  6. f : float;
}

A transformation matrix (first row a c e, second row b d f, third row 0 0 1)

val i : transform

The identity transform

val string_of_transform : transform -> string

Make a string of a transform for debug purposes.

Making transformation matrices

val i_matrix : transform_matrix

The identity matrix

val string_of_matrix : transform_matrix -> string

String of a transformation matrix.

val mktranslate : float -> float -> transform_matrix

Make a transformation matrix from x and y translation.

val mkscale : (float * float) -> float -> float -> transform_matrix

Make a transformation matrix from an x and y scale and a point to scale about.

val mkrotate : (float * float) -> float -> transform_matrix

Make a rotation matrix to rotate by a number of radians around a point.

val mkshearx : (float * float) -> float -> transform_matrix

Matrix to shear in x by a given factor about a point.

val mksheary : (float * float) -> float -> transform_matrix

Matrix to shear in y by a given factor about a point.

Composing and manipulating transforms

val compose : transform_op -> transform -> transform

compose t ts adds operation t to the transform ts.

val append : transform -> transform -> transform

append a b is a transform with the same effect as performing b then a

compose a b produces a matrix equivalent to performing b then a.

val matrix_of_op : transform_op -> transform_matrix

Make a matrix from a single transformation operation

val matrix_of_transform : transform -> transform_matrix

Make a matrix from a transform

Inverting transforms

exception NonInvertable

Exception raised if a matrix is non-invertable

val matrix_invert : transform_matrix -> transform_matrix

Matrix inversion. May raise NonInvertable

val transform : transform -> (float * float) -> float * float

Transform a coordinate by a given transform.

val transform_matrix : transform_matrix -> (float * float) -> float * float

Transform a coordinate by a given transformation matrix.

Decomposing and recomposing matrices

val decompose : transform_matrix -> float * float * float * float * float * float

Decompose a transformation matrix to scale, aspect, rotation, shear, translation in x, translation in y. Always succeeds, but results are not guaranteed to mean anything.

val recompose : float -> float -> float -> float -> float -> float -> transform_matrix

Recompose from the above information. It is not guaranteed that recompose (decompose t) = t

OCaml

Innovation. Community. Security.