Copyright | (c) 2011-2015 diagrams-core team (see LICENSE) |
---|---|
License | BSD-style (see LICENSE) |
Maintainer | diagrams-discuss@googlegroups.com |
Safe Haskell | None |
Language | Haskell2010 |
The core library of primitives forming the basis of an embedded
domain-specific language for describing and rendering diagrams.
Normal users of the diagrams library should almost never need to
import anything from this package directly; instead, import modules
(especially Diagrams.Prelude
) from the diagrams-lib package,
which re-exports most things of value to users.
For most library code needing access to core internals, it should be sufficient to import this module, which simply re-exports useful functionality from other modules in the core library. Library writers needing finer-grained access or functionality may occasionally find it useful to directly import one of the constituent core modules.
The diagrams library relies heavily on custom types and classes. Many
of the relevant definitions are in the Diagrams.Core.Types module.
Indeed the definition of the diagram type QDiagram
is contained in:
QDiagram
.
The best place to start when learning about diagrams' types is the user manual: http://projects.haskell.org/diagrams/doc/manual.html#type-reference The following list shows which types are contained in each module of Diagrams.Core.
,Annotation
,UpAnnots
b v n m
,DownAnnots
v n
,QDiaLeaf
b v n m
,Measure
n
,Subdiagram
b v n m
,SubMap
b v n m
,Prim
b v n
,Backend
b v n
,DNode
b v n a
,DTree
b v n a
,RNode
b v n a
,RTree
b v n a
,NullBackend
,Renderable
t b
.D
v n
,Envelope
v n
,Enveloped
a
.OrderedField
s
.Juxtaposable
a
,AName
,Name
,IsName
a
.Qualifiable
q
.HasOrigin
t
.Query
v n m
,AttributeClass
a
,Attribute
v n
,Style
v n
.HasStyle
,SortedList
a
,Trace
v n
.Traced
a
u
,:-:
v
,HasLinearMap
HasBasis
,Transformation
v n
,Transformable
t
.TransInv
t
- type family V a :: * -> *
- type family N a :: *
- type Vn a = V a (N a)
- class (V a ~ v, N a ~ n, Additive v, Num n) => InSpace v n a
- class (V a ~ V b, N a ~ N b) => SameSpace a b
- data Point f a :: (* -> *) -> * -> *
- origin :: (Additive f, Num a) => Point f a
- (*.) :: (Functor v, Num n) => n -> Point v n -> Point v n
- relative :: (Additive f, Num a) => Point f a -> Iso' (Point f a) (f a)
- basis :: (Additive t, Traversable t, Num a) => [t a]
- dimension :: forall a. (Additive (V a), Traversable (V a)) => a -> Int
- determinant :: (Additive v, Traversable v, Num n) => Transformation v n -> n
- isReflection :: (Additive v, Traversable v, Num n, Ord n) => Transformation v n -> Bool
- data u :-: v
- (<->) :: (u -> v) -> (v -> u) -> u :-: v
- linv :: (u :-: v) -> v :-: u
- lapp :: (u :-: v) -> u -> v
- data Transformation v n
- inv :: (Functor v, Num n) => Transformation v n -> Transformation v n
- transp :: Transformation v n -> v n :-: v n
- transl :: Transformation v n -> v n
- dropTransl :: (Additive v, Num n) => Transformation v n -> Transformation v n
- apply :: Transformation v n -> v n -> v n
- papply :: (Additive v, Num n) => Transformation v n -> Point v n -> Point v n
- fromLinear :: (Additive v, Num n) => (v n :-: v n) -> (v n :-: v n) -> Transformation v n
- translation :: v n -> Transformation v n
- translate :: Transformable t => Vn t -> t -> t
- moveTo :: (InSpace v n t, HasOrigin t) => Point v n -> t -> t
- place :: (InSpace v n t, HasOrigin t) => t -> Point v n -> t
- scaling :: (Additive v, Fractional n) => n -> Transformation v n
- scale :: (InSpace v n a, Eq n, Fractional n, Transformable a) => n -> a -> a
- avgScale :: (Additive v, Traversable v, Floating n) => Transformation v n -> n
- class Transformable t where
- newtype TransInv t = TransInv t
- eye :: (HasBasis v, Num n) => v (v n)
- data AName
- data Name
- class (Typeable a, Ord a, Show a) => IsName a where
- class Qualifiable q where
- (.>) :: (IsName a1, IsName a2) => a1 -> a2 -> Name
- eachName :: (Typeable a, Ord a, Show a) => Traversal' Name a
- newtype SubMap b v n m = SubMap (Map Name [Subdiagram b v n m])
- fromNames :: IsName a => [(a, Subdiagram b v n m)] -> SubMap b v n m
- rememberAs :: IsName a => a -> QDiagram b v n m -> SubMap b v n m -> SubMap b v n m
- lookupSub :: IsName nm => nm -> SubMap b v n m -> Maybe [Subdiagram b v n m]
- class (Typeable a, Semigroup a) => AttributeClass a
- data Attribute v n :: * where
- Attribute :: AttributeClass a => a -> Attribute v n
- MAttribute :: AttributeClass a => Measured n a -> Attribute v n
- TAttribute :: (AttributeClass a, Transformable a, V a ~ v, N a ~ n) => a -> Attribute v n
- data Style v n
- class HasStyle a where
- getAttr :: forall a v n. AttributeClass a => Style v n -> Maybe a
- atAttr :: AttributeClass a => Lens' (Style v n) (Maybe a)
- atMAttr :: (AttributeClass a, Typeable n) => Lens' (Style v n) (Maybe (Measured n a))
- atTAttr :: (V a ~ v, N a ~ n, AttributeClass a, Transformable a) => Lens' (Style v n) (Maybe a)
- applyAttr :: (AttributeClass a, HasStyle d) => a -> d -> d
- applyMAttr :: (AttributeClass a, N d ~ n, HasStyle d) => Measured n a -> d -> d
- applyTAttr :: (AttributeClass a, Transformable a, V a ~ V d, N a ~ N d, HasStyle d) => a -> d -> d
- newtype Envelope v n = Envelope (Option (v n -> Max n))
- appEnvelope :: Envelope v n -> Maybe (v n -> n)
- onEnvelope :: ((v n -> n) -> v n -> n) -> Envelope v n -> Envelope v n
- mkEnvelope :: (v n -> n) -> Envelope v n
- class (Metric (V a), OrderedField (N a)) => Enveloped a where
- envelopeVMay :: Enveloped a => Vn a -> a -> Maybe (Vn a)
- envelopeV :: Enveloped a => Vn a -> a -> Vn a
- envelopePMay :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> Maybe (Point v n)
- envelopeP :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> Point v n
- diameter :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> n
- radius :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> n
- size :: (V a ~ v, N a ~ n, Enveloped a, HasBasis v) => a -> v n
- newtype Trace v n = Trace {
- appTrace :: Point v n -> v n -> SortedList n
- data SortedList a
- mkSortedList :: Ord a => [a] -> SortedList a
- getSortedList :: SortedList a -> [a]
- mkTrace :: (Point v n -> v n -> SortedList n) -> Trace v n
- class (Additive (V a), Ord (N a)) => Traced a where
- traceV :: (n ~ N a, Num n, Traced a) => Point (V a) n -> V a n -> a -> Maybe (V a n)
- traceP :: (n ~ N a, Traced a, Num n) => Point (V a) n -> V a n -> a -> Maybe (Point (V a) n)
- maxTraceV :: (n ~ N a, Num n, Traced a) => Point (V a) n -> V a n -> a -> Maybe (V a n)
- maxTraceP :: (n ~ N a, Num n, Traced a) => Point (V a) n -> V a n -> a -> Maybe (Point (V a) n)
- rayTraceV :: (n ~ N a, Traced a, Num n) => Point (V a) n -> V a n -> a -> Maybe (V a n)
- rayTraceP :: (n ~ N a, Traced a, Num n) => Point (V a) n -> V a n -> a -> Maybe (Point (V a) n)
- maxRayTraceV :: (n ~ N a, Traced a, Num n) => Point (V a) n -> V a n -> a -> Maybe (V a n)
- maxRayTraceP :: (n ~ N a, Traced a, Num n) => Point (V a) n -> V a n -> a -> Maybe (Point (V a) n)
- class HasOrigin t where
- moveOriginBy :: (V t ~ v, N t ~ n, HasOrigin t) => v n -> t -> t
- class Juxtaposable a where
- juxtaposeDefault :: (Enveloped a, HasOrigin a) => Vn a -> a -> a -> a
- newtype Query v n m = Query {}
- data Prim b v n where
- Prim :: (Transformable p, Typeable p, Renderable p b) => p -> Prim b (V p) (N p)
- data QDiagram b v n m
- type Diagram b = QDiagram b (V b) (N b) Any
- mkQD :: Prim b v n -> Envelope v n -> Trace v n -> SubMap b v n m -> Query v n m -> QDiagram b v n m
- pointDiagram :: (Metric v, Fractional n) => Point v n -> QDiagram b v n m
- envelope :: (OrderedField n, Metric v, Monoid' m) => Lens' (QDiagram b v n m) (Envelope v n)
- trace :: (Metric v, OrderedField n, Semigroup m) => Lens' (QDiagram b v n m) (Trace v n)
- subMap :: (Metric v, Semigroup m, OrderedField n) => Lens' (QDiagram b v n m) (SubMap b v n m)
- names :: (Metric v, Semigroup m, OrderedField n) => QDiagram b v n m -> [(Name, [Point v n])]
- query :: Monoid m => QDiagram b v n m -> Query v n m
- nameSub :: (IsName nm, Metric v, OrderedField n, Semigroup m) => (QDiagram b v n m -> Subdiagram b v n m) -> nm -> QDiagram b v n m -> QDiagram b v n m
- withName :: (IsName nm, Metric v, Semigroup m, OrderedField n) => nm -> (Subdiagram b v n m -> QDiagram b v n m -> QDiagram b v n m) -> QDiagram b v n m -> QDiagram b v n m
- withNameAll :: (IsName nm, Metric v, Semigroup m, OrderedField n) => nm -> ([Subdiagram b v n m] -> QDiagram b v n m -> QDiagram b v n m) -> QDiagram b v n m -> QDiagram b v n m
- withNames :: (IsName nm, Metric v, Semigroup m, OrderedField n) => [nm] -> ([Subdiagram b v n m] -> QDiagram b v n m -> QDiagram b v n m) -> QDiagram b v n m -> QDiagram b v n m
- localize :: forall b v n m. (Metric v, OrderedField n, Semigroup m) => QDiagram b v n m -> QDiagram b v n m
- href :: (Metric v, OrderedField n, Semigroup m) => String -> QDiagram b v n m -> QDiagram b v n m
- opacityGroup :: (Metric v, OrderedField n, Semigroup m) => Double -> QDiagram b v n m -> QDiagram b v n m
- groupOpacity :: (Metric v, OrderedField n, Semigroup m) => Double -> QDiagram b v n m -> QDiagram b v n m
- setEnvelope :: forall b v n m. (OrderedField n, Metric v, Monoid' m) => Envelope v n -> QDiagram b v n m -> QDiagram b v n m
- setTrace :: forall b v n m. (OrderedField n, Metric v, Semigroup m) => Trace v n -> QDiagram b v n m -> QDiagram b v n m
- atop :: (OrderedField n, Metric v, Semigroup m) => QDiagram b v n m -> QDiagram b v n m -> QDiagram b v n m
- data Subdiagram b v n m = Subdiagram (QDiagram b v n m) (DownAnnots v n)
- mkSubdiagram :: QDiagram b v n m -> Subdiagram b v n m
- getSub :: (Metric v, OrderedField n, Semigroup m) => Subdiagram b v n m -> QDiagram b v n m
- rawSub :: Subdiagram b v n m -> QDiagram b v n m
- location :: (Additive v, Num n) => Subdiagram b v n m -> Point v n
- subPoint :: (Metric v, OrderedField n) => Point v n -> Subdiagram b v n m
- data Measured n a
- type Measure n = Measured n n
- fromMeasured :: Num n => n -> n -> Measured n a -> a
- output :: n -> Measure n
- local :: Num n => n -> Measure n
- global :: Num n => n -> Measure n
- normalized :: Num n => n -> Measure n
- scaleLocal :: Num n => n -> Measured n a -> Measured n a
- atLeast :: Ord n => Measure n -> Measure n -> Measure n
- atMost :: Ord n => Measure n -> Measure n -> Measure n
- class Backend b v n where
- class Transformable t => Renderable t b where
- renderDia :: (Backend b v n, HasLinearMap v, Metric v, Typeable n, OrderedField n, Monoid' m) => b -> Options b v n -> QDiagram b v n m -> Result b v n
- renderDiaT :: (Backend b v n, HasLinearMap v, Metric v, Typeable n, OrderedField n, Monoid' m) => b -> Options b v n -> QDiagram b v n m -> (Transformation v n, Result b v n)
- data NullBackend
- type D v n = QDiagram NullBackend v n Any
- class (HasBasis v, Traversable v) => HasLinearMap v
- class (Additive v, Representable v, Rep v ~ E v) => HasBasis v
- class (Floating s, Ord s) => OrderedField s
- class (Typeable n, RealFloat n) => TypeableFloat n
- class (Semigroup m, Monoid m) => Monoid' m
Associated vector spaces
Many sorts of objects have an associated vector space in which
they "live". The type function V
maps from object types to
the associated vector space. The resulting vector space has kind * -> *
which means it takes another value (a number) and returns a concrete
vector. For example V2
has kind * -> *
and V2 Double
is a vector.
type V [a] # | |
type V (Option a) # | |
type V (Set a) # | |
type V (Split m) # | |
type V (Deletable m) # | |
type V (TransInv t) # | |
type V (a -> b) # | |
type V (a, b) # | |
type V (Map k a) # | |
type V (Point v n) # | |
type V ((:+:) m n) # | |
type V (Measured n a) # | |
type V (Transformation v n) # | |
type V (Style v n) # | |
type V (Attribute v n) # | |
type V (Trace v n) # | |
type V (Envelope v n) # | |
type V (a, b, c) # | |
type V (Query v n m) # | |
type V (Prim b v n) # | |
type V (SubMap b v n m) # | |
type V (Subdiagram b v n m) # | |
type V (QDiagram b v n m) # | |
The numerical field for the object, the number type used for calculations.
type N [a] # | |
type N (Option a) # | |
type N (Set a) # | |
type N (Split m) # | |
type N (Deletable m) # | |
type N (TransInv t) # | |
type N (a -> b) # | |
type N (a, b) # | |
type N (Map k a) # | |
type N (Point v n) # | |
type N ((:+:) m n) # | |
type N (Measured n a) # | |
type N (Transformation v n) # | |
type N (Style v n) # | |
type N (Attribute v n) # | |
type N (Trace v n) # | |
type N (Envelope v n) # | |
type N (a, b, c) # | |
type N (Query v n m) # | |
type N (Prim b v n) # | |
type N (SubMap b v n m) # | |
type N (Subdiagram b v n m) # | |
type N (QDiagram b v n m) # | |
Conveient type alias to retrieve the vector type associated with an
object's vector space. This is usually used as Vn a ~ v n
where v
is
the vector space and n
is the numerical field.
class (V a ~ V b, N a ~ N b) => SameSpace a b #
SameSpace a b
means the types a
and b
belong to the same
vector space v n
.
Points
data Point f a :: (* -> *) -> * -> * #
A handy wrapper to help distinguish points from vectors at the type level
Unbox (f a) => Vector Vector (Point f a) | |
Unbox (f a) => MVector MVector (Point f a) | |
Monad f => Monad (Point f) | |
Functor f => Functor (Point f) | |
Applicative f => Applicative (Point f) | |
Foldable f => Foldable (Point f) | |
Traversable f => Traversable (Point f) | |
Generic1 (Point f) | |
Distributive f => Distributive (Point f) | |
Representable f => Representable (Point f) | |
Eq1 f => Eq1 (Point f) | |
Ord1 f => Ord1 (Point f) | |
Read1 f => Read1 (Point f) | |
Show1 f => Show1 (Point f) | |
Serial1 f => Serial1 (Point f) | |
Additive f => Affine (Point f) | |
R4 f => R4 (Point f) | |
R3 f => R3 (Point f) | |
R2 f => R2 (Point f) | |
R1 f => R1 (Point f) | |
Finite f => Finite (Point f) | |
Metric f => Metric (Point f) | |
Additive f => Additive (Point f) | |
Apply f => Apply (Point f) | |
Bind f => Bind (Point f) | |
Functor v => Cosieve (Query v) (Point v) # | |
Eq (f a) => Eq (Point f a) | |
Fractional (f a) => Fractional (Point f a) | |
(Data (f a), Typeable * a, Typeable (* -> *) f) => Data (Point f a) | |
Num (f a) => Num (Point f a) | |
Ord (f a) => Ord (Point f a) | |
Read (f a) => Read (Point f a) | |
Show (f a) => Show (Point f a) | |
Ix (f a) => Ix (Point f a) | |
Generic (Point f a) | |
Storable (f a) => Storable (Point f a) | |
Binary (f a) => Binary (Point f a) | |
Serial (f a) => Serial (Point f a) | |
Serialize (f a) => Serialize (Point f a) | |
NFData (f a) => NFData (Point f a) | |
Hashable (f a) => Hashable (Point f a) | |
Unbox (f a) => Unbox (Point f a) | |
Ixed (f a) => Ixed (Point f a) | |
Wrapped (Point f a) | |
Epsilon (f a) => Epsilon (Point f a) | |
(Additive v, Num n) => HasOrigin (Point v n) # | |
(Additive v, Num n) => Transformable (Point v n) # | |
(Additive v, Ord n) => Traced (Point v n) # | The trace of a single point is the empty trace, i.e. the one which returns no intersection points for every query. Arguably it should return a single finite distance for vectors aimed directly at the given point, but due to floating-point inaccuracy this is problematic. Note that the envelope for a single point is not the empty envelope (see Diagrams.Core.Envelope). |
(OrderedField n, Metric v) => Enveloped (Point v n) # | |
(~) * t (Point g b) => Rewrapped (Point f a) t | |
Traversable f => Each (Point f a) (Point f b) a b | |
data MVector s (Point f a) | |
type Rep1 (Point f) | |
type Rep (Point f) | |
type Diff (Point f) | |
type Size (Point f) | |
type Rep (Point f a) | |
data Vector (Point f a) | |
type Index (Point f a) | |
type IxValue (Point f a) | |
type Unwrapped (Point f a) | |
type N (Point v n) # | |
type V (Point v n) # | |
(*.) :: (Functor v, Num n) => n -> Point v n -> Point v n #
Scale a point by a scalar. Specialized version of '(*^)'.
relative :: (Additive f, Num a) => Point f a -> Iso' (Point f a) (f a) #
An isomorphism between points and vectors, given a reference point.
Transformations
Utilities
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.
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.
Invertible linear transformations
(v1 :-: v2)
is a linear map paired with its inverse.
(<->) :: (u -> v) -> (v -> u) -> u :-: v #
Create an invertible linear map from two functions which are assumed to be linear inverses.
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
).
(Additive v, Num n) => Semigroup (Transformation v n) # | Transformations are closed under composition; |
(Additive v, Num n) => Monoid (Transformation v n) # | |
(Additive v, Num n) => HasOrigin (Transformation v n) # | |
(Additive v, Num n) => Transformable (Transformation v n) # | |
(Transformable a, (~) (* -> *) (V a) v, (~) * (N a) n) => Action (Transformation v n) a # | Transformations can act on transformable things. |
type N (Transformation v n) # | |
type V (Transformation v n) # | |
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.
Some specific transformations
translation :: v n -> Transformation v n #
Create a translation.
translate :: Transformable t => Vn t -> t -> t #
Translate by a vector.
moveTo :: (InSpace v n t, HasOrigin t) => Point v n -> t -> t #
Translate the object by the translation that sends the origin to
the given point. Note that this is dual to moveOriginTo
, i.e. we
should have
moveTo (origin .^+ v) === moveOriginTo (origin .^- v)
For types which are also Transformable
, this is essentially the
same as translate
, i.e.
moveTo (origin .^+ v) === translate v
place :: (InSpace v n t, HasOrigin t) => t -> Point v n -> t #
A flipped variant of moveTo
, provided for convenience. Useful
when writing a function which takes a point as an argument, such
as when using withName
and friends.
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.
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
The Transformable class
class Transformable t where #
Type class for things t
which can be transformed.
transform :: Transformation (V t) (N t) -> t -> t #
Apply a transformation to an object.
Transformable t => Transformable [t] # | |
(Transformable t, Ord t) => Transformable (Set t) # | |
Transformable m => Transformable (Deletable m) # | |
(Num (N t), Additive (V t), Transformable t) => Transformable (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) # | |
(Transformable t, Transformable s, (~) (* -> *) (V t) (V s), (~) * (N t) (N s)) => Transformable (t, s) # | |
Transformable t => Transformable (Map k t) # | |
(Additive v, Num n) => Transformable (Point v n) # | |
(InSpace v n t, Transformable t, HasLinearMap v, Floating n) => Transformable (Measured n t) # | |
(Additive v, Num n) => Transformable (Transformation v n) # | |
(Additive v, Traversable v, Floating n) => Transformable (Style v n) # | |
(Additive v, Traversable v, Floating n) => Transformable (Attribute v n) # |
|
(Additive v, Num n) => Transformable (Trace v n) # | |
(Metric v, Floating n) => Transformable (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) # | |
(Additive v, Num n) => Transformable (Query v n m) # | |
Transformable (Prim b v n) # | The |
Transformable (SubMap b v n m) # | |
Transformable (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. |
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 t |
Eq t => Eq (TransInv t) # | |
Ord t => Ord (TransInv t) # | |
Show t => Show (TransInv t) # | |
Semigroup t => Semigroup (TransInv t) # | |
Monoid t => Monoid (TransInv t) # | |
Wrapped (TransInv t) # | |
HasOrigin (TransInv t) # | |
(Num (N t), Additive (V t), Transformable t) => Transformable (TransInv t) # | |
Qualifiable a => Qualifiable (TransInv a) # | |
Traced t => Traced (TransInv t) # | |
Enveloped t => Enveloped (TransInv t) # | |
Rewrapped (TransInv t) (TransInv t') # | |
type Unwrapped (TransInv t) # | |
type N (TransInv t) # | |
type V (TransInv t) # | |
Names
A (qualified) name is a (possibly empty) sequence of atomic names.
Eq Name # | |
Ord Name # | |
Show Name # | |
Semigroup Name # | |
Monoid Name # | |
Wrapped Name # | |
Qualifiable Name # | Of course, names can be qualified using |
IsName Name # | |
Rewrapped Name Name # | |
Each Name Name AName AName # | |
Action Name (SubMap b v n m) # | A name acts on a name map by qualifying every name in it. |
type Unwrapped Name # | |
class (Typeable a, Ord a, Show a) => IsName a where #
Class for those types which can be used as names. They must
support Typeable
(to facilitate extracting them from
existential wrappers), Ord
(for comparison and efficient
storage) and Show
.
To make an instance of IsName
, you need not define any methods,
just declare it.
WARNING: it is not recommended to use
GeneralizedNewtypeDeriving
in conjunction with IsName
, since
in that case the underlying type and the newtype
will be
considered equivalent when comparing names. For example:
newtype WordN = WordN Int deriving (Show, Ord, Eq, Typeable, IsName)
is unlikely to work as intended, since (1 :: Int)
and (WordN 1)
will be considered equal as names. Instead, use
newtype WordN = WordN Int deriving (Show, Ord, Eq, Typeable, IsName) instance IsName WordN
class Qualifiable q where #
Instances of Qualifiable
are things which can be qualified by
prefixing them with a name.
Qualifiable Name # | Of course, names can be qualified using |
Qualifiable a => Qualifiable [a] # | |
(Ord a, Qualifiable a) => Qualifiable (Set a) # | |
Qualifiable a => Qualifiable (TransInv a) # | |
Qualifiable a => Qualifiable (b -> a) # | |
(Qualifiable a, Qualifiable b) => Qualifiable (a, b) # | |
Qualifiable a => Qualifiable (Map k a) # | |
Qualifiable a => Qualifiable (Measured n a) # | |
(Qualifiable a, Qualifiable b, Qualifiable c) => Qualifiable (a, b, c) # | |
Qualifiable (SubMap b v n m) # |
|
(Metric v, OrderedField n, Semigroup m) => Qualifiable (QDiagram b v n m) # | Diagrams can be qualified so that all their named points can now be referred to using the qualification prefix. |
(.>) :: (IsName a1, IsName a2) => a1 -> a2 -> Name infixr 5 #
Convenient operator for writing qualified names with atomic
components of different types. Instead of writing toName a1 <>
toName a2 <> toName a3
you can just write a1 .> a2 .> a3
.
eachName :: (Typeable a, Ord a, Show a) => Traversal' Name a #
Traversal over each name in a Name
that matches the target type.
>>> toListOf eachName (a
.> False .>b
) :: String "ab" >>>a
.> True .>b
& eachName %~ nota
.> False .>b
Note that the type of the name is very important.
>>> sumOf eachName ((1::Int) .> (2 :: Integer) .> (3 :: Int)) :: Int 4 >>> sumOf eachName ((1::Int) .> (2 :: Integer) .> (3 :: Int)) :: Integer 2
Subdiagram maps
A SubMap
is a map associating names to subdiagrams. There can
be multiple associations for any given name.
SubMap (Map Name [Subdiagram b v n m]) |
Action Name (SubMap b v n m) # | A name acts on a name map by qualifying every name in it. |
Functor (SubMap b v n) # | |
Semigroup (SubMap b v n m) # | |
Monoid (SubMap b v n m) # |
|
Wrapped (SubMap b v n m) # | |
(OrderedField n, Metric v) => HasOrigin (SubMap b v n m) # | |
Transformable (SubMap b v n m) # | |
Qualifiable (SubMap b v n m) # |
|
Rewrapped (SubMap b v n m) (SubMap b' v' n' m') # | |
type Unwrapped (SubMap b v n m) # | |
type N (SubMap b v n m) # | |
type V (SubMap b v n m) # | |
fromNames :: IsName a => [(a, Subdiagram b v n m)] -> SubMap b v n m #
Construct a SubMap
from a list of associations between names
and subdiagrams.
rememberAs :: IsName a => a -> QDiagram b v n m -> SubMap b v n m -> SubMap b v n m #
Add a name/diagram association to a submap.
lookupSub :: IsName nm => nm -> SubMap b v n m -> Maybe [Subdiagram b v n m] #
Look for the given name in a name map, returning a list of subdiagrams associated with that name. If no names match the given name exactly, return all the subdiagrams associated with names of which the given name is a suffix.
Attributes and styles
class (Typeable a, Semigroup a) => AttributeClass a #
data Attribute v n :: * where #
An existential wrapper type to hold attributes. Some attributes are simply inert/static; some are affected by transformations; and some are affected by transformations and can be modified generically.
Attribute :: AttributeClass a => a -> Attribute v n | |
MAttribute :: AttributeClass a => Measured n a -> Attribute v n | |
TAttribute :: (AttributeClass a, Transformable a, V a ~ v, N a ~ n) => a -> Attribute v n |
Show (Attribute v n) # | Shows the kind of attribute and the type contained in the attribute. |
Typeable * n => Semigroup (Attribute v n) # | Attributes form a semigroup, where the semigroup operation simply returns the right-hand attribute when the types do not match, and otherwise uses the semigroup operation specific to the (matching) types. |
(Additive v, Traversable v, Floating n) => Transformable (Attribute v n) # |
|
Each (Style v n) (Style v' n') (Attribute v n) (Attribute v' n') # | |
type N (Attribute v n) # | |
type V (Attribute v n) # | |
A Style
is a heterogeneous collection of attributes, containing
at most one attribute of any given type.
Show (Style v n) # | Show the attributes in the style. |
Typeable * n => Semigroup (Style v n) # | Combine a style by combining the attributes; if the two styles have attributes of the same type they are combined according to their semigroup structure. |
Typeable * n => Monoid (Style v n) # | The empty style contains no attributes. |
Ixed (Style v n) # | |
At (Style v n) # | |
Wrapped (Style v n) # | |
(Additive v, Traversable v, Floating n) => Transformable (Style v n) # | |
Typeable * n => HasStyle (Style v n) # | |
Action (Style v n) m # | Styles have no action on other monoids. |
Rewrapped (Style v n) (Style v' n') # | |
Each (Style v n) (Style v' n') (Attribute v n) (Attribute v' n') # | |
type Index (Style v n) # | |
type IxValue (Style v n) # | |
type Unwrapped (Style v n) # | |
type N (Style v n) # | |
type V (Style v n) # | |
Type class for things which have a style.
applyStyle :: Style (V a) (N a) -> a -> a #
Apply a style by combining it (on the left) with the existing style.
HasStyle a => HasStyle [a] # | |
(HasStyle a, Ord a) => HasStyle (Set a) # | |
HasStyle b => HasStyle (a -> b) # | |
(HasStyle a, HasStyle b, (~) (* -> *) (V a) (V b), (~) * (N a) (N b)) => HasStyle (a, b) # | |
HasStyle a => HasStyle (Map k a) # | |
HasStyle b => HasStyle (Measured n b) # | |
Typeable * n => HasStyle (Style v n) # | |
(Metric v, OrderedField n, Semigroup m) => HasStyle (QDiagram b v n m) # | |
getAttr :: forall a v n. AttributeClass a => Style v n -> Maybe a #
Extract an attribute from a style of a particular type. If the
style contains an attribute of the requested type, it will be
returned wrapped in Just
; otherwise, Nothing
is returned.
Trying to extract a measured attibute will fail. It either has to
be unmeasured with unmeasureAttrs
or use the atMAttr
lens.
atMAttr :: (AttributeClass a, Typeable n) => Lens' (Style v n) (Maybe (Measured n a)) #
Lens onto a measured attribute of a style.
atTAttr :: (V a ~ v, N a ~ n, AttributeClass a, Transformable a) => Lens' (Style v n) (Maybe a) #
Lens onto a transformable attribute of a style.
applyAttr :: (AttributeClass a, HasStyle d) => a -> d -> d #
Apply an attribute to an instance of HasStyle
(such as a
diagram or a style). If the object already has an attribute of
the same type, the new attribute is combined on the left with the
existing attribute, according to their semigroup structure.
applyMAttr :: (AttributeClass a, N d ~ n, HasStyle d) => Measured n a -> d -> d #
Apply a measured attribute to an instance of HasStyle
(such as a
diagram or a style). If the object already has an attribute of
the same type, the new attribute is combined on the left with the
existing attribute, according to their semigroup structure.
applyTAttr :: (AttributeClass a, Transformable a, V a ~ V d, N a ~ N d, HasStyle d) => a -> d -> d #
Apply a transformable attribute to an instance of HasStyle
(such as a diagram or a style). If the object already has an
attribute of the same type, the new attribute is combined on the
left with the existing attribute, according to their semigroup
structure.
Envelopes
Every diagram comes equipped with an envelope. What is an envelope?
Consider first the idea of a bounding box. A bounding box expresses the distance to a bounding plane in every direction parallel to an axis. That is, a bounding box can be thought of as the intersection of a collection of half-planes, two perpendicular to each axis.
More generally, the intersection of half-planes in every direction would give a tight "bounding region", or convex hull. However, representing such a thing intensionally would be impossible; hence bounding boxes are often used as an approximation.
An envelope is an extensional representation of such a "bounding region". Instead of storing some sort of direct representation, we store a function which takes a direction as input and gives a distance to a bounding half-plane as output. The important point is that envelopes can be composed, and transformed by any affine transformation.
Formally, given a vector v
, the envelope computes a scalar s
such
that
- for every point
u
inside the diagram, if the projection of(u - origin)
ontov
iss' *^ v
, thens' <= s
. s
is the smallest such scalar.
There is also a special "empty envelope".
The idea for envelopes came from Sebastian Setzer; see http://byorgey.wordpress.com/2009/10/28/collecting-attributes/#comment-2030. See also Brent Yorgey, Monoids: Theme and Variations, published in the 2012 Haskell Symposium: http://ozark.hendrix.edu/~yorgey/pub/monoid-pearl.pdf; video: http://www.youtube.com/watch?v=X-8NCkD2vOw.
Show (Envelope v n) # | |
Ord n => Semigroup (Envelope v n) # | |
Ord n => Monoid (Envelope v n) # | |
Wrapped (Envelope v n) # | |
(Metric v, Fractional n) => HasOrigin (Envelope v n) # | The local origin of an envelope is the point with respect to which bounding queries are made, i.e. the point from which the input vectors are taken to originate. |
(Metric v, Floating n) => Transformable (Envelope v n) # | |
(Metric v, OrderedField n) => Enveloped (Envelope v n) # | |
(Metric v, OrderedField n) => Juxtaposable (Envelope v n) # | |
Rewrapped (Envelope v n) (Envelope v' n') # | |
type Unwrapped (Envelope v n) # | |
type N (Envelope v n) # | |
type V (Envelope v n) # | |
appEnvelope :: Envelope v n -> Maybe (v n -> n) #
"Apply" an envelope by turning it into a function. Nothing
is returned iff the envelope is empty.
onEnvelope :: ((v n -> n) -> v n -> n) -> Envelope v n -> Envelope v n #
A convenient way to transform an envelope, by specifying a
transformation on the underlying v n -> n
function. The empty
envelope is unaffected.
mkEnvelope :: (v n -> n) -> Envelope v n #
Create an envelope from a v n -> n
function.
class (Metric (V a), OrderedField (N a)) => Enveloped a where #
Enveloped
abstracts over things which have an envelope.
getEnvelope :: a -> Envelope (V a) (N a) #
Compute the envelope of an object. For types with an intrinsic
notion of "local origin", the envelope will be based there.
Other types (e.g. Trail
) may have some other default
reference point at which the envelope will be based; their
instances should document what it is.
Enveloped b => Enveloped [b] # | |
Enveloped b => Enveloped (Set b) # | |
Enveloped t => Enveloped (TransInv t) # | |
(Enveloped a, Enveloped b, (~) (* -> *) (V a) (V b), (~) * (N a) (N b)) => Enveloped (a, b) # | |
Enveloped b => Enveloped (Map k b) # | |
(OrderedField n, Metric v) => Enveloped (Point v n) # | |
(Metric v, OrderedField n) => Enveloped (Envelope v n) # | |
(OrderedField n, Metric v, Monoid' m) => Enveloped (Subdiagram b v n m) # | |
(Metric v, OrderedField n, Monoid' m) => Enveloped (QDiagram b v n m) # | |
envelopeVMay :: Enveloped a => Vn a -> a -> Maybe (Vn a) #
Compute the vector from the local origin to a separating
hyperplane in the given direction, or Nothing
for the empty
envelope.
envelopeV :: Enveloped a => Vn a -> a -> Vn a #
Compute the vector from the local origin to a separating hyperplane in the given direction. Returns the zero vector for the empty envelope.
envelopePMay :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> Maybe (Point v n) #
Compute the point on a separating hyperplane in the given
direction, or Nothing
for the empty envelope.
envelopeP :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> Point v n #
Compute the point on a separating hyperplane in the given direction. Returns the origin for the empty envelope.
diameter :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> n #
Compute the diameter of a enveloped object along a particular vector. Returns zero for the empty envelope.
radius :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> n #
Compute the "radius" (1/2 the diameter) of an enveloped object along a particular vector.
size :: (V a ~ v, N a ~ n, Enveloped a, HasBasis v) => a -> v n #
The smallest positive axis-parallel vector that bounds the envelope of an object.
Traces
Every diagram comes equipped with a trace. Intuitively, the trace for a diagram is like a raytracer: given a line (represented as a base point and a direction vector), the trace computes a sorted list of signed distances from the base point to all intersections of the line with the boundary of the diagram.
Note that the outputs are not absolute distances, but multipliers
relative to the input vector. That is, if the base point is p
and direction vector is v
, and one of the output scalars is
s
, then there is an intersection at the point p .+^ (s *^ v)
.
Trace | |
|
Show (Trace v n) # | |
Ord n => Semigroup (Trace v n) # | |
Ord n => Monoid (Trace v n) # | |
Wrapped (Trace v n) # | |
(Additive v, Num n) => HasOrigin (Trace v n) # | |
(Additive v, Num n) => Transformable (Trace v n) # | |
(Additive v, Ord n) => Traced (Trace v n) # | |
Rewrapped (Trace v n) (Trace v' n') # | |
type Unwrapped (Trace v n) # | |
type N (Trace v n) # | |
type V (Trace v n) # | |
data SortedList a #
A newtype wrapper around a list which maintains the invariant
that the list is sorted. The constructor is not exported; use
the smart constructor mkSortedList
(which sorts the given list)
instead.
Ord a => Semigroup (SortedList a) # |
|
Ord a => Monoid (SortedList a) # |
|
mkSortedList :: Ord a => [a] -> SortedList a #
A smart constructor for the SortedList
type, which sorts the
input to ensure the SortedList
invariant.
getSortedList :: SortedList a -> [a] #
Project the (guaranteed sorted) list out of a SortedList
wrapper.
mkTrace :: (Point v n -> v n -> SortedList n) -> Trace v n #
class (Additive (V a), Ord (N a)) => Traced a where #
Traced
abstracts over things which have a trace.
Traced b => Traced [b] # | |
Traced b => Traced (Set b) # | |
Traced t => Traced (TransInv t) # | |
(Traced a, Traced b, SameSpace a b) => Traced (a, b) # | |
Traced b => Traced (Map k b) # | |
(Additive v, Ord n) => Traced (Point v n) # | The trace of a single point is the empty trace, i.e. the one which returns no intersection points for every query. Arguably it should return a single finite distance for vectors aimed directly at the given point, but due to floating-point inaccuracy this is problematic. Note that the envelope for a single point is not the empty envelope (see Diagrams.Core.Envelope). |
(Additive v, Ord n) => Traced (Trace v n) # | |
(OrderedField n, Metric v, Semigroup m) => Traced (Subdiagram b v n m) # | |
(Metric v, OrderedField n, Semigroup m) => Traced (QDiagram b v n m) # | |
traceV :: (n ~ N a, Num n, Traced a) => Point (V a) n -> V a n -> a -> Maybe (V a n) #
Compute the vector from the given point p
to the "smallest"
boundary intersection along the given vector v
. The
"smallest" boundary intersection is defined as the one given by
p .+^ (s *^ v)
for the smallest (most negative) value of
s
. Return Nothing
if there is no intersection. See also
traceP
.
See also rayTraceV
which uses the smallest positive
intersection, which is often more intuitive behavior.
traceP :: (n ~ N a, Traced a, Num n) => Point (V a) n -> V a n -> a -> Maybe (Point (V a) n) #
Compute the "smallest" boundary point along the line determined
by the given point p
and vector v
. The "smallest" boundary
point is defined as the one given by p .+^ (s *^ v)
for
the smallest (most negative) value of s
. Return Nothing
if
there is no such boundary point. See also traceV
.
See also rayTraceP
which uses the smallest positive
intersection, which is often more intuitive behavior.
maxTraceV :: (n ~ N a, Num n, Traced a) => Point (V a) n -> V a n -> a -> Maybe (V a n) #
Like traceV
, but computes a vector to the "largest" boundary
point instead of the smallest. (Note, however, the "largest"
boundary point may still be in the opposite direction from the
given vector, if all the boundary points are, as in the third
example shown below.)
maxTraceP :: (n ~ N a, Num n, Traced a) => Point (V a) n -> V a n -> a -> Maybe (Point (V a) n) #
Like traceP
, but computes the "largest" boundary point
instead of the smallest. (Note, however, the "largest" boundary
point may still be in the opposite direction from the given
vector, if all the boundary points are.)
rayTraceV :: (n ~ N a, Traced a, Num n) => Point (V a) n -> V a n -> a -> Maybe (V a n) #
Compute the vector from the given point to the closest boundary
point of the given object in the given direction, or Nothing
if
there is no such boundary point (as in the third example
below). Note that unlike traceV
, only positive boundary
points are considered, i.e. boundary points corresponding to a
positive scalar multiple of the direction vector. This is
intuitively the "usual" behavior of a raytracer, which only
considers intersections "in front of" the camera. Compare the
second example diagram below with the second example shown for
traceV
.
rayTraceP :: (n ~ N a, Traced a, Num n) => Point (V a) n -> V a n -> a -> Maybe (Point (V a) n) #
Compute the boundary point on an object which is closest to the
given base point in the given direction, or Nothing
if there is
no such boundary point. Note that unlike traceP
, only positive
boundary points are considered, i.e. boundary points
corresponding to a positive scalar multiple of the direction
vector. This is intuitively the "usual" behavior of a raytracer,
which only considers intersection points "in front of" the
camera.
maxRayTraceV :: (n ~ N a, Traced a, Num n) => Point (V a) n -> V a n -> a -> Maybe (V a n) #
Like rayTraceV
, but computes a vector to the "largest"
boundary point instead of the smallest. Considers only
positive boundary points.
maxRayTraceP :: (n ~ N a, Traced a, Num n) => Point (V a) n -> V a n -> a -> Maybe (Point (V a) n) #
Like rayTraceP
, but computes the "largest" boundary point
instead of the smallest. Considers only positive boundary
points.
Things with local origins
Class of types which have an intrinsic notion of a "local origin", i.e. things which are not invariant under translation, and which allow the origin to be moved.
One might wonder why not just use Transformable
instead of
having a separate class for HasOrigin
; indeed, for types which
are instances of both we should have the identity
moveOriginTo (origin .^+ v) === translate (negated v)
The reason is that some things (e.g. vectors, Trail
s) are
transformable but are translationally invariant, i.e. have no
origin.
moveOriginTo :: Point (V t) (N t) -> t -> t #
Move the local origin to another point.
Note that this function is in some sense dual to translate
(for types which are also Transformable
); moving the origin
itself while leaving the object "fixed" is dual to fixing the
origin and translating the diagram.
HasOrigin t => HasOrigin [t] # | |
(HasOrigin t, Ord t) => HasOrigin (Set t) # | |
HasOrigin (TransInv t) # | |
(HasOrigin t, HasOrigin s, SameSpace s t) => HasOrigin (s, t) # | |
HasOrigin t => HasOrigin (Map k t) # | |
(Additive v, Num n) => HasOrigin (Point v n) # | |
HasOrigin t => HasOrigin (Measured n t) # | |
(Additive v, Num n) => HasOrigin (Transformation v n) # | |
(Additive v, Num n) => HasOrigin (Trace v n) # | |
(Metric v, Fractional n) => HasOrigin (Envelope v n) # | The local origin of an envelope is the point with respect to which bounding queries are made, i.e. the point from which the input vectors are taken to originate. |
(Additive v, Num n) => HasOrigin (Query v n m) # | |
(OrderedField n, Metric v) => HasOrigin (SubMap b v n m) # | |
(Metric v, OrderedField n) => HasOrigin (Subdiagram b v n m) # | |
(Metric v, OrderedField n, Semigroup m) => HasOrigin (QDiagram b v n m) # | Every diagram has an intrinsic "local origin" which is the basis for all combining operations. |
moveOriginBy :: (V t ~ v, N t ~ n, HasOrigin t) => v n -> t -> t #
Move the local origin by a relative vector.
Juxtaposable things
class Juxtaposable a where #
Class of things which can be placed "next to" other things, for some appropriate notion of "next to".
juxtapose :: Vn a -> a -> a -> a #
juxtapose v a1 a2
positions a2
next to a1
in the
direction of v
. In particular, place a2
so that v
points
from the local origin of a1
towards the old local origin of
a2
; a1
's local origin becomes a2
's new local origin. The
result is just a translated version of a2
. (In particular,
this operation does not combine a1
and a2
in any way.)
(Enveloped b, HasOrigin b) => Juxtaposable [b] # | |
(Enveloped b, HasOrigin b, Ord b) => Juxtaposable (Set b) # | |
Juxtaposable a => Juxtaposable (b -> a) # | |
(Enveloped a, HasOrigin a, Enveloped b, HasOrigin b, (~) (* -> *) (V a) (V b), (~) * (N a) (N b)) => Juxtaposable (a, b) # | |
(Enveloped b, HasOrigin b) => Juxtaposable (Map k b) # | |
Juxtaposable a => Juxtaposable (Measured n a) # | |
(Metric v, OrderedField n) => Juxtaposable (Envelope v n) # | |
(Metric v, OrderedField n, Monoid' m) => Juxtaposable (QDiagram b v n m) # | |
juxtaposeDefault :: (Enveloped a, HasOrigin a) => Vn a -> a -> a -> a #
Queries
A query is a function that maps points in a vector space to values in some monoid. Queries naturally form a monoid, with two queries being combined pointwise.
The idea for annotating diagrams with monoidal queries came from the graphics-drawingcombinators package, http://hackage.haskell.org/package/graphics-drawingcombinators.
Functor v => Corepresentable (Query v) # | |
Functor v => Profunctor (Query v) # | |
Functor v => Closed (Query v) # | |
Functor v => Costrong (Query v) # | |
Functor v => Cosieve (Query v) (Point v) # | |
Monad (Query v n) # | |
Functor (Query v n) # | |
Applicative (Query v n) # | |
Distributive (Query v n) # | |
Representable (Query v n) # | |
Semigroup m => Semigroup (Query v n m) # | |
Monoid m => Monoid (Query v n m) # | |
Wrapped (Query v n m) # | |
(Additive v, Num n) => HasOrigin (Query v n m) # | |
(Additive v, Num n) => Transformable (Query v n m) # | |
Rewrapped (Query v a m) (Query v' a' m') # | |
type Corep (Query v) # | |
type Rep (Query v n) # | |
type Unwrapped (Query v n m) # | |
type N (Query v n m) # | |
type V (Query v n m) # | |
Primitives
A value of type Prim b v n
is an opaque (existentially quantified)
primitive which backend b
knows how to render in vector space v
.
Prim :: (Transformable p, Typeable p, Renderable p b) => p -> Prim b (V p) (N p) |
Transformable (Prim b v n) # | The |
Renderable (Prim b v n) b # | The |
type N (Prim b v n) # | |
type V (Prim b v n) # | |
Diagrams
The fundamental diagram type. The type variables are as follows:
b
represents the backend, such asSVG
orCairo
. Note that each backend also exports a type synonymB
for itself, so the type variableb
may also typically be instantiated byB
, meaning "use whatever backend is in scope".v
represents the vector space of the diagram. Typical instantiations includeV2
(for a two-dimensional diagram) orV3
(for a three-dimensional diagram).n
represents the numerical field the diagram uses. Typically this will be a concrete numeric type likeDouble
.m
is the monoidal type of "query annotations": each point in the diagram has a value of typem
associated to it, and these values are combined according to theMonoid
instance form
. Most often,m
is simply instantiated toAny
, associating a simpleBool
value to each point indicating whether the point is inside the diagram;Diagram
is a synonym forQDiagram
withm
thus instantiated toAny
.
Diagrams can be combined via their Monoid
instance, transformed
via their Transformable
instance, and assigned attributes via
their HasStyle
instance.
Note that the Q
in QDiagram
stands for "Queriable", as
distinguished from Diagram
, where m
is fixed to Any
. This
is not really a very good name, but it's probably not worth
changing it at this point.
Functor (QDiagram b v n) # | |
(Metric v, OrderedField n, Semigroup m) => Semigroup (QDiagram b v n m) # | |
(Metric v, OrderedField n, Semigroup m) => Monoid (QDiagram b v n m) # | Diagrams form a monoid since each of their components do: the empty diagram has no primitives, an empty envelope, an empty trace, no named subdiagrams, and a constantly empty query function. Diagrams compose by aligning their respective local origins. The new diagram has all the primitives and all the names from the two diagrams combined, and query functions are combined pointwise. The first diagram goes on top of the second. "On top of" probably only makes sense in vector spaces of dimension lower than 3, but in theory it could make sense for, say, 3-dimensional diagrams when viewed by 4-dimensional beings. |
Wrapped (QDiagram b v n m) # | |
(Metric v, OrderedField n, Semigroup m) => HasOrigin (QDiagram b v n m) # | Every diagram has an intrinsic "local origin" which is the basis for all combining operations. |
(OrderedField n, Metric v, Semigroup m) => Transformable (QDiagram b v n m) # | Diagrams can be transformed by transforming each of their components appropriately. |
(Metric v, OrderedField n, Semigroup m) => Qualifiable (QDiagram b v n m) # | Diagrams can be qualified so that all their named points can now be referred to using the qualification prefix. |
(Metric v, OrderedField n, Semigroup m) => HasStyle (QDiagram b v n m) # | |
(Metric v, OrderedField n, Semigroup m) => Traced (QDiagram b v n m) # | |
(Metric v, OrderedField n, Monoid' m) => Enveloped (QDiagram b v n m) # | |
(Metric v, OrderedField n, Monoid' m) => Juxtaposable (QDiagram b v n m) # | |
Rewrapped (QDiagram b v n m) (QDiagram b' v' n' m') # | |
type Unwrapped (QDiagram b v n m) # | |
type N (QDiagram b v n m) # | |
type V (QDiagram b v n m) # | |
type Diagram b = QDiagram b (V b) (N b) Any #
Diagram b
is a synonym for
. That is,
the default sort of diagram is one where querying at a point
simply tells you whether the diagram contains that point or not.
Transforming a default diagram into one with a more interesting
query can be done via the QDiagram
b (V b) (N b) Any
Functor
instance of
or
the QDiagram
b v nvalue
function.
mkQD :: Prim b v n -> Envelope v n -> Trace v n -> SubMap b v n m -> Query v n m -> QDiagram b v n m #
Create a diagram from a single primitive, along with an envelope, trace, subdiagram map, and query function.
pointDiagram :: (Metric v, Fractional n) => Point v n -> QDiagram b v n m #
Create a "point diagram", which has no content, no trace, an empty query, and a point envelope.
names :: (Metric v, Semigroup m, OrderedField n) => QDiagram b v n m -> [(Name, [Point v n])] #
Get a list of names of subdiagrams and their locations.
query :: Monoid m => QDiagram b v n m -> Query v n m #
Get the query function associated with a diagram.
nameSub :: (IsName nm, Metric v, OrderedField n, Semigroup m) => (QDiagram b v n m -> Subdiagram b v n m) -> nm -> QDiagram b v n m -> QDiagram b v n m #
Attach an atomic name to a certain subdiagram, computed from the
given diagram /with the mapping from name to subdiagram
included/. The upshot of this knot-tying is that if d' = d #
named x
, then lookupName x d' == Just d'
(instead of Just
d
).
withName :: (IsName nm, Metric v, Semigroup m, OrderedField n) => nm -> (Subdiagram b v n m -> QDiagram b v n m -> QDiagram b v n m) -> QDiagram b v n m -> QDiagram b v n m #
Given a name and a diagram transformation indexed by a subdiagram, perform the transformation using the most recent subdiagram associated with (some qualification of) the name, or perform the identity transformation if the name does not exist.
withNameAll :: (IsName nm, Metric v, Semigroup m, OrderedField n) => nm -> ([Subdiagram b v n m] -> QDiagram b v n m -> QDiagram b v n m) -> QDiagram b v n m -> QDiagram b v n m #
Given a name and a diagram transformation indexed by a list of subdiagrams, perform the transformation using the collection of all such subdiagrams associated with (some qualification of) the given name.
withNames :: (IsName nm, Metric v, Semigroup m, OrderedField n) => [nm] -> ([Subdiagram b v n m] -> QDiagram b v n m -> QDiagram b v n m) -> QDiagram b v n m -> QDiagram b v n m #
Given a list of names and a diagram transformation indexed by a list of subdiagrams, perform the transformation using the list of most recent subdiagrams associated with (some qualification of) each name. Do nothing (the identity transformation) if any of the names do not exist.
localize :: forall b v n m. (Metric v, OrderedField n, Semigroup m) => QDiagram b v n m -> QDiagram b v n m #
"Localize" a diagram by hiding all the names, so they are no longer visible to the outside.
href :: (Metric v, OrderedField n, Semigroup m) => String -> QDiagram b v n m -> QDiagram b v n m #
Make a diagram into a hyperlink. Note that only some backends will honor hyperlink annotations.
opacityGroup :: (Metric v, OrderedField n, Semigroup m) => Double -> QDiagram b v n m -> QDiagram b v n m #
Change the transparency of a Diagram
as a group.
groupOpacity :: (Metric v, OrderedField n, Semigroup m) => Double -> QDiagram b v n m -> QDiagram b v n m #
Change the transparency of a Diagram
as a group.
setEnvelope :: forall b v n m. (OrderedField n, Metric v, Monoid' m) => Envelope v n -> QDiagram b v n m -> QDiagram b v n m #
Replace the envelope of a diagram.
setTrace :: forall b v n m. (OrderedField n, Metric v, Semigroup m) => Trace v n -> QDiagram b v n m -> QDiagram b v n m #
Replace the trace of a diagram.
atop :: (OrderedField n, Metric v, Semigroup m) => QDiagram b v n m -> QDiagram b v n m -> QDiagram b v n m infixl 6 #
A convenient synonym for mappend
on diagrams, designed to be
used infix (to help remember which diagram goes on top of which
when combining them, namely, the first on top of the second).
Subdiagrams
data Subdiagram b v n m #
A Subdiagram
represents a diagram embedded within the context
of a larger diagram. Essentially, it consists of a diagram
paired with any accumulated information from the larger context
(transformations, attributes, etc.).
Subdiagram (QDiagram b v n m) (DownAnnots v n) |
Functor (Subdiagram b v n) # | |
(Metric v, OrderedField n) => HasOrigin (Subdiagram b v n m) # | |
Transformable (Subdiagram b v n m) # | |
(OrderedField n, Metric v, Semigroup m) => Traced (Subdiagram b v n m) # | |
(OrderedField n, Metric v, Monoid' m) => Enveloped (Subdiagram b v n m) # | |
type N (Subdiagram b v n m) # | |
type V (Subdiagram b v n m) # | |
mkSubdiagram :: QDiagram b v n m -> Subdiagram b v n m #
Turn a diagram into a subdiagram with no accumulated context.
getSub :: (Metric v, OrderedField n, Semigroup m) => Subdiagram b v n m -> QDiagram b v n m #
Turn a subdiagram into a normal diagram, including the enclosing
context. Concretely, a subdiagram is a pair of (1) a diagram and
(2) a "context" consisting of an extra transformation and
attributes. getSub
simply applies the transformation and
attributes to the diagram to get the corresponding "top-level"
diagram.
rawSub :: Subdiagram b v n m -> QDiagram b v n m #
Extract the "raw" content of a subdiagram, by throwing away the context.
location :: (Additive v, Num n) => Subdiagram b v n m -> Point v n #
Get the location of a subdiagram; that is, the location of its local origin with respect to the vector space of its parent diagram. In other words, the point where its local origin "ended up".
subPoint :: (Metric v, OrderedField n) => Point v n -> Subdiagram b v n m #
Create a "point subdiagram", that is, a pointDiagram
(with no
content and a point envelope) treated as a subdiagram with local
origin at the given point. Note this is not the same as
mkSubdiagram . pointDiagram
, which would result in a subdiagram
with local origin at the parent origin, rather than at the given
point.
Measurements
'Measured n a' is an object that depends on local
, normalized
and global
scales. The normalized
and global
scales are
calculated when rendering a diagram.
For attributes, the local
scale gets multiplied by the average
scale of the transform.
Profunctor Measured # | |
Monad (Measured n) # | |
Functor (Measured n) # | |
Applicative (Measured n) # | |
Distributive (Measured n) # | |
Representable (Measured n) # | |
Additive (Measured n) # | |
Floating a => Floating (Measured n a) # | |
Fractional a => Fractional (Measured n a) # | |
Num a => Num (Measured n a) # | |
Semigroup a => Semigroup (Measured n a) # | |
Monoid a => Monoid (Measured n a) # | |
HasOrigin t => HasOrigin (Measured n t) # | |
(InSpace v n t, Transformable t, HasLinearMap v, Floating n) => Transformable (Measured n t) # | |
Qualifiable a => Qualifiable (Measured n a) # | |
HasStyle b => HasStyle (Measured n b) # | |
Juxtaposable a => Juxtaposable (Measured n a) # | |
MonadReader (n, n, n) (Measured n) # | |
type Rep (Measured n) # | |
type N (Measured n a) # | |
type V (Measured n a) # | |
fromMeasured :: Num n => n -> n -> Measured n a -> a #
fromMeasured globalScale normalizedScale measure -> a
global :: Num n => n -> Measure n #
Global units are scaled so that they are interpreted relative to the size of the final rendered diagram.
normalized :: Num n => n -> Measure n #
Normalized units get scaled so that one normalized unit is the size of the final diagram.
scaleLocal :: Num n => n -> Measured n a -> Measured n a #
Scale the local units of a Measured
thing.
Backends
Abstract diagrams are rendered to particular formats by
backends. Each backend/vector space combination must be an
instance of the Backend
class.
A minimal complete definition consists of Render
, Result
,
Options
, and renderRTree
. However, most backends will want to
implement adjustDia
as well; the default definition does
nothing. Some useful standard definitions are provided in the
Diagrams.TwoD.Adjust
module from the diagrams-lib
package.
An intermediate representation used for rendering primitives.
(Typically, this will be some sort of monad, but it need not
be.) The Renderable
class guarantees that a backend will be
able to convert primitives into this type; how these rendered
primitives are combined into an ultimate Result
is completely
up to the backend.
The result of running/interpreting a rendering operation.
Backend-specific rendering options.
adjustDia :: (Additive v, Monoid' m, Num n) => b -> Options b v n -> QDiagram b v n m -> (Options b v n, Transformation v n, QDiagram b v n m) #
adjustDia
allows the backend to make adjustments to the final
diagram (e.g. to adjust the size based on the options) before
rendering it. It returns a modified options record, the
transformation applied to the diagram (which can be used to
convert attributes whose value is Measure
, or transform
e.g. screen coordinates back into local diagram coordinates),
and the adjusted diagram itself.
See the diagrams-lib package (particularly the
Diagrams.TwoD.Adjust
module) for some useful implementations.
renderRTree :: b -> Options b v n -> RTree b v n Annotation -> Result b v n #
Given some options, take a representation of a diagram as a
tree and render it. The RTree
has already been simplified
and has all measurements converted to Output
units.
Backend NullBackend v n # | |
class Transformable t => Renderable t b where #
The Renderable type class connects backends to primitives which they know how to render.
render :: b -> t -> Render b (V t) (N t) #
Given a token representing the backend and a transformable object, render it in the appropriate rendering context.
Renderable (Prim b v n) b # | The |
renderDia :: (Backend b v n, HasLinearMap v, Metric v, Typeable n, OrderedField n, Monoid' m) => b -> Options b v n -> QDiagram b v n m -> Result b v n #
Render a diagram.
renderDiaT :: (Backend b v n, HasLinearMap v, Metric v, Typeable n, OrderedField n, Monoid' m) => b -> Options b v n -> QDiagram b v n m -> (Transformation v n, Result b v n) #
Render a diagram, returning also the transformation which was
used to convert the diagram from its ("global") coordinate
system into the output coordinate system. The inverse of this
transformation can be used, for example, to convert output/screen
coordinates back into diagram coordinates. See also adjustDia
.
The null backend
data NullBackend #
A null backend which does no actual rendering. It is provided
mainly for convenience in situations where you must give a
diagram a concrete, monomorphic type, but don't actually care
which one. See D
for more explanation and examples.
It is courteous, when defining a new primitive P
, to make an instance
instance Renderable P NullBackend where render _ _ = mempty
This ensures that the trick with D
annotations can be used for
diagrams containing your primitive.
Backend NullBackend v n # | |
Monoid (Render NullBackend v n) # | |
data Render NullBackend # | |
data Options NullBackend # | |
type Result NullBackend v n # | |
type D v n = QDiagram NullBackend v n Any #
The D
type is provided for convenience in situations where you
must give a diagram a concrete, monomorphic type, but don't care
which one. Such situations arise when you pass a diagram to a
function which is polymorphic in its input but monomorphic in its
output, such as width
, height
, phantom
, or names
. Such
functions compute some property of the diagram, or use it to
accomplish some other purpose, but do not result in the diagram
being rendered. If the diagram does not have a monomorphic type,
GHC complains that it cannot determine the diagram's type.
For example, here is the error we get if we try to compute the
width of an image (this example requires diagrams-lib
):
ghci> width (image (uncheckedImageRef "foo.png" 200 200)) <interactive>:11:8: No instance for (Renderable (DImage n0 External) b0) arising from a use ofimage
The type variablesn0
,b0
are ambiguous Possible fix: add a type signature that fixes these type variable(s) Note: there is a potential instance available: instance Fractional n => Renderable (DImage n a) NullBackend -- Defined inImage
Possible fix: add an instance declaration for (Renderable (DImage n0 External) b0) In the first argument ofwidth
, namely `(image (uncheckedImageRef "foo.png" 200 200))' In the expression: width (image (uncheckedImageRef "foo.png" 200 200)) In an equation forit
: it = width (image (uncheckedImageRef "foo.png" 200 200))
GHC complains that there is no instance for Renderable (DImage n0
External) b0
; what is really going on is that it does not have enough
information to decide what backend to use (hence the
uninstantiated n0
and b0
). This is annoying because we know that the
choice of backend cannot possibly affect the width of the image
(it's 200! it's right there in the code!); but there is no way
for GHC to know that.
The solution is to annotate the call to image
with the type
, like so:D
V2
Double
ghci> width (image (uncheckedImageRef "foo.png" 200 200) :: D V2 Double) 200.00000000000006
(It turns out the width wasn't 200 after all...)
As another example, here is the error we get if we try to compute the width of a radius-1 circle:
ghci> width (circle 1) <interactive>:12:1: Couldn't match expected typeV2
with actual type `V a0' The type variablea0
is ambiguous Possible fix: add a type signature that fixes these type variable(s) In the expression: width (circle 1) In an equation forit
: it = width (circle 1)
There's even more ambiguity here. Whereas image
always returns
a Diagram
, the circle
function can produce any TrailLike
type, and the width
function can consume any Enveloped
type,
so GHC has no idea what type to pick to go in the middle.
However, the solution is the same:
ghci> width (circle 1 :: D V2 Double) 1.9999999999999998
Convenience classes
class (HasBasis v, Traversable v) => HasLinearMap v #
HasLinearMap
is a poor man's class constraint synonym, just to
help shorten some of the ridiculously long constraint sets.
(HasBasis v, Traversable v) => HasLinearMap v # | |
class (Additive v, Representable v, Rep v ~ E v) => HasBasis v #
An Additive
vector space whose representation is made up of basis elements.
class (Floating s, Ord s) => OrderedField s #
When dealing with envelopes we often want scalars to be an ordered field (i.e. support all four arithmetic operations and be totally ordered) so we introduce this class as a convenient shorthand.
(Floating s, Ord s) => OrderedField s # | |
class (Typeable n, RealFloat n) => TypeableFloat n #
(Typeable * n, RealFloat n) => TypeableFloat n # | |