diagrams-core-1.4.1.1: Core libraries for diagrams EDSL

Diagrams.Core.Transform

Description

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.

Synopsis

# Transformations

## Invertible linear transformations

data u :-: v infixr 7 #

(v1 :-: v2) is a linear map paired with its inverse.

Constructors

 (u -> v) :-: (v -> u) infixr 7
Instances
 Semigroup (a :-: a) # Instance detailsDefined in Diagrams.Core.Transform Methods(<>) :: (a :-: a) -> (a :-: a) -> a :-: a #sconcat :: NonEmpty (a :-: a) -> a :-: a #stimes :: Integral b => b -> (a :-: a) -> a :-: a # Monoid (v :-: v) # Invertible linear maps from a vector space to itself form a monoid under composition. Instance detailsDefined in Diagrams.Core.Transform Methodsmempty :: v :-: v #mappend :: (v :-: v) -> (v :-: v) -> v :-: v #mconcat :: [v :-: v] -> v :-: v #

(<->) :: (u -> v) -> (v -> u) -> u :-: v #

Create an invertible linear map from two functions which are assumed to be linear inverses.

linv :: (u :-: v) -> v :-: u #

Invert a linear map.

lapp :: (u :-: v) -> u -> v #

Apply a linear map to a vector.

## General transformations

data Transformation v n #

General (affine) transformations, represented by an invertible linear map, its transpose, and a vector representing a translation component.

By the transpose of a linear map we mean simply the linear map corresponding to the transpose of the map's matrix representation. For example, any scale is its own transpose, since scales are represented by matrices with zeros everywhere except the diagonal. The transpose of a rotation is the same as its inverse.

