Portability | GHC |
---|---|

Stability | unstable |

Maintainer | stephen.tetley@gmail.com |

Affine transformations.

The common affine transformations represented as type classes - scaling, rotation, translation.

Internally, when a Picture is composed and transformed, Wumpus only transforms the bounding box - transformations of the picture content (paths or text labels) are communicated to PostScript or SVG for final rendering. This is because Wumpus has no access to the paths that make fonts so cannot transform them directly.

Other elements - Vectors, Points, BoundingBoxes and Primtives -
are also instances of the affine classes. However, generally
Wumpus transforms these elements directly rather than
delegating the transformation to PostScript or SVG (the
situation for the Label primitive is more complicated - the
*start* point is transformed by Wumpus but a matrix
transformation is sent to PostScript to manipulate the opaque
character objects).

Note - transformations on Primitives are applied to the control
points of the primitive not the *drawing*. A scaled, stroked
path will be drawn with at the standard line width rather than
with a thicker line. Also, text may not render pleasantly after
it has been transformed, PostScript references seem to caution
against transforming text and recommend changing `/scalefont`

instead of scaling via a transfomation.

To generate efficient PostScript, Wumpus relies on the matrix representations of the affine transformations being invertible. Do not scale elements by zero!

- class Transform t where
- class Rotate t where
- class RotateAbout t where
- rotateAbout :: u ~ DUnit t => Radian -> Point2 u -> t -> t

- class Scale t where
- class Translate t where
- rotate30 :: Rotate t => t -> t
- rotate30About :: (RotateAbout t, DUnit t ~ u) => Point2 u -> t -> t
- rotate45 :: Rotate t => t -> t
- rotate45About :: (RotateAbout t, DUnit t ~ u) => Point2 u -> t -> t
- rotate60 :: Rotate t => t -> t
- rotate60About :: (RotateAbout t, DUnit t ~ u) => Point2 u -> t -> t
- rotate90 :: Rotate t => t -> t
- rotate90About :: (RotateAbout t, DUnit t ~ u) => Point2 u -> t -> t
- rotate120 :: Rotate t => t -> t
- rotate120About :: (RotateAbout t, DUnit t ~ u) => Point2 u -> t -> t
- uniformScale :: (Scale t, DUnit t ~ u) => u -> t -> t
- reflectX :: (Num u, Scale t, DUnit t ~ u) => t -> t
- reflectY :: (Num u, Scale t, DUnit t ~ u) => t -> t
- translateBy :: (Translate t, DUnit t ~ u) => Vec2 u -> t -> t
- reflectXPlane :: (Num u, Scale t, Translate t, u ~ DUnit t) => Point2 u -> t -> t
- reflectYPlane :: (Num u, Scale t, Translate t, u ~ DUnit t) => Point2 u -> t -> t

# Type classes

Apply a matrix transformation directly.

Type class for rotation.

class RotateAbout t whereSource

Type class for rotation about a point.

rotateAbout :: u ~ DUnit t => Radian -> Point2 u -> t -> tSource

(Floating u, Real u) => RotateAbout (Point2 u) | |

(Floating u, Real u) => RotateAbout (Vec2 u) | |

(Real u, Floating u) => RotateAbout (BoundingBox u) | |

(Real u, Floating u) => RotateAbout (Primitive u) | |

(Real u, Floating u) => RotateAbout (Picture u) |

Type class for scaling.

Type class for translation.

# Common rotations

rotate30About :: (RotateAbout t, DUnit t ~ u) => Point2 u -> t -> tSource

Rotate by 30 degrees about the supplied point.

rotate45About :: (RotateAbout t, DUnit t ~ u) => Point2 u -> t -> tSource

Rotate by 45 degrees about the supplied point.

rotate60About :: (RotateAbout t, DUnit t ~ u) => Point2 u -> t -> tSource

Rotate by 60 degrees about the supplied point.

rotate90About :: (RotateAbout t, DUnit t ~ u) => Point2 u -> t -> tSource

Rotate by 90 degrees about the supplied point.

rotate120About :: (RotateAbout t, DUnit t ~ u) => Point2 u -> t -> tSource

Rotate by 120 degrees about the supplied point.

# Common scalings

uniformScale :: (Scale t, DUnit t ~ u) => u -> t -> tSource

Scale both x and y dimensions by the same amount.

# Translate by a vector

translateBy :: (Translate t, DUnit t ~ u) => Vec2 u -> t -> tSource

Translate by the x and y components of a vector.