Maintainer | diagrams-discuss@googlegroups.com |
---|
Graphics.Rendering.Diagrams defines the core library of primitives forming the basis of an embedded domain-specific language for describing and rendering diagrams.
The Transform
module defines generic transformations
parameterized by any vector space.
- data u :-: v = (u :-* v) :-: (v :-* u)
- (<->) :: (HasLinearMap u, HasLinearMap v) => (u -> v) -> (v -> u) -> u :-: v
- linv :: (u :-: v) -> v :-: u
- lapp :: (VectorSpace v, Scalar u ~ Scalar v, HasLinearMap u) => (u :-: v) -> u -> v
- data Transformation v = Transformation (v :-: v) (v :-: v) v
- inv :: HasLinearMap v => Transformation v -> Transformation v
- transp :: Transformation v -> v :-: v
- transl :: Transformation v -> v
- apply :: HasLinearMap v => Transformation v -> v -> v
- papply :: HasLinearMap v => Transformation v -> Point v -> Point v
- fromLinear :: AdditiveGroup v => (v :-: v) -> (v :-: v) -> Transformation v
- class (HasBasis v, HasTrie (Basis v), VectorSpace v) => HasLinearMap v
- class HasLinearMap (V t) => Transformable t where
- transform :: Transformation (V t) -> t -> t
- newtype TransInv t = TransInv {
- unTransInv :: t
- translation :: HasLinearMap v => v -> Transformation v
- translate :: (Transformable t, HasLinearMap (V t)) => V t -> t -> t
- scaling :: (HasLinearMap v, Fractional (Scalar v)) => Scalar v -> Transformation v
- scale :: (Transformable t, Fractional (Scalar (V t))) => Scalar (V t) -> t -> t
Transformations
Invertible linear transformations
(v1 :-: v2)
is a linear map paired with its inverse.
HasLinearMap v => Monoid (:-: v v) | Invertible linear maps from a vector space to itself form a monoid under composition. |
(<->) :: (HasLinearMap u, HasLinearMap v) => (u -> v) -> (v -> u) -> u :-: vSource
Create an invertible linear map from two functions which are assumed to be linear inverses.
lapp :: (VectorSpace v, Scalar u ~ Scalar v, HasLinearMap u) => (u :-: v) -> u -> vSource
Apply a linear map to a vector.
General transformations
data Transformation v Source
General (affine) transformations, represented by an invertible linear map, its transpose, and a vector representing a translation component.
Transformation (v :-: v) (v :-: v) v |
HasLinearMap v => Monoid (Transformation v) | Transformations are closed under composition; |
HasLinearMap v => HasOrigin (Transformation v) | |
HasLinearMap v => Transformable (Transformation v) | |
(v ~ V a, HasLinearMap v, Transformable a) => Action (Transformation v) a | Transformations can act on transformable things. |
inv :: HasLinearMap v => Transformation v -> Transformation vSource
Invert a transformation.
transp :: Transformation v -> v :-: vSource
Get the transpose of a transformation (ignoring the translation component).
transl :: Transformation v -> vSource
Get the translational component of a transformation.
apply :: HasLinearMap v => Transformation v -> v -> vSource
Apply a transformation to a vector. Note that any translational component of the transformation will not affect the vector, since vectors are invariant under translation.
papply :: HasLinearMap v => Transformation v -> Point v -> Point vSource
Apply a transformation to a point.
fromLinear :: AdditiveGroup v => (v :-: v) -> (v :-: v) -> Transformation vSource
Create a general affine transformation from an invertible linear transformation and its transpose. The translational component is assumed to be zero.
The Transformable class
class (HasBasis v, HasTrie (Basis v), VectorSpace v) => HasLinearMap v Source
HasLinearMap
is a poor man's class constraint synonym, just to
help shorten some of the ridiculously long constraint sets.
(HasBasis v, HasTrie (Basis v), VectorSpace v) => HasLinearMap v |
class HasLinearMap (V t) => Transformable t whereSource
Type class for things t
which can be transformed.
transform :: Transformation (V t) -> t -> tSource
Apply a transformation to an object.
Translational invariance
TransInv
is a wrapper which makes a transformable type
translationally invariant; the translational component of
transformations will no longer affect things wrapped in
TransInv
.
TransInv | |
|
Show t => Show (TransInv t) | |
Monoid t => Monoid (TransInv t) | |
VectorSpace (V t) => HasOrigin (TransInv t) | |
Transformable t => Transformable (TransInv t) |
Vector space independent transformations
Most transformations are specific to a particular vector space, but a few can be defined generically over any vector space.
translation :: HasLinearMap v => v -> Transformation vSource
Create a translation.
translate :: (Transformable t, HasLinearMap (V t)) => V t -> t -> tSource
Translate by a vector.
scaling :: (HasLinearMap v, Fractional (Scalar v)) => Scalar v -> Transformation vSource
Create a uniform scaling transformation.
scale :: (Transformable t, Fractional (Scalar (V t))) => Scalar (V t) -> t -> tSource
Scale uniformly in every dimension by the given scalar.