The reason we need to keep track of transposes is because it turns out that when transforming a shape according to some linear map L, the shape's normal vectors transform according to L's inverse transpose. (For a more detailed explanation and proof, see https://wiki.haskell.org/Diagrams/Dev/Transformations.) This is exactly what we need when transforming bounding functions, which are defined in terms of perpendicular (i.e. normal) hyperplanes.

For more general, non-invertible transformations, see Diagrams.Deform (in diagrams-lib).

Constructors

 Transformation (v n :-: v n) (v n :-: v n) (v n)
Instances
 (Additive v, Num n) => Semigroup (Transformation v n) # Transformations are closed under composition; t1 <> t2 is the transformation which performs first t2, then t1. Instance detailsDefined in Diagrams.Core.Transform Methods(<>) :: Transformation v n -> Transformation v n -> Transformation v n #sconcat :: NonEmpty (Transformation v n) -> Transformation v n #stimes :: Integral b => b -> Transformation v n -> Transformation v n # (Additive v, Num n) => Monoid (Transformation v n) # Instance detailsDefined in Diagrams.Core.Transform Methodsmappend :: Transformation v n -> Transformation v n -> Transformation v n #mconcat :: [Transformation v n] -> Transformation v n # (Additive v, Num n) => HasOrigin (Transformation v n) # Instance detailsDefined in Diagrams.Core.Transform MethodsmoveOriginTo :: Point (V (Transformation v n)) (N (Transformation v n)) -> Transformation v n -> Transformation v n # (Additive v, Num n) => Transformable (Transformation v n) # Instance detailsDefined in Diagrams.Core.Transform Methodstransform :: Transformation (V (Transformation v n)) (N (Transformation v n)) -> Transformation v n -> Transformation v n # (Transformable a, V a ~ v, N a ~ n) => Action (Transformation v n) a # Transformations can act on transformable things. Instance detailsDefined in Diagrams.Core.Transform Methodsact :: Transformation v n -> a -> a # type N (Transformation v n) # Instance detailsDefined in Diagrams.Core.Transform type N (Transformation v n) = n type V (Transformation v n) # Instance detailsDefined in Diagrams.Core.Transform type V (Transformation v n) = v

inv :: (Functor v, Num n) => Transformation v n -> Transformation v n #

Invert a transformation.

transp :: Transformation v n -> v n :-: v n #

Get the transpose of a transformation (ignoring the translation component).

transl :: Transformation v n -> v n #

Get the translational component of a transformation.

dropTransl :: (Additive v, Num n) => Transformation v n -> Transformation v n #

Drop the translational component of a transformation, leaving only the linear part.

apply :: Transformation v n -> v n -> v n #

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 :: (Additive v, Num n) => Transformation v n -> Point v n -> Point v n #

Apply a transformation to a point.

fromLinear :: (Additive v, Num n) => (v n :-: v n) -> (v n :-: v n) -> Transformation v n #

Create a general affine transformation from an invertible linear transformation and its transpose. The translational component is assumed to be zero.

fromOrthogonal :: (Additive v, Num n) => (v n :-: v n) -> Transformation v n #

An orthogonal linear map is one whose inverse is also its transpose.

fromSymmetric :: (Additive v, Num n) => (v n :-: v n) -> Transformation v n #

A symmetric linear map is one whose transpose is equal to its self.

basis :: (Additive t, Traversable t, Num a) => [t a] #

Produce a default basis for a vector space. If the dimensionality of the vector space is not statically known, see basisFor.

dimension :: forall a. (Additive (V a), Traversable (V a)) => a -> Int #

Get the dimension of an object whose vector space is an instance of HasLinearMap, e.g. transformations, paths, diagrams, etc.

onBasis :: (Additive v, Traversable v, Num n) => Transformation v n -> ([v n], v n) #

Get the matrix equivalent of the linear transform, (as a list of columns) and the translation vector. This is mostly useful for implementing backends.

listRep :: Foldable v => v n -> [n] #

Convert a vector v to a list of scalars.

matrixRep :: (Additive v, Traversable v, Num n) => Transformation v n -> [[n]] #

Convert the linear part of a Transformation to a matrix representation as a list of column vectors which are also lists.

matrixHomRep :: (Additive v, Traversable v, Num n) => Transformation v n -> [[n]] #

Convert a Transformation v to a homogeneous matrix representation. The final list is the translation. The representation leaves off the last row of the matrix as it is always [0,0, ... 1] and this representation is the defacto standard for backends.

determinant :: (Additive v, Traversable v, Num n) => Transformation v n -> n #

The determinant of (the linear part of) a Transformation.

isReflection :: (Additive v, Traversable v, Num n, Ord n) => Transformation v n -> Bool #

Determine whether a Transformation includes a reflection component, that is, whether it reverses orientation.

avgScale :: (Additive v, Traversable v, Floating n) => Transformation v n -> n #

Compute the "average" amount of scaling performed by a transformation. Satisfies the properties

  avgScale (scaling k) == k
avgScale (t1 <> t2)  == avgScale t1 * avgScale t2


eye :: (HasBasis v, Num n) => v (v n) #

Identity matrix.

# The Transformable class

type HasLinearMap v = (HasBasis v, Traversable v) #

HasLinearMap is a constraint synonym, just to help shorten some of the ridiculously long constraint sets.

type HasBasis v = (Additive v, Representable v, Rep v ~ E v) #

An Additive vector space whose representation is made up of basis elements.

class Transformable t where #

Type class for things t which can be transformed.

Methods

transform :: Transformation (V t) (N t) -> t -> t #

Apply a transformation to an object.

Instances
 Transformable t => Transformable [t] # Instance detailsDefined in Diagrams.Core.Transform Methodstransform :: Transformation (V [t]) (N [t]) -> [t] -> [t] # (Transformable t, Ord t) => Transformable (Set t) # Instance detailsDefined in Diagrams.Core.Transform Methodstransform :: Transformation (V (Set t)) (N (Set t)) -> Set t -> Set t # # Instance detailsDefined in Diagrams.Core.Transform Methodstransform :: Transformation (V (Deletable m)) (N (Deletable m)) -> Deletable m -> Deletable m # (Num (N t), Additive (V t), Transformable t) => Transformable (TransInv t) # Instance detailsDefined in Diagrams.Core.Transform Methodstransform :: Transformation (V (TransInv t)) (N (TransInv t)) -> TransInv t -> TransInv t # (V t ~ v, N t ~ n, V t ~ V s, N t ~ N s, Functor v, Num n, Transformable t, Transformable s) => Transformable (s -> t) # Instance detailsDefined in Diagrams.Core.Transform Methodstransform :: Transformation (V (s -> t)) (N (s -> t)) -> (s -> t) -> s -> t # (Transformable t, Transformable s, V t ~ V s, N t ~ N s) => Transformable (t, s) # Instance detailsDefined in Diagrams.Core.Transform Methodstransform :: Transformation (V (t, s)) (N (t, s)) -> (t, s) -> (t, s) # Transformable t => Transformable (Map k t) # Instance detailsDefined in Diagrams.Core.Transform Methodstransform :: Transformation (V (Map k t)) (N (Map k t)) -> Map k t -> Map k t # (Additive v, Num n) => Transformable (Point v n) # Instance detailsDefined in Diagrams.Core.Transform Methodstransform :: Transformation (V (Point v n)) (N (Point v n)) -> Point v n -> Point v n # (InSpace v n t, Transformable t, HasLinearMap v, Floating n) => Transformable (Measured n t) # Instance detailsDefined in Diagrams.Core.Transform Methodstransform :: Transformation (V (Measured n t)) (N (Measured n t)) -> Measured n t -> Measured n t # (Additive v, Num n) => Transformable (Transformation v n) # Instance detailsDefined in Diagrams.Core.Transform Methodstransform :: Transformation (V (Transformation v n)) (N (Transformation v n)) -> Transformation v n -> Transformation v n # (Additive v, Traversable v, Floating n) => Transformable (Style v n) # Instance detailsDefined in Diagrams.Core.Style Methodstransform :: Transformation (V (Style v n)) (N (Style v n)) -> Style v n -> Style v n # (Additive v, Traversable v, Floating n) => Transformable (Attribute v n) # TAttributes are transformed directly, MAttributes have their local scale multiplied by the average scale of the transform. Plain Attributes are unaffected. Instance detailsDefined in Diagrams.Core.Style Methodstransform :: Transformation (V (Attribute v n)) (N (Attribute v n)) -> Attribute v n -> Attribute v n # (Additive v, Num n) => Transformable (Trace v n) # Instance detailsDefined in Diagrams.Core.Trace Methodstransform :: Transformation (V (Trace v n)) (N (Trace v n)) -> Trace v n -> Trace v n # (Metric v, Floating n) => Transformable (Envelope v n) # Instance detailsDefined in Diagrams.Core.Envelope Methodstransform :: Transformation (V (Envelope v n)) (N (Envelope v n)) -> Envelope v n -> Envelope v n # (Transformable t, Transformable s, Transformable u, V s ~ V t, N s ~ N t, V s ~ V u, N s ~ N u) => Transformable (t, s, u) # Instance detailsDefined in Diagrams.Core.Transform Methodstransform :: Transformation (V (t, s, u)) (N (t, s, u)) -> (t, s, u) -> (t, s, u) # (Additive v, Num n) => Transformable (Query v n m) # Instance detailsDefined in Diagrams.Core.Query Methodstransform :: Transformation (V (Query v n m)) (N (Query v n m)) -> Query v n m -> Query v n m # Transformable (Prim b v n) # The Transformable instance for Prim just pushes calls to transform down through the Prim constructor. Instance detailsDefined in Diagrams.Core.Types Methodstransform :: Transformation (V (Prim b v n)) (N (Prim b v n)) -> Prim b v n -> Prim b v n # Transformable (SubMap b v n m) # Instance detailsDefined in Diagrams.Core.Types Methodstransform :: Transformation (V (SubMap b v n m)) (N (SubMap b v n m)) -> SubMap b v n m -> SubMap b v n m # Transformable (Subdiagram b v n m) # Instance detailsDefined in Diagrams.Core.Types Methodstransform :: Transformation (V (Subdiagram b v n m)) (N (Subdiagram b v n m)) -> Subdiagram b v n m -> Subdiagram b v n m # (OrderedField n, Metric v, Semigroup m) => Transformable (QDiagram b v n m) # Diagrams can be transformed by transforming each of their components appropriately. Instance detailsDefined in Diagrams.Core.Types Methodstransform :: Transformation (V (QDiagram b v n m)) (N (QDiagram b v n m)) -> QDiagram b v n m -> QDiagram b v n m #

# Translational invariance

newtype TransInv t #

TransInv is a wrapper which makes a transformable type translationally invariant; the translational component of transformations will no longer affect things wrapped in TransInv.

Constructors

 TransInv t
Instances
 Eq t => Eq (TransInv t) # Instance detailsDefined in Diagrams.Core.Transform Methods(==) :: TransInv t -> TransInv t -> Bool #(/=) :: TransInv t -> TransInv t -> Bool # Ord t => Ord (TransInv t) # Instance detailsDefined in Diagrams.Core.Transform Methodscompare :: TransInv t -> TransInv t -> Ordering #(<) :: TransInv t -> TransInv t -> Bool #(<=) :: TransInv t -> TransInv t -> Bool #(>) :: TransInv t -> TransInv t -> Bool #(>=) :: TransInv t -> TransInv t -> Bool #max :: TransInv t -> TransInv t -> TransInv t #min :: TransInv t -> TransInv t -> TransInv t # Show t => Show (TransInv t) # Instance detailsDefined in Diagrams.Core.Transform MethodsshowsPrec :: Int -> TransInv t -> ShowS #show :: TransInv t -> String #showList :: [TransInv t] -> ShowS # Semigroup t => Semigroup (TransInv t) # Instance detailsDefined in Diagrams.Core.Transform Methods(<>) :: TransInv t -> TransInv t -> TransInv t #sconcat :: NonEmpty (TransInv t) -> TransInv t #stimes :: Integral b => b -> TransInv t -> TransInv t # Monoid t => Monoid (TransInv t) # Instance detailsDefined in Diagrams.Core.Transform Methodsmappend :: TransInv t -> TransInv t -> TransInv t #mconcat :: [TransInv t] -> TransInv t # # Instance detailsDefined in Diagrams.Core.Transform Associated Typestype Unwrapped (TransInv t) :: Type # Methods_Wrapped' :: Iso' (TransInv t) (Unwrapped (TransInv t)) # # Instance detailsDefined in Diagrams.Core.Transform MethodsmoveOriginTo :: Point (V (TransInv t)) (N (TransInv t)) -> TransInv t -> TransInv t # (Num (N t), Additive (V t), Transformable t) => Transformable (TransInv t) # Instance detailsDefined in Diagrams.Core.Transform Methodstransform :: Transformation (V (TransInv t)) (N (TransInv t)) -> TransInv t -> TransInv t # # Instance detailsDefined in Diagrams.Core.Names Methods(.>>) :: IsName a0 => a0 -> TransInv a -> TransInv a # Traced t => Traced (TransInv t) # Instance detailsDefined in Diagrams.Core.Trace MethodsgetTrace :: TransInv t -> Trace (V (TransInv t)) (N (TransInv t)) # Enveloped t => Enveloped (TransInv t) # Instance detailsDefined in Diagrams.Core.Envelope MethodsgetEnvelope :: TransInv t -> Envelope (V (TransInv t)) (N (TransInv t)) # Rewrapped (TransInv t) (TransInv t') # Instance detailsDefined in Diagrams.Core.Transform type Unwrapped (TransInv t) # Instance detailsDefined in Diagrams.Core.Transform type Unwrapped (TransInv t) = t type N (TransInv t) # Instance detailsDefined in Diagrams.Core.Transform type N (TransInv t) = N t type V (TransInv t) # Instance detailsDefined in Diagrams.Core.Transform type V (TransInv t) = V 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 :: v n -> Transformation v n #

Create a translation.

translate :: Transformable t => Vn t -> t -> t #

Translate by a vector.

scaling :: (Additive v, Fractional n) => n -> Transformation v n #

Create a uniform scaling transformation.

scale :: (InSpace v n a, Eq n, Fractional n, Transformable a) => n -> a -> a #

Scale uniformly in every dimension by the given scalar.