-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/

-- | Core libraries for diagrams EDSL
--   
--   The core modules underlying diagrams, an embedded domain-specific
--   language for compositional, declarative drawing.
@package diagrams-core
@version 1.5.1.1

-- | Type family for identifying associated vector spaces.
module Diagrams.Core.V

-- | 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 family V a :: Type -> Type

-- | The numerical field for the object, the number type used for
--   calculations.
type family N a

-- | Convenient 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.
type Vn a = V a N a

-- | InSpace v n a means the type a belongs to the vector
--   space v n, where v is Additive and n
--   is a Num.
type InSpace (v :: Type -> Type) n a = (V a ~ v, N a ~ n, Additive v, Num n)

-- | SameSpace a b means the types a and b
--   belong to the same vector space v n.
type SameSpace a b = (V a ~ V b, N a ~ N b)

-- | A type for points (as distinct from vectors).
module Diagrams.Core.Points

-- | A handy wrapper to help distinguish points from vectors at the type
--   level
newtype Point (f :: Type -> Type) a
P :: f a -> Point (f :: Type -> Type) a

-- | Vector spaces have origins.
origin :: forall (f :: Type -> Type) a. (Additive f, Num a) => Point f a

-- | Scale a point by a scalar. Specialized version of (*^).
(*.) :: forall (v :: Type -> Type) n. (Functor v, Num n) => n -> Point v n -> Point v n

-- | An isomorphism between points and vectors, given a reference point.
relative :: forall (f :: Type -> Type) a. (Additive f, Num a) => Point f a -> Iso' (Point f a) (f a)
_Point :: forall f1 a g b p f2. (Profunctor p, Functor f2) => p (f1 a) (f2 (g b)) -> p (Point f1 a) (f2 (Point g b))

-- | Mirror a point through a given point.
reflectThrough :: forall (v :: Type -> Type) n. (Additive v, Num n) => Point v n -> Point v n -> Point v n

-- | Reflect a point across the origin.
mirror :: forall (v :: Type -> Type) n. (Additive v, Num n) => Point v n -> Point v n

-- | Apply a transformation relative to the given point.
relative2 :: (Additive v, Num n) => Point v n -> (v n -> v n -> v n) -> Point v n -> Point v n -> Point v n

-- | Apply a transformation relative to the given point.
relative3 :: (Additive v, Num n) => Point v n -> (v n -> v n -> v n -> v n) -> Point v n -> Point v n -> Point v n -> Point v n

module Diagrams.Core.Measure

-- | '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.
newtype Measured n a
Measured :: ((n, n, n) -> a) -> Measured n a
[unmeasure] :: Measured n a -> (n, n, n) -> a

-- | A measure is a Measured number.
type Measure n = Measured n n

-- | 
--   fromMeasured globalScale normalizedScale measure -> a
--   
fromMeasured :: Num n => n -> n -> Measured n a -> a

-- | Output units don't change.
output :: n -> Measure n

-- | Local units are scaled by the average scale of a transform.
local :: Num n => n -> Measure n

-- | Global units are scaled so that they are interpreted relative to the
--   size of the final rendered diagram.
global :: Num n => n -> Measure n

-- | Normalized units get scaled so that one normalized unit is the size of
--   the final diagram.
normalized :: Num n => n -> Measure n

-- | Just like normalized but spelt properly.
normalised :: Num n => n -> Measure n

-- | Scale the local units of a Measured thing.
scaleLocal :: Num n => n -> Measured n a -> Measured n a

-- | Calculate the larger of two measures.
atLeast :: Ord n => Measure n -> Measure n -> Measure n

-- | Calculate the smaller of two measures.
atMost :: Ord n => Measure n -> Measure n -> Measure n
instance Linear.Vector.Additive (Diagrams.Core.Measure.Measured n)
instance GHC.Internal.Base.Applicative (Diagrams.Core.Measure.Measured n)
instance Data.Distributive.Distributive (Diagrams.Core.Measure.Measured n)
instance GHC.Internal.Float.Floating a => GHC.Internal.Float.Floating (Diagrams.Core.Measure.Measured n a)
instance GHC.Internal.Real.Fractional a => GHC.Internal.Real.Fractional (Diagrams.Core.Measure.Measured n a)
instance GHC.Internal.Base.Functor (Diagrams.Core.Measure.Measured n)
instance GHC.Internal.Base.Monad (Diagrams.Core.Measure.Measured n)
instance Control.Monad.Reader.Class.MonadReader (n, n, n) (Diagrams.Core.Measure.Measured n)
instance GHC.Internal.Base.Monoid a => GHC.Internal.Base.Monoid (Diagrams.Core.Measure.Measured n a)
instance GHC.Internal.Num.Num a => GHC.Internal.Num.Num (Diagrams.Core.Measure.Measured n a)
instance Data.Profunctor.Unsafe.Profunctor Diagrams.Core.Measure.Measured
instance Data.Functor.Rep.Representable (Diagrams.Core.Measure.Measured n)
instance GHC.Internal.Base.Semigroup a => GHC.Internal.Base.Semigroup (Diagrams.Core.Measure.Measured n a)

-- | Types which have an intrinsic notion of a "local origin", i.e.
--   things which are not invariant under translation.
module Diagrams.Core.HasOrigin

-- | 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, Trails) are
--   transformable but are translationally invariant, i.e. have no origin.
class HasOrigin 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.
moveOriginTo :: HasOrigin t => Point (V t) (N t) -> t -> t

-- | Move the local origin by a relative vector.
moveOriginBy :: (V t ~ v, N t ~ n, HasOrigin t) => 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
--   
--   
moveTo :: forall (v :: Type -> Type) n t. (InSpace v n t, HasOrigin t) => Point v n -> t -> 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.
place :: forall (v :: Type -> Type) n t. (InSpace v n t, HasOrigin t) => t -> Point v n -> t
instance Diagrams.Core.HasOrigin.HasOrigin t => Diagrams.Core.HasOrigin.HasOrigin [t]
instance Diagrams.Core.HasOrigin.HasOrigin t => Diagrams.Core.HasOrigin.HasOrigin (Data.Map.Internal.Map k t)
instance Diagrams.Core.HasOrigin.HasOrigin t => Diagrams.Core.HasOrigin.HasOrigin (Diagrams.Core.Measure.Measured n t)
instance (Linear.Vector.Additive v, GHC.Internal.Num.Num n) => Diagrams.Core.HasOrigin.HasOrigin (Linear.Affine.Point v n)
instance (Diagrams.Core.HasOrigin.HasOrigin t, GHC.Classes.Ord t) => Diagrams.Core.HasOrigin.HasOrigin (Data.Set.Internal.Set t)
instance (Diagrams.Core.HasOrigin.HasOrigin t, Diagrams.Core.HasOrigin.HasOrigin s, Diagrams.Core.V.SameSpace s t) => Diagrams.Core.HasOrigin.HasOrigin (s, t)

-- | 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.
module Diagrams.Core.Transform

-- | (v1 :-: v2) is a linear map paired with its inverse.
data u :-: v
(:-:) :: (u -> v) -> (v -> u) -> (:-:) u v
infixr 7 :-:
infixr 7 :-:

-- | Create an invertible linear map from two functions which are assumed
--   to be linear inverses.
(<->) :: (u -> v) -> (v -> u) -> u :-: v

-- | Invert a linear map.
linv :: (u :-: v) -> v :-: u

-- | Apply a linear map to a vector.
lapp :: (u :-: v) -> u -> v

-- | 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).
data Transformation (v :: Type -> Type) n
Transformation :: (v n :-: v n) -> (v n :-: v n) -> v n -> Transformation (v :: Type -> Type) n

-- | Invert a transformation.
inv :: forall (v :: Type -> Type) n. (Functor v, Num n) => Transformation v n -> Transformation v n

-- | Get the transpose of a transformation (ignoring the translation
--   component).
transp :: Transformation v n -> v n :-: v n

-- | Get the translational component of a transformation.
transl :: Transformation v n -> v n

-- | Drop the translational component of a transformation, leaving only the
--   linear part.
dropTransl :: forall (v :: Type -> Type) n. (Additive v, Num n) => Transformation v n -> Transformation 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.
apply :: Transformation v n -> v n -> v n

-- | Apply a transformation to a point.
papply :: forall (v :: Type -> Type) n. (Additive v, Num n) => Transformation v n -> Point v n -> Point v n

-- | Create a general affine transformation from an invertible linear
--   transformation and its transpose. The translational component is
--   assumed to be zero.
fromLinear :: (Additive v, Num n) => (v n :-: v n) -> (v n :-: v n) -> Transformation v n

-- | An orthogonal linear map is one whose inverse is also its transpose.
fromOrthogonal :: (Additive v, Num n) => (v n :-: v n) -> Transformation v n

-- | A symmetric linear map is one whose transpose is equal to its self.
fromSymmetric :: (Additive v, Num n) => (v n :-: v n) -> Transformation v n

-- | Produce a default basis for a vector space. If the dimensionality of
--   the vector space is not statically known, see basisFor.
basis :: (Additive t, Traversable t, Num a) => [t a]

-- | Get the dimension of an object whose vector space is an instance of
--   HasLinearMap, e.g. transformations, paths, diagrams, etc.
dimension :: (Additive (V a), Traversable (V a)) => a -> Int

-- | Get the matrix equivalent of the linear transform, (as a list of
--   columns) and the translation vector. This is mostly useful for
--   implementing backends.
onBasis :: (Additive v, Traversable v, Num n) => Transformation v n -> ([v n], v n)

-- | Convert a vector v to a list of scalars.
listRep :: Foldable v => v n -> [n]

-- | Convert the linear part of a Transformation to a matrix
--   representation as a list of column vectors which are also lists.
matrixRep :: forall (v :: Type -> Type) n. (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.
matrixHomRep :: forall (v :: Type -> Type) n. (Additive v, Traversable v, Num n) => Transformation v n -> [[n]]

-- | The determinant of (the linear part of) a Transformation.
determinant :: forall (v :: Type -> Type) n. (Additive v, Traversable v, Num n) => Transformation v n -> n

-- | Determine whether a Transformation includes a reflection
--   component, that is, whether it reverses orientation.
isReflection :: forall (v :: Type -> Type) n. (Additive v, Traversable v, Num n, Ord n) => Transformation v n -> Bool

-- | Compute the "average" amount of scaling performed by a transformation.
--   Satisfies the properties
--   
--   
--   avgScale (scaling k) == k
--   avgScale (t1 <> t2)  == avgScale t1 * avgScale t2
--   
--   
avgScale :: forall (v :: Type -> Type) n. (Additive v, Traversable v, Floating n) => Transformation v n -> n

-- | Identity matrix.
eye :: (HasBasis v, Num n) => v (v n)

-- | HasLinearMap is a constraint synonym, just to help shorten some
--   of the ridiculously long constraint sets.
type HasLinearMap (v :: Type -> Type) = (HasBasis v, Traversable v)

-- | An Additive vector space whose representation is made up of
--   basis elements.
type HasBasis (v :: Type -> Type) = (Additive v, Representable v, Rep v ~ E v)

-- | Type class for things t which can be transformed.
class Transformable t

-- | Apply a transformation to an object.
transform :: Transformable t => Transformation (V t) (N t) -> t -> 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.
newtype TransInv t
TransInv :: t -> TransInv t

-- | Create a translation.
translation :: v n -> Transformation v n

-- | Translate by a vector.
translate :: Transformable t => Vn t -> t -> t

-- | Create a uniform scaling transformation.
scaling :: forall (v :: Type -> Type) n. (Additive v, Fractional n) => n -> Transformation v n

-- | Scale uniformly in every dimension by the given scalar.
scale :: forall (v :: Type -> Type) n a. (InSpace v n a, Eq n, Fractional n, Transformable a) => n -> a -> a
instance (Diagrams.Core.Transform.Transformable a, Diagrams.Core.V.V a GHC.Types.~ v, Diagrams.Core.V.N a GHC.Types.~ n) => Data.Monoid.Action.Action (Diagrams.Core.Transform.Transformation v n) a
instance GHC.Classes.Eq t => GHC.Classes.Eq (Diagrams.Core.Transform.TransInv t)
instance Diagrams.Core.HasOrigin.HasOrigin (Diagrams.Core.Transform.TransInv t)
instance (Linear.Vector.Additive v, GHC.Internal.Num.Num n) => Diagrams.Core.HasOrigin.HasOrigin (Diagrams.Core.Transform.Transformation v n)
instance GHC.Internal.Base.Monoid (v Diagrams.Core.Transform.:-: v)
instance GHC.Internal.Base.Monoid t => GHC.Internal.Base.Monoid (Diagrams.Core.Transform.TransInv t)
instance (Linear.Vector.Additive v, GHC.Internal.Num.Num n) => GHC.Internal.Base.Monoid (Diagrams.Core.Transform.Transformation v n)
instance GHC.Classes.Ord t => GHC.Classes.Ord (Diagrams.Core.Transform.TransInv t)
instance Control.Lens.Wrapped.Rewrapped (Diagrams.Core.Transform.TransInv t) (Diagrams.Core.Transform.TransInv t')
instance GHC.Internal.Base.Semigroup (a Diagrams.Core.Transform.:-: a)
instance GHC.Internal.Base.Semigroup t => GHC.Internal.Base.Semigroup (Diagrams.Core.Transform.TransInv t)
instance (Linear.Vector.Additive v, GHC.Internal.Num.Num n) => GHC.Internal.Base.Semigroup (Diagrams.Core.Transform.Transformation v n)
instance GHC.Internal.Show.Show t => GHC.Internal.Show.Show (Diagrams.Core.Transform.TransInv t)
instance Diagrams.Core.Transform.Transformable m => Diagrams.Core.Transform.Transformable (Data.Monoid.Deletable.Deletable m)
instance (Diagrams.Core.V.V t GHC.Types.~ v, Diagrams.Core.V.N t GHC.Types.~ n, Diagrams.Core.V.V t GHC.Types.~ Diagrams.Core.V.V s, Diagrams.Core.V.N t GHC.Types.~ Diagrams.Core.V.N s, GHC.Internal.Base.Functor v, GHC.Internal.Num.Num n, Diagrams.Core.Transform.Transformable t, Diagrams.Core.Transform.Transformable s) => Diagrams.Core.Transform.Transformable (s -> t)
instance Diagrams.Core.Transform.Transformable t => Diagrams.Core.Transform.Transformable [t]
instance Diagrams.Core.Transform.Transformable t => Diagrams.Core.Transform.Transformable (Data.Map.Internal.Map k t)
instance (Diagrams.Core.V.InSpace v n t, Diagrams.Core.Transform.Transformable t, Diagrams.Core.Transform.HasLinearMap v, GHC.Internal.Float.Floating n) => Diagrams.Core.Transform.Transformable (Diagrams.Core.Measure.Measured n t)
instance (Linear.Vector.Additive v, GHC.Internal.Num.Num n) => Diagrams.Core.Transform.Transformable (Linear.Affine.Point v n)
instance (Diagrams.Core.Transform.Transformable t, GHC.Classes.Ord t) => Diagrams.Core.Transform.Transformable (Data.Set.Internal.Set t)
instance (GHC.Internal.Num.Num (Diagrams.Core.V.N t), Linear.Vector.Additive (Diagrams.Core.V.V t), Diagrams.Core.Transform.Transformable t) => Diagrams.Core.Transform.Transformable (Diagrams.Core.Transform.TransInv t)
instance (Linear.Vector.Additive v, GHC.Internal.Num.Num n) => Diagrams.Core.Transform.Transformable (Diagrams.Core.Transform.Transformation v n)
instance (Diagrams.Core.Transform.Transformable t, Diagrams.Core.Transform.Transformable s, Diagrams.Core.V.V t GHC.Types.~ Diagrams.Core.V.V s, Diagrams.Core.V.N t GHC.Types.~ Diagrams.Core.V.N s) => Diagrams.Core.Transform.Transformable (t, s)
instance (Diagrams.Core.Transform.Transformable t, Diagrams.Core.Transform.Transformable s, Diagrams.Core.Transform.Transformable u, Diagrams.Core.V.V s GHC.Types.~ Diagrams.Core.V.V t, Diagrams.Core.V.N s GHC.Types.~ Diagrams.Core.V.N t, Diagrams.Core.V.V s GHC.Types.~ Diagrams.Core.V.V u, Diagrams.Core.V.N s GHC.Types.~ Diagrams.Core.V.N u) => Diagrams.Core.Transform.Transformable (t, s, u)
instance Control.Lens.Wrapped.Wrapped (Diagrams.Core.Transform.TransInv t)

-- | A definition of styles for diagrams as extensible,
--   heterogeneous collections of attributes.
module Diagrams.Core.Style

-- | Every attribute must be an instance of AttributeClass, which
--   simply guarantees Typeable and Semigroup constraints.
--   The Semigroup instance for an attribute determines how it will
--   combine with other attributes of the same type.
class (Typeable a, Semigroup a) => AttributeClass a

-- | 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.
data Attribute (v :: Type -> Type) n
[Attribute] :: forall a (v :: Type -> Type) n. AttributeClass a => a -> Attribute v n
[MAttribute] :: forall a n (v :: Type -> Type). AttributeClass a => Measured n a -> Attribute v n
[TAttribute] :: forall a (v :: Type -> Type) n. (AttributeClass a, Transformable a, V a ~ v, N a ~ n) => a -> Attribute v n

-- | Prism onto an Attribute.
_Attribute :: forall a (v :: Type -> Type) n. AttributeClass a => Prism' (Attribute v n) a

-- | Prism onto an MAttribute.
_MAttribute :: forall a n (v :: Type -> Type). (AttributeClass a, Typeable n) => Prism' (Attribute v n) (Measured n a)

-- | Prism onto a TAttribute.
_TAttribute :: forall a (v :: Type -> Type) n. (V a ~ v, N a ~ n, AttributeClass a, Transformable a) => Prism' (Attribute v n) a

-- | Unwrap an unknown Attribute type, performing a dynamic (but
--   safe) check on the type of the result. If the required type matches
--   the type of the attribute, the attribute value is returned wrapped in
--   Just; if the types do not match, Nothing is
--   returned.
--   
--   Measured attributes cannot be extrated from this function until they
--   have been unmeasured with unmeasureAttribute. If you want a
--   measured attibute use the _MAttribute prism.
unwrapAttribute :: forall a (v :: Type -> Type) n. AttributeClass a => Attribute v n -> Maybe a

-- | Turn an MAttribute into an Attribute using the given
--   global and normalized scale.
unmeasureAttribute :: forall n (v :: Type -> Type). Num n => n -> n -> Attribute v n -> Attribute v n

-- | Type of an attribute that is stored with a style. Measured attributes
--   return the type as if it where unmeasured.
attributeType :: forall (v :: Type -> Type) n. Attribute v n -> TypeRep

-- | A Style is a heterogeneous collection of attributes,
--   containing at most one attribute of any given type.
newtype Style (v :: Type -> Type) n
Style :: HashMap TypeRep (Attribute v n) -> Style (v :: Type -> Type) n

-- | Turn an attribute into a style. An easier way to make a style is to
--   use the monoid instance and apply library functions for applying that
--   attribute:
--   
--   
--   myStyle = mempty # fc blue :: Style V2 Double
--   
attributeToStyle :: forall (v :: Type -> Type) n. Attribute v n -> Style v n

-- | 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.
getAttr :: forall a (v :: Type -> Type) n. AttributeClass a => Style v n -> Maybe a

-- | Replace all MAttributes with Attributes using the
--   global and normalized scales.
unmeasureAttrs :: forall n (v :: Type -> Type). Num n => n -> n -> Style v n -> Style v n

-- | Lens onto a plain attribute of a style.
atAttr :: forall a (v :: Type -> Type) n. AttributeClass a => Lens' (Style v n) (Maybe a)

-- | Lens onto a measured attribute of a style.
atMAttr :: forall a n (v :: Type -> Type). (AttributeClass a, Typeable n) => Lens' (Style v n) (Maybe (Measured n a))

-- | Lens onto a transformable attribute of a style.
atTAttr :: forall a (v :: Type -> Type) n. (V a ~ v, N a ~ n, AttributeClass a, Transformable a) => Lens' (Style v n) (Maybe a)

-- | 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.
applyAttr :: (AttributeClass a, HasStyle d) => 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.
applyMAttr :: (AttributeClass a, N d ~ n, HasStyle d) => Measured n 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.
applyTAttr :: (AttributeClass a, Transformable a, V a ~ V d, N a ~ N d, HasStyle d) => a -> d -> d

-- | Type class for things which have a style.
class HasStyle a

-- | Apply a style by combining it (on the left) with the existing
--   style.
applyStyle :: HasStyle a => Style (V a) (N a) -> a -> a
instance Data.Monoid.Action.Action (Diagrams.Core.Style.Style v n) m
instance Control.Lens.At.At (Diagrams.Core.Style.Style v n)
instance Control.Lens.Each.Each (Diagrams.Core.Style.Style v n) (Diagrams.Core.Style.Style v' n') (Diagrams.Core.Style.Attribute v n) (Diagrams.Core.Style.Attribute v' n')
instance Diagrams.Core.Style.HasStyle b => Diagrams.Core.Style.HasStyle (a -> b)
instance Diagrams.Core.Style.HasStyle a => Diagrams.Core.Style.HasStyle [a]
instance Diagrams.Core.Style.HasStyle a => Diagrams.Core.Style.HasStyle (Data.Map.Internal.Map k a)
instance Diagrams.Core.Style.HasStyle b => Diagrams.Core.Style.HasStyle (Diagrams.Core.Measure.Measured n b)
instance (Diagrams.Core.Style.HasStyle a, GHC.Classes.Ord a) => Diagrams.Core.Style.HasStyle (Data.Set.Internal.Set a)
instance GHC.Internal.Data.Typeable.Internal.Typeable n => Diagrams.Core.Style.HasStyle (Diagrams.Core.Style.Style v n)
instance (Diagrams.Core.Style.HasStyle a, Diagrams.Core.Style.HasStyle b, Diagrams.Core.V.V a GHC.Types.~ Diagrams.Core.V.V b, Diagrams.Core.V.N a GHC.Types.~ Diagrams.Core.V.N b) => Diagrams.Core.Style.HasStyle (a, b)
instance Control.Lens.At.Ixed (Diagrams.Core.Style.Style v n)
instance GHC.Internal.Data.Typeable.Internal.Typeable n => GHC.Internal.Base.Monoid (Diagrams.Core.Style.Style v n)
instance Control.Lens.Wrapped.Rewrapped (Diagrams.Core.Style.Style v n) (Diagrams.Core.Style.Style v' n')
instance GHC.Internal.Data.Typeable.Internal.Typeable n => GHC.Internal.Base.Semigroup (Diagrams.Core.Style.Attribute v n)
instance GHC.Internal.Data.Typeable.Internal.Typeable n => GHC.Internal.Base.Semigroup (Diagrams.Core.Style.Style v n)
instance GHC.Internal.Show.Show (Diagrams.Core.Style.Attribute v n)
instance GHC.Internal.Show.Show (Diagrams.Core.Style.Style v n)
instance (Linear.Vector.Additive v, GHC.Internal.Data.Traversable.Traversable v, GHC.Internal.Float.Floating n) => Diagrams.Core.Transform.Transformable (Diagrams.Core.Style.Attribute v n)
instance (Linear.Vector.Additive v, GHC.Internal.Data.Traversable.Traversable v, GHC.Internal.Float.Floating n) => Diagrams.Core.Transform.Transformable (Diagrams.Core.Style.Style v n)
instance Control.Lens.Wrapped.Wrapped (Diagrams.Core.Style.Style v n)

-- | This module defines a type of names which can be used for referring to
--   subdiagrams, and related types.
module Diagrams.Core.Names

-- | Atomic names. AName is just an existential wrapper around
--   things which are Typeable, Ord and Show.
data AName
[AName] :: forall a. (Typeable a, Ord a, Show a) => a -> AName

-- | Prism onto AName.
_AName :: (Typeable a, Ord a, Show a) => Prism' AName a

-- | A (qualified) name is a (possibly empty) sequence of atomic names.
newtype Name
Name :: [AName] -> Name

-- | 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 (Typeable a, Ord a, Show a) => IsName a
toName :: IsName a => a -> Name

-- | 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.
(.>) :: (IsName a1, IsName a2) => a1 -> a2 -> Name
infixr 5 .>

-- | Traversal over each name in a Name that matches the target
--   type.
--   
--   
--   >>> toListOf eachName (a .> False .> b) :: String
--   "ab"
--   >>> a .> True .> b & eachName %~ not
--   a .> 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
--   
eachName :: (Typeable a, Ord a, Show a) => Traversal' Name a

-- | Instances of Qualifiable are things which can be qualified by
--   prefixing them with a name.
class Qualifiable q

-- | Qualify with the given name.
(.>>) :: (Qualifiable q, IsName a) => a -> q -> q
infixr 5 .>>
instance Control.Lens.Each.Each Diagrams.Core.Names.Name Diagrams.Core.Names.Name Diagrams.Core.Names.AName Diagrams.Core.Names.AName
instance GHC.Classes.Eq Diagrams.Core.Names.AName
instance GHC.Classes.Eq Diagrams.Core.Names.Name
instance Diagrams.Core.Names.IsName Diagrams.Core.Names.AName
instance Diagrams.Core.Names.IsName GHC.Types.Bool
instance Diagrams.Core.Names.IsName GHC.Types.Char
instance Diagrams.Core.Names.IsName GHC.Types.Double
instance Diagrams.Core.Names.IsName GHC.Types.Float
instance Diagrams.Core.Names.IsName GHC.Types.Int
instance Diagrams.Core.Names.IsName GHC.Num.Integer.Integer
instance Diagrams.Core.Names.IsName a => Diagrams.Core.Names.IsName [a]
instance Diagrams.Core.Names.IsName a => Diagrams.Core.Names.IsName (GHC.Internal.Maybe.Maybe a)
instance Diagrams.Core.Names.IsName Diagrams.Core.Names.Name
instance (Diagrams.Core.Names.IsName a, Diagrams.Core.Names.IsName b) => Diagrams.Core.Names.IsName (a, b)
instance (Diagrams.Core.Names.IsName a, Diagrams.Core.Names.IsName b, Diagrams.Core.Names.IsName c) => Diagrams.Core.Names.IsName (a, b, c)
instance Diagrams.Core.Names.IsName ()
instance GHC.Internal.Base.Monoid Diagrams.Core.Names.Name
instance GHC.Classes.Ord Diagrams.Core.Names.AName
instance GHC.Classes.Ord Diagrams.Core.Names.Name
instance Diagrams.Core.Names.Qualifiable a => Diagrams.Core.Names.Qualifiable (b -> a)
instance Diagrams.Core.Names.Qualifiable a => Diagrams.Core.Names.Qualifiable [a]
instance Diagrams.Core.Names.Qualifiable a => Diagrams.Core.Names.Qualifiable (Data.Map.Internal.Map k a)
instance Diagrams.Core.Names.Qualifiable a => Diagrams.Core.Names.Qualifiable (Diagrams.Core.Measure.Measured n a)
instance Diagrams.Core.Names.Qualifiable Diagrams.Core.Names.Name
instance (GHC.Classes.Ord a, Diagrams.Core.Names.Qualifiable a) => Diagrams.Core.Names.Qualifiable (Data.Set.Internal.Set a)
instance Diagrams.Core.Names.Qualifiable a => Diagrams.Core.Names.Qualifiable (Diagrams.Core.Transform.TransInv a)
instance (Diagrams.Core.Names.Qualifiable a, Diagrams.Core.Names.Qualifiable b) => Diagrams.Core.Names.Qualifiable (a, b)
instance (Diagrams.Core.Names.Qualifiable a, Diagrams.Core.Names.Qualifiable b, Diagrams.Core.Names.Qualifiable c) => Diagrams.Core.Names.Qualifiable (a, b, c)
instance Control.Lens.Wrapped.Rewrapped Diagrams.Core.Names.Name Diagrams.Core.Names.Name
instance GHC.Internal.Base.Semigroup Diagrams.Core.Names.Name
instance GHC.Internal.Show.Show Diagrams.Core.Names.AName
instance GHC.Internal.Show.Show Diagrams.Core.Names.Name
instance Control.Lens.Wrapped.Wrapped Diagrams.Core.Names.Name

-- | diagrams-core defines the core library of primitives forming
--   the basis of an embedded domain-specific language for describing and
--   rendering diagrams.
--   
--   The Trace module defines a data type and type class for
--   "traces", aka functional boundaries, essentially corresponding to
--   embedding a raytracer with each diagram.
module Diagrams.Core.Trace

-- | 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.
data SortedList a

-- | A smart constructor for the SortedList type, which sorts the
--   input to ensure the SortedList invariant.
mkSortedList :: Ord a => [a] -> SortedList a

-- | Project the (guaranteed sorted) list out of a SortedList
--   wrapper.
getSortedList :: SortedList a -> [a]

-- | Apply a list function to a SortedList. The function need not
--   result in a sorted list; the result will be sorted before being
--   rewrapped as a SortedList.
onSortedList :: Ord b => ([a] -> [b]) -> SortedList a -> SortedList b

-- | Apply an order-preserving list function to a SortedList.
--   No sorts or checks are done.
unsafeOnSortedList :: ([a] -> [b]) -> SortedList a -> SortedList b

-- | 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).
--   
newtype Trace (v :: Type -> Type) n
Trace :: (Point v n -> v n -> SortedList n) -> Trace (v :: Type -> Type) n
appTrace :: Trace v n -> Point v n -> v n -> SortedList n
mkTrace :: (Point v n -> v n -> SortedList n) -> Trace v n

-- | Traced abstracts over things which have a trace.
class (Additive V a, Ord N a) => Traced a

-- | Compute the trace of an object.
getTrace :: Traced a => a -> Trace (V a) (N a)

-- | 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.
--   
traceV :: (n ~ N a, Num n, Traced a) => Point (V a) n -> V a n -> a -> Maybe (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.
--   
traceP :: (n ~ N a, Traced a, Num n) => Point (V a) n -> V a n -> a -> Maybe (Point (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.)
--   
maxTraceV :: (n ~ N a, Num n, Traced a) => Point (V a) n -> V a n -> a -> Maybe (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.)
--   
maxTraceP :: (n ~ N a, Num n, Traced a) => Point (V a) n -> V a n -> a -> Maybe (Point (V a) n)

-- | Get a modified Trace for an object which only returns positive
--   boundary points, i.e. those boundary points given by a positive
--   scalar multiple of the direction vector. Note, this property will be
--   destroyed if the resulting Trace is translated at all.
getRayTrace :: (n ~ N a, Traced a, Num n) => a -> Trace (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.
--   
rayTraceV :: (n ~ N a, Traced a, Num n) => Point (V a) n -> V a n -> a -> Maybe (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.
--   
rayTraceP :: (n ~ N a, Traced a, Num n) => Point (V a) n -> V a n -> a -> Maybe (Point (V a) n)

-- | Like rayTraceV, but computes a vector to the "largest" boundary
--   point instead of the smallest. Considers only positive boundary
--   points.
--   
maxRayTraceV :: (n ~ N a, Traced a, Num n) => Point (V a) n -> V a n -> a -> Maybe (V a n)

-- | Like rayTraceP, but computes 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)
instance (Linear.Vector.Additive v, GHC.Internal.Num.Num n) => Diagrams.Core.HasOrigin.HasOrigin (Diagrams.Core.Trace.Trace v n)
instance GHC.Classes.Ord a => GHC.Internal.Base.Monoid (Diagrams.Core.Trace.SortedList a)
instance GHC.Classes.Ord n => GHC.Internal.Base.Monoid (Diagrams.Core.Trace.Trace v n)
instance Control.Lens.Wrapped.Rewrapped (Diagrams.Core.Trace.Trace v n) (Diagrams.Core.Trace.Trace v' n')
instance GHC.Classes.Ord a => GHC.Internal.Base.Semigroup (Diagrams.Core.Trace.SortedList a)
instance GHC.Classes.Ord n => GHC.Internal.Base.Semigroup (Diagrams.Core.Trace.Trace v n)
instance GHC.Internal.Show.Show (Diagrams.Core.Trace.Trace v n)
instance Diagrams.Core.Trace.Traced b => Diagrams.Core.Trace.Traced [b]
instance Diagrams.Core.Trace.Traced b => Diagrams.Core.Trace.Traced (Data.Map.Internal.Map k b)
instance (Linear.Vector.Additive v, GHC.Classes.Ord n) => Diagrams.Core.Trace.Traced (Linear.Affine.Point v n)
instance Diagrams.Core.Trace.Traced b => Diagrams.Core.Trace.Traced (Data.Set.Internal.Set b)
instance (Linear.Vector.Additive v, GHC.Classes.Ord n) => Diagrams.Core.Trace.Traced (Diagrams.Core.Trace.Trace v n)
instance Diagrams.Core.Trace.Traced t => Diagrams.Core.Trace.Traced (Diagrams.Core.Transform.TransInv t)
instance (Diagrams.Core.Trace.Traced a, Diagrams.Core.Trace.Traced b, Diagrams.Core.V.SameSpace a b) => Diagrams.Core.Trace.Traced (a, b)
instance (Linear.Vector.Additive v, GHC.Internal.Num.Num n) => Diagrams.Core.Transform.Transformable (Diagrams.Core.Trace.Trace v n)
instance Control.Lens.Wrapped.Wrapped (Diagrams.Core.Trace.Trace v n)

-- | The Query module defines a type for "queries" on diagrams,
--   which are functions from points in a vector space to some monoid.
module Diagrams.Core.Query

-- | 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.
newtype Query (v :: Type -> Type) n m
Query :: (Point v n -> m) -> Query (v :: Type -> Type) n m
[runQuery] :: Query (v :: Type -> Type) n m -> Point v n -> m
instance GHC.Internal.Base.Applicative (Diagrams.Core.Query.Query v n)
instance GHC.Internal.Base.Functor v => Data.Profunctor.Closed.Closed (Diagrams.Core.Query.Query v)
instance GHC.Internal.Base.Functor v => Data.Profunctor.Rep.Corepresentable (Diagrams.Core.Query.Query v)
instance GHC.Internal.Base.Functor v => Data.Profunctor.Sieve.Cosieve (Diagrams.Core.Query.Query v) (Linear.Affine.Point v)
instance GHC.Internal.Base.Functor v => Data.Profunctor.Strong.Costrong (Diagrams.Core.Query.Query v)
instance Data.Distributive.Distributive (Diagrams.Core.Query.Query v n)
instance GHC.Internal.Base.Functor (Diagrams.Core.Query.Query v n)
instance (Linear.Vector.Additive v, GHC.Internal.Num.Num n) => Diagrams.Core.HasOrigin.HasOrigin (Diagrams.Core.Query.Query v n m)
instance GHC.Internal.Base.Monad (Diagrams.Core.Query.Query v n)
instance GHC.Internal.Base.Monoid m => GHC.Internal.Base.Monoid (Diagrams.Core.Query.Query v n m)
instance GHC.Internal.Base.Functor v => Data.Profunctor.Unsafe.Profunctor (Diagrams.Core.Query.Query v)
instance Data.Functor.Rep.Representable (Diagrams.Core.Query.Query v n)
instance Control.Lens.Wrapped.Rewrapped (Diagrams.Core.Query.Query v a m) (Diagrams.Core.Query.Query v' a' m')
instance GHC.Internal.Base.Semigroup m => GHC.Internal.Base.Semigroup (Diagrams.Core.Query.Query v n m)
instance (Linear.Vector.Additive v, GHC.Internal.Num.Num n) => Diagrams.Core.Transform.Transformable (Diagrams.Core.Query.Query v n m)
instance Control.Lens.Wrapped.Wrapped (Diagrams.Core.Query.Query v n m)

-- | diagrams-core defines the core library of primitives forming the basis
--   of an embedded domain-specific language for describing and rendering
--   diagrams.
--   
--   The Diagrams.Core.Envelope module defines a data type and
--   type class for "envelopes", aka functional bounding regions.
module Diagrams.Core.Envelope

-- | 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) onto v is s' *^ v, then
--   s' <= 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.
newtype Envelope (v :: Type -> Type) n
Envelope :: Maybe (v n -> Max n) -> Envelope (v :: Type -> Type) n

-- | "Apply" an envelope by turning it into a function. Nothing is
--   returned iff the envelope is empty.
appEnvelope :: Envelope v n -> Maybe (v n -> n)

-- | A convenient way to transform an envelope, by specifying a
--   transformation on the underlying v n -> n function. The
--   empty envelope is unaffected.
onEnvelope :: ((v n -> n) -> v n -> n) -> Envelope v n -> Envelope v n

-- | Create an envelope from a v n -> n function.
mkEnvelope :: (v n -> n) -> Envelope v n

-- | Create a point envelope for the given point. A point envelope has
--   distance zero to a bounding hyperplane in every direction. Note this
--   is not the same as the empty envelope.
pointEnvelope :: forall n (v :: Type -> Type). (Fractional n, Metric v) => Point v n -> Envelope v n

-- | Enveloped abstracts over things which have an envelope.
class (Metric V a, OrderedField N a) => Enveloped 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.
getEnvelope :: Enveloped a => a -> Envelope (V a) (N a)

-- | Compute the diameter of a enveloped object along a particular vector.
--   Returns zero for the empty envelope.
diameter :: (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.
radius :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> n

-- | Compute the range of an enveloped object along a certain direction.
--   Returns a pair of scalars (lo,hi) such that the object
--   extends from (lo *^ v) to (hi *^ v). Returns
--   Nothing for objects with an empty envelope.
extent :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> Maybe (n, n)

-- | The smallest positive axis-parallel vector that bounds the
--   envelope of an object.
size :: (V a ~ v, N a ~ n, Enveloped a, HasBasis v) => a -> v n

-- | Compute the vector from the local origin to a separating hyperplane in
--   the given direction, or Nothing for the empty envelope.
envelopeVMay :: Enveloped a => Vn a -> a -> Maybe (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.
envelopeV :: Enveloped a => Vn a -> a -> Vn a

-- | Compute the point on a separating hyperplane in the given direction,
--   or Nothing 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.
--   Returns the origin for the empty envelope.
envelopeP :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> Point v n

-- | Equivalent to the norm of envelopeVMay:
--   
--   
--   envelopeSMay v x == fmap norm (envelopeVMay v x)
--   
--   
--   (other than differences in rounding error)
--   
--   Note that the envelopeVMay / envelopePMay functions
--   above should be preferred, as this requires a call to norm. However,
--   it is more efficient than calling norm on the results of those
--   functions.
envelopeSMay :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> Maybe n

-- | Equivalent to the norm of envelopeV:
--   
--   
--   envelopeS v x == norm (envelopeV v x)
--   
--   
--   (other than differences in rounding error)
--   
--   Note that the envelopeV / envelopeP functions above
--   should be preferred, as this requires a call to norm. However, it is
--   more efficient than calling norm on the results of those functions.
envelopeS :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> n

-- | 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 constraint as a convenient shorthand.
type OrderedField s = (Floating s, Ord s)
instance (Linear.Metric.Metric v, Diagrams.Core.Envelope.OrderedField n) => Diagrams.Core.Envelope.Enveloped (Diagrams.Core.Envelope.Envelope v n)
instance Diagrams.Core.Envelope.Enveloped b => Diagrams.Core.Envelope.Enveloped [b]
instance Diagrams.Core.Envelope.Enveloped b => Diagrams.Core.Envelope.Enveloped (Data.Map.Internal.Map k b)
instance (Diagrams.Core.Envelope.OrderedField n, Linear.Metric.Metric v) => Diagrams.Core.Envelope.Enveloped (Linear.Affine.Point v n)
instance Diagrams.Core.Envelope.Enveloped b => Diagrams.Core.Envelope.Enveloped (Data.Set.Internal.Set b)
instance Diagrams.Core.Envelope.Enveloped t => Diagrams.Core.Envelope.Enveloped (Diagrams.Core.Transform.TransInv t)
instance (Diagrams.Core.Envelope.Enveloped a, Diagrams.Core.Envelope.Enveloped b, Diagrams.Core.V.V a GHC.Types.~ Diagrams.Core.V.V b, Diagrams.Core.V.N a GHC.Types.~ Diagrams.Core.V.N b) => Diagrams.Core.Envelope.Enveloped (a, b)
instance (Linear.Metric.Metric v, GHC.Internal.Real.Fractional n) => Diagrams.Core.HasOrigin.HasOrigin (Diagrams.Core.Envelope.Envelope v n)
instance GHC.Classes.Ord n => GHC.Internal.Base.Monoid (Diagrams.Core.Envelope.Envelope v n)
instance Control.Lens.Wrapped.Rewrapped (Diagrams.Core.Envelope.Envelope v n) (Diagrams.Core.Envelope.Envelope v' n')
instance GHC.Classes.Ord n => GHC.Internal.Base.Semigroup (Diagrams.Core.Envelope.Envelope v n)
instance GHC.Internal.Show.Show (Diagrams.Core.Envelope.Envelope v n)
instance (Linear.Metric.Metric v, GHC.Internal.Float.Floating n) => Diagrams.Core.Transform.Transformable (Diagrams.Core.Envelope.Envelope v n)
instance Control.Lens.Wrapped.Wrapped (Diagrams.Core.Envelope.Envelope v n)

-- | Things which can be placed "next to" other things, for some
--   appropriate notion of "next to".
module Diagrams.Core.Juxtapose

-- | Class of things which can be placed "next to" other things, for some
--   appropriate notion of "next to".
class Juxtaposable 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.)
juxtapose :: Juxtaposable a => Vn a -> a -> a -> a

-- | Default implementation of juxtapose for things which are
--   instances of Enveloped and HasOrigin. If either envelope
--   is empty, the second object is returned unchanged.
juxtaposeDefault :: (Enveloped a, HasOrigin a) => Vn a -> a -> a -> a
instance (Linear.Metric.Metric v, Diagrams.Core.Envelope.OrderedField n) => Diagrams.Core.Juxtapose.Juxtaposable (Diagrams.Core.Envelope.Envelope v n)
instance Diagrams.Core.Juxtapose.Juxtaposable a => Diagrams.Core.Juxtapose.Juxtaposable (b -> a)
instance (Diagrams.Core.Envelope.Enveloped b, Diagrams.Core.HasOrigin.HasOrigin b) => Diagrams.Core.Juxtapose.Juxtaposable [b]
instance (Diagrams.Core.Envelope.Enveloped b, Diagrams.Core.HasOrigin.HasOrigin b) => Diagrams.Core.Juxtapose.Juxtaposable (Data.Map.Internal.Map k b)
instance Diagrams.Core.Juxtapose.Juxtaposable a => Diagrams.Core.Juxtapose.Juxtaposable (Diagrams.Core.Measure.Measured n a)
instance (Diagrams.Core.Envelope.Enveloped b, Diagrams.Core.HasOrigin.HasOrigin b, GHC.Classes.Ord b) => Diagrams.Core.Juxtapose.Juxtaposable (Data.Set.Internal.Set b)
instance (Diagrams.Core.Envelope.Enveloped a, Diagrams.Core.HasOrigin.HasOrigin a, Diagrams.Core.Envelope.Enveloped b, Diagrams.Core.HasOrigin.HasOrigin b, Diagrams.Core.V.V a GHC.Types.~ Diagrams.Core.V.V b, Diagrams.Core.V.N a GHC.Types.~ Diagrams.Core.V.N b) => Diagrams.Core.Juxtapose.Juxtaposable (a, b)

-- | The core library of primitives forming the basis of an embedded
--   domain-specific language for describing and rendering diagrams.
--   
--   Diagrams.Core.Types defines types and classes for primitives,
--   diagrams, and backends.
module Diagrams.Core.Types

-- | Static annotations which can be placed at a particular node of a
--   diagram tree.
data Annotation

-- | Hyperlink
Href :: String -> Annotation
OpacityGroup :: Double -> Annotation
KeyVal :: (String, String) -> Annotation

-- | Apply a static annotation at the root of a diagram.
applyAnnotation :: forall (v :: Type -> Type) n m b. (Metric v, OrderedField n, Semigroup m) => Annotation -> 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.
href :: forall (v :: Type -> Type) n m b. (Metric v, OrderedField n, Semigroup m) => String -> QDiagram b v n m -> QDiagram b v n m

-- | Change the transparency of a Diagram as a group.
opacityGroup :: forall (v :: Type -> Type) n m b. (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 :: forall (v :: Type -> Type) n m b. (Metric v, OrderedField n, Semigroup m) => Double -> QDiagram b v n m -> QDiagram b v n m

-- | Apply a general Key-Value annotation
keyVal :: forall (v :: Type -> Type) n m b. (Metric v, OrderedField n, Semigroup m) => (String, String) -> QDiagram b v n m -> QDiagram b v n m

-- | Monoidal annotations which travel up the diagram tree, i.e.
--   which are aggregated from component diagrams to the whole:
--   
--   
--   
- envelopes (see Diagrams.Core.Envelope). The envelopes are
--   "deletable" meaning that at any point we can throw away the existing
--   envelope and replace it with a new one; sometimes we want to consider
--   a diagram as having a different envelope unrelated to its "natural"
--   envelope.
--   
- traces (see Diagrams.Core.Trace), also deletable.
--   
- name/subdiagram associations (see Diagrams.Core.Names)
--   
- query functions (see Diagrams.Core.Query)
--   
type UpAnnots b (v :: Type -> Type) n m = Deletable Envelope v n ::: Deletable Trace v n ::: Deletable SubMap b v n m ::: Query v n m ::: ()

-- | Monoidal annotations which travel down the diagram tree, i.e.
--   which accumulate along each path to a leaf (and which can act on the
--   upwards-travelling annotations):
--   
--   
--   
- styles (see Diagrams.Core.Style)
--   
- names (see Diagrams.Core.Names)
--   
type DownAnnots (v :: Type -> Type) n = Transformation v n :+: Style v n ::: Name ::: ()

-- | Inject a transformation into a default downwards annotation value.
transfToAnnot :: forall (v :: Type -> Type) n. Transformation v n -> DownAnnots v n

-- | Extract the (total) transformation from a downwards annotation value.
transfFromAnnot :: forall (v :: Type -> Type) n. (Additive v, Num n) => DownAnnots v n -> Transformation v n

-- | A leaf in a QDiagram tree is either a Prim, or a
--   "delayed" QDiagram which expands to a real QDiagram
--   once it learns the "final context" in which it will be rendered. For
--   example, in order to decide how to draw an arrow, we must know the
--   precise transformation applied to it (since the arrow head and tail
--   are scale-invariant).
data QDiaLeaf b (v :: Type -> Type) n m
PrimLeaf :: Prim b v n -> QDiaLeaf b (v :: Type -> Type) n m

-- | The QDiagram produced by a DelayedLeaf function
--   must already apply any transformation in the given
--   DownAnnots (that is, the transformation will not be applied
--   by the context).
DelayedLeaf :: (DownAnnots v n -> n -> n -> QDiagram b v n m) -> QDiaLeaf b (v :: Type -> Type) n m
withQDiaLeaf :: forall b (v :: Type -> Type) n r m. (Prim b v n -> r) -> ((DownAnnots v n -> n -> n -> QDiagram b v n m) -> r) -> QDiaLeaf b v n m -> r

-- | The fundamental diagram type. The type variables are as follows:
--   
--   
--   
- b represents the backend, such as SVG or
--   Cairo. Note that each backend also exports a type synonym
--   B for itself, so the type variable b may also
--   typically be instantiated by B, meaning "use whatever backend
--   is in scope".
--   
- v represents the vector space of the diagram. Typical
--   instantiations include V2 (for a two-dimensional diagram) or
--   V3 (for a three-dimensional diagram).
--   
- n represents the numerical field the diagram uses.
--   Typically this will be a concrete numeric type like
--   Double.
--   
- m is the monoidal type of "query annotations": each point
--   in the diagram has a value of type m associated to it, and
--   these values are combined according to the Monoid instance for
--   m. Most often, m is simply instantiated to
--   Any, associating a simple Bool value to each point
--   indicating whether the point is inside the diagram; Diagram is
--   a synonym for QDiagram with m thus instantiated to
--   Any.
--   
--   
--   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.
newtype QDiagram b (v :: Type -> Type) n m
QD :: DUALTree (DownAnnots v n) (UpAnnots b v n m) Annotation (QDiaLeaf b v n m) -> QDiagram b (v :: Type -> Type) n m

-- | Diagram b is a synonym for QDiagram b (V b) (N b)
--   Any. 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 Functor instance of
--   QDiagram b v n or the value function.
type Diagram b = QDiagram b V b N b Any

-- | Create a diagram from a single primitive, along with an envelope,
--   trace, subdiagram map, and query function.
mkQD :: forall b (v :: Type -> Type) n m. 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 generic QDiaLeaf, along with an envelope,
--   trace, subdiagram map, and query function.
mkQD' :: forall b (v :: Type -> Type) n m. QDiaLeaf b v n m -> Envelope v n -> Trace v n -> SubMap b v n m -> Query v n m -> QDiagram b v n m

-- | Create a "point diagram", which has no content, no trace, an empty
--   query, and a point envelope.
pointDiagram :: forall (v :: Type -> Type) n b m. (Metric v, Fractional n) => Point v n -> QDiagram b v n m

-- | Lens onto the Envelope of a QDiagram.
envelope :: forall n (v :: Type -> Type) m b. (OrderedField n, Metric v, Monoid' m) => Lens' (QDiagram b v n m) (Envelope v n)

-- | Lens onto the Trace of a QDiagram.
trace :: forall (v :: Type -> Type) n m b. (Metric v, OrderedField n, Semigroup m) => Lens' (QDiagram b v n m) (Trace v n)

-- | Lens onto the SubMap of a QDiagram (i.e. an
--   association from names to subdiagrams).
subMap :: forall (v :: Type -> Type) m n b. (Metric v, Semigroup m, OrderedField n) => Lens' (QDiagram b v n m) (SubMap b v n m)

-- | Get a list of names of subdiagrams and their locations.
names :: forall (v :: Type -> Type) m n b. (Metric v, Semigroup m, OrderedField n) => QDiagram b v n m -> [(Name, [Point v n])]

-- | Get the query function associated with a diagram.
query :: forall m b (v :: Type -> Type) n. Monoid m => QDiagram b v n m -> Query v n m

-- | 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).
atop :: forall n (v :: Type -> Type) m b. (OrderedField n, Metric v, Semigroup m) => QDiagram b v n m -> QDiagram b v n m -> QDiagram b v n m
infixl 6 `atop`

-- | 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).
nameSub :: forall nm (v :: Type -> Type) n m b. (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

-- | Lookup the most recent diagram associated with (some qualification of)
--   the given name.
lookupName :: forall nm (v :: Type -> Type) m n b. (IsName nm, Metric v, Semigroup m, OrderedField n) => nm -> QDiagram b v n m -> Maybe (Subdiagram 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.
withName :: forall nm (v :: Type -> Type) m n b. (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.
withNameAll :: forall nm (v :: Type -> Type) m n b. (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.
withNames :: forall nm (v :: Type -> Type) m n b. (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" a diagram by hiding all the names, so they are no longer
--   visible to the outside.
localize :: forall b (v :: Type -> Type) n m. (Metric v, OrderedField n, Semigroup m) => QDiagram b v n m -> QDiagram b v n m

-- | Replace the envelope of a diagram.
setEnvelope :: forall b (v :: Type -> Type) n m. (OrderedField n, Metric v, Monoid' m) => Envelope v n -> QDiagram b v n m -> QDiagram b v n m

-- | Replace the trace of a diagram.
setTrace :: forall b (v :: Type -> Type) n m. (OrderedField n, Metric v, Semigroup m) => Trace v n -> QDiagram b v n m -> QDiagram 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.).
data Subdiagram b (v :: Type -> Type) n m
Subdiagram :: QDiagram b v n m -> DownAnnots v n -> Subdiagram b (v :: Type -> Type) n m

-- | Turn a diagram into a subdiagram with no accumulated context.
mkSubdiagram :: forall b (v :: Type -> Type) n m. QDiagram b v n m -> Subdiagram 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.
getSub :: forall (v :: Type -> Type) n m b. (Metric v, OrderedField n, Semigroup m) => Subdiagram b v n m -> QDiagram b v n m

-- | Extract the "raw" content of a subdiagram, by throwing away the
--   context.
rawSub :: forall b (v :: Type -> Type) n m. Subdiagram b v n m -> QDiagram b v n m

-- | 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".
location :: forall (v :: Type -> Type) n b m. (Additive v, Num n) => Subdiagram b v n m -> Point v n

-- | 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.
subPoint :: forall (v :: Type -> Type) n b m. (Metric v, OrderedField n) => Point v n -> Subdiagram b v n m

-- | A SubMap is a map associating names to subdiagrams. There can
--   be multiple associations for any given name.
newtype SubMap b (v :: Type -> Type) n m
SubMap :: Map Name [Subdiagram b v n m] -> SubMap b (v :: Type -> Type) n m

-- | Construct a SubMap from a list of associations between names
--   and subdiagrams.
fromNames :: forall a b (v :: Type -> Type) n m. IsName a => [(a, Subdiagram b v n m)] -> SubMap b v n m

-- | Add a name/diagram association to a submap.
rememberAs :: forall a b (v :: Type -> Type) n m. IsName a => a -> QDiagram b v n m -> SubMap b v n m -> SubMap 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.
lookupSub :: forall nm b (v :: Type -> Type) n m. IsName nm => nm -> SubMap b v n m -> Maybe [Subdiagram b v n m]

-- | 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.
data Prim b (v :: Type -> Type) n
[Prim] :: forall p b. (Transformable p, Typeable p, Renderable p b) => p -> Prim b (V p) (N p)
_Prim :: (Typeable p, Renderable p b) => Prism' (Prim b (V p) (N p)) p

-- | 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.
class Backend b (v :: Type -> Type) n where {
    
    -- | An intermediate representation used for rendering primitives.
    --   (Typically, this will be some sort of monad, but it need not be.) The
    --   <a>Renderable</a> class guarantees that a backend will be able to
    --   convert primitives into this type; how these rendered primitives are
    --   combined into an ultimate <a>Result</a> is completely up to the
    --   backend.
    data Render b (v :: Type -> Type) n;
    
    -- | The result of running/interpreting a rendering operation.
    type Result b (v :: Type -> Type) n;
    
    -- | Backend-specific rendering options.
    data Options b (v :: Type -> Type) n;
}

-- | 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.
adjustDia :: (Backend b v n, 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)

-- | 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.
renderRTree :: Backend b v n => b -> Options b v n -> RTree b v n Annotation -> Result b v n

-- | A DTree is a raw tree representation of a QDiagram, with
--   all the u-annotations removed. It is used as an intermediate
--   type by diagrams-core; backends should not need to make use of it.
--   Instead, backends can make use of RTree, which DTree
--   gets compiled and optimized to.
type DTree b (v :: Type -> Type) n a = Tree DNode b v n a
data DNode b (v :: Type -> Type) n a
DStyle :: Style v n -> DNode b (v :: Type -> Type) n a
DTransform :: Transformation v n -> DNode b (v :: Type -> Type) n a
DAnnot :: a -> DNode b (v :: Type -> Type) n a

-- | DDelay marks a point where a delayed subtree was expanded.
--   Such subtrees already take all non-frozen transforms above them into
--   account, so when later processing the tree, upon encountering a
--   DDelay node we must drop any accumulated non-frozen
--   transformation.
DDelay :: DNode b (v :: Type -> Type) n a
DPrim :: Prim b v n -> DNode b (v :: Type -> Type) n a
DEmpty :: DNode b (v :: Type -> Type) n a

-- | An RTree is a compiled and optimized representation of a
--   QDiagram, which can be used by backends. They have the
--   following invariant which backends may rely upon:
--   
--   
--   
- RPrim nodes never have any children.
--   
type RTree b (v :: Type -> Type) n a = Tree RNode b v n a
data RNode b (v :: Type -> Type) n a

-- | A style node.
RStyle :: Style v n -> RNode b (v :: Type -> Type) n a
RAnnot :: a -> RNode b (v :: Type -> Type) n a

-- | A primitive.
RPrim :: Prim b v n -> RNode b (v :: Type -> Type) n a
REmpty :: RNode b (v :: Type -> Type) n a

-- | Prism onto a style of an RNode.
_RStyle :: forall b (v :: Type -> Type) n a p f. (Choice p, Applicative f) => p (Style v n) (f (Style v n)) -> p (RNode b v n a) (f (RNode b v n a))

-- | Prism onto an annotation of an RNode.
_RAnnot :: forall b (v :: Type -> Type) n a p f. (Choice p, Applicative f) => p a (f a) -> p (RNode b v n a) (f (RNode b v n a))

-- | Prism onto a Prim of an RNode.
_RPrim :: forall b (v :: Type -> Type) n a p f. (Choice p, Applicative f) => p (Prim b v n) (f (Prim b v n)) -> p (RNode b v n a) (f (RNode b v n a))

-- | Prism onto an empty RNode.
_REmpty :: forall b (v :: Type -> Type) n a p f. (Choice p, Applicative f) => p () (f ()) -> p (RNode b v n a) (f (RNode b v n a))

-- | 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.
data NullBackend

-- | 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 of image
--       The type variables n0, 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 in Image
--       Possible fix:
--         add an instance declaration for
--         (Renderable (DImage n0 External) b0)
--       In the first argument of width, namely
--         `(image (uncheckedImageRef "foo.png" 200 200))'
--       In the expression:
--         width (image (uncheckedImageRef "foo.png" 200 200))
--       In an equation for it:
--           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
--   D V2 Double, like so:
--   
--   
--   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 type V2 with actual type `V a0'
--       The type variable a0 is ambiguous
--       Possible fix: add a type signature that fixes these type variable(s)
--       In the expression: width (circle 1)
--       In an equation for it: 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
--   
--   
type D (v :: Type -> Type) n = QDiagram NullBackend v n Any

-- | Constraint for numeric types that are RealFloat and
--   Typeable, which often occur together. This is used to shorten
--   shorten type constraint contexts.
type TypeableFloat n = (Typeable n, RealFloat n)

-- | The Renderable type class connects backends to primitives which they
--   know how to render.
class Transformable t => Renderable t b

-- | Given a token representing the backend and a transformable object,
--   render it in the appropriate rendering context.
render :: Renderable t b => b -> t -> Render b (V t) (N t)
instance Data.Monoid.Action.Action Diagrams.Core.Names.Name a => Data.Monoid.Action.Action Diagrams.Core.Names.Name (Data.Monoid.Deletable.Deletable a)
instance Data.Monoid.Action.Action Diagrams.Core.Names.Name (Diagrams.Core.Envelope.Envelope v n)
instance Data.Monoid.Action.Action Diagrams.Core.Names.Name (Diagrams.Core.Query.Query v n m)
instance Data.Monoid.Action.Action Diagrams.Core.Names.Name (Diagrams.Core.Types.SubMap b v n m)
instance Data.Monoid.Action.Action Diagrams.Core.Names.Name (Diagrams.Core.Trace.Trace v n)
instance Diagrams.Core.Types.Backend Diagrams.Core.Types.NullBackend v n
instance (Linear.Metric.Metric v, Diagrams.Core.Envelope.OrderedField n, Data.Monoid.WithSemigroup.Monoid' m) => Diagrams.Core.Envelope.Enveloped (Diagrams.Core.Types.QDiagram b v n m)
instance (Diagrams.Core.Envelope.OrderedField n, Linear.Metric.Metric v, Data.Monoid.WithSemigroup.Monoid' m) => Diagrams.Core.Envelope.Enveloped (Diagrams.Core.Types.Subdiagram b v n m)
instance GHC.Internal.Base.Functor (Diagrams.Core.Types.QDiaLeaf b v n)
instance GHC.Internal.Base.Functor (Diagrams.Core.Types.QDiagram b v n)
instance GHC.Internal.Base.Functor (Diagrams.Core.Types.SubMap b v n)
instance GHC.Internal.Base.Functor (Diagrams.Core.Types.Subdiagram b v n)
instance (Linear.Metric.Metric v, Diagrams.Core.Envelope.OrderedField n, GHC.Internal.Base.Semigroup m) => Diagrams.Core.HasOrigin.HasOrigin (Diagrams.Core.Types.QDiagram b v n m)
instance (Diagrams.Core.Envelope.OrderedField n, Linear.Metric.Metric v) => Diagrams.Core.HasOrigin.HasOrigin (Diagrams.Core.Types.SubMap b v n m)
instance (Linear.Metric.Metric v, Diagrams.Core.Envelope.OrderedField n) => Diagrams.Core.HasOrigin.HasOrigin (Diagrams.Core.Types.Subdiagram b v n m)
instance (Linear.Metric.Metric v, Diagrams.Core.Envelope.OrderedField n, GHC.Internal.Base.Semigroup m) => Diagrams.Core.Style.HasStyle (Diagrams.Core.Types.QDiagram b v n m)
instance (Linear.Metric.Metric v, Diagrams.Core.Envelope.OrderedField n, Data.Monoid.WithSemigroup.Monoid' m) => Diagrams.Core.Juxtapose.Juxtaposable (Diagrams.Core.Types.QDiagram b v n m)
instance (Linear.Metric.Metric v, Diagrams.Core.Envelope.OrderedField n, GHC.Internal.Base.Semigroup m) => GHC.Internal.Base.Monoid (Diagrams.Core.Types.QDiagram b v n m)
instance GHC.Internal.Base.Monoid (Diagrams.Core.Types.Render Diagrams.Core.Types.NullBackend v n)
instance GHC.Internal.Base.Monoid (Diagrams.Core.Types.SubMap b v n m)
instance (Linear.Metric.Metric v, Diagrams.Core.Envelope.OrderedField n, GHC.Internal.Base.Semigroup m) => Diagrams.Core.Names.Qualifiable (Diagrams.Core.Types.QDiagram b v n m)
instance Diagrams.Core.Names.Qualifiable (Diagrams.Core.Types.SubMap b v n m)
instance Diagrams.Core.Types.Renderable (Diagrams.Core.Types.Prim b v n) b
instance Control.Lens.Wrapped.Rewrapped (Diagrams.Core.Types.QDiagram b v n m) (Diagrams.Core.Types.QDiagram b' v' n' m')
instance Control.Lens.Wrapped.Rewrapped (Diagrams.Core.Types.SubMap b v n m) (Diagrams.Core.Types.SubMap b' v' n' m')
instance (Linear.Metric.Metric v, Diagrams.Core.Envelope.OrderedField n, GHC.Internal.Base.Semigroup m) => GHC.Internal.Base.Semigroup (Diagrams.Core.Types.QDiagram b v n m)
instance GHC.Internal.Base.Semigroup (Diagrams.Core.Types.Render Diagrams.Core.Types.NullBackend v n)
instance GHC.Internal.Base.Semigroup (Diagrams.Core.Types.SubMap b v n m)
instance GHC.Internal.Show.Show Diagrams.Core.Types.Annotation
instance (Linear.Metric.Metric v, Diagrams.Core.Envelope.OrderedField n, GHC.Internal.Base.Semigroup m) => Diagrams.Core.Trace.Traced (Diagrams.Core.Types.QDiagram b v n m)
instance (Diagrams.Core.Envelope.OrderedField n, Linear.Metric.Metric v, GHC.Internal.Base.Semigroup m) => Diagrams.Core.Trace.Traced (Diagrams.Core.Types.Subdiagram b v n m)
instance Diagrams.Core.Transform.Transformable (Diagrams.Core.Types.Prim b v n)
instance (Diagrams.Core.Envelope.OrderedField n, Linear.Metric.Metric v, GHC.Internal.Base.Semigroup m) => Diagrams.Core.Transform.Transformable (Diagrams.Core.Types.QDiagram b v n m)
instance Diagrams.Core.Transform.Transformable (Diagrams.Core.Types.SubMap b v n m)
instance Diagrams.Core.Transform.Transformable (Diagrams.Core.Types.Subdiagram b v n m)
instance Control.Lens.Wrapped.Wrapped (Diagrams.Core.Types.QDiagram b v n m)
instance Control.Lens.Wrapped.Wrapped (Diagrams.Core.Types.SubMap b v n m)

-- | This module provides tools for compiling QDiagrams into a
--   more convenient and optimized tree form, suitable for use by backends.
module Diagrams.Core.Compile
data RNode b (v :: Type -> Type) n a

-- | A style node.
RStyle :: Style v n -> RNode b (v :: Type -> Type) n a
RAnnot :: a -> RNode b (v :: Type -> Type) n a

-- | A primitive.
RPrim :: Prim b v n -> RNode b (v :: Type -> Type) n a
REmpty :: RNode b (v :: Type -> Type) n a

-- | An RTree is a compiled and optimized representation of a
--   QDiagram, which can be used by backends. They have the
--   following invariant which backends may rely upon:
--   
--   
--   
- RPrim nodes never have any children.
--   
type RTree b (v :: Type -> Type) n a = Tree RNode b v n a

-- | Compile a QDiagram into an RTree, rewriting styles
--   with the given function along the way. Suitable for use by backends
--   when implementing renderData. The first argument is the
--   transformation used to convert the diagram from local to output units.
toRTree :: forall (v :: Type -> Type) n m b. (HasLinearMap v, Metric v, Typeable n, OrderedField n, Monoid m, Semigroup m) => Transformation v n -> QDiagram b v n m -> RTree b v n Annotation

-- | Render a diagram.
renderDia :: forall b (v :: Type -> Type) n m. (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, 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.
renderDiaT :: forall b (v :: Type -> Type) n m. (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)

-- | Convert a QDiagram into a raw tree.
toDTree :: forall (v :: Type -> Type) n b m. (HasLinearMap v, Floating n, Typeable n) => n -> n -> QDiagram b v n m -> Maybe (DTree b v n Annotation)

-- | Convert a DTree to an RTree which can be used
--   directly by backends. A DTree includes nodes of type
--   DTransform (Transformation v); in the RTree
--   transform is pushed down until it reaches a primitive node.
fromDTree :: forall b (v :: Type -> Type) n. (Floating n, HasLinearMap v) => DTree b v n Annotation -> RTree b v n Annotation

-- | 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:
--   https://diagrams.github.io/doc/manual.html#type-reference The
--   following list shows which types are contained in each module of
--   Diagrams.Core.
--   
--   
--   
--   
- Diagrams.Core.Types

- 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.

--   
- Diagrams.Core.Envelope

- Envelope v n,
--   Enveloped a,
- OrderedField
--   s.

--   
- Diagrams.Core.Juxtapose

- Juxtaposable
--   a.

--   
- Diagrams.Core.Names

- AName,
--   Name, IsName
--   a,
- Qualifiable q.

--   
- Diagrams.Core.HasOrigin

- HasOrigin
--   t.

--   
- Diagrams.Core.Query

- Query v n
--   m.

--   
- Diagrams.Core.Style

- AttributeClass
--   a, Attribute v n,
- Style v
--   n, HasStyle.

--   
- Diagrams.Core.Trace

- SortedList
--   a,
- Trace v n, Traced
--   a.

--   
- Diagrams.Core.Transform

- u :-: v,
--   HasLinearMap,
--   HasBasis
- Transformation v n,
--   Transformable t,
- TransInv
--   t.

--   
- Diagrams.Core.V

- V
--   a,
- N a,
- Vn
--   a,
- InSpace v n
--   a,
- SameSpace a b.

--   
module Diagrams.Core

-- | 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 family V a :: Type -> Type

-- | The numerical field for the object, the number type used for
--   calculations.
type family N a

-- | Convenient 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.
type Vn a = V a N a

-- | InSpace v n a means the type a belongs to the vector
--   space v n, where v is Additive and n
--   is a Num.
type InSpace (v :: Type -> Type) n a = (V a ~ v, N a ~ n, Additive v, Num n)

-- | SameSpace a b means the types a and b
--   belong to the same vector space v n.
type SameSpace a b = (V a ~ V b, N a ~ N b)

-- | A handy wrapper to help distinguish points from vectors at the type
--   level
data Point (f :: Type -> Type) a

-- | Vector spaces have origins.
origin :: forall (f :: Type -> Type) a. (Additive f, Num a) => Point f a

-- | Scale a point by a scalar. Specialized version of (*^).
(*.) :: forall (v :: Type -> Type) n. (Functor v, Num n) => n -> Point v n -> Point v n

-- | An isomorphism between points and vectors, given a reference point.
relative :: forall (f :: Type -> Type) a. (Additive f, Num a) => Point f a -> Iso' (Point f a) (f a)

-- | Produce a default basis for a vector space. If the dimensionality of
--   the vector space is not statically known, see basisFor.
basis :: (Additive t, Traversable t, Num a) => [t a]

-- | Get the dimension of an object whose vector space is an instance of
--   HasLinearMap, e.g. transformations, paths, diagrams, etc.
dimension :: (Additive (V a), Traversable (V a)) => a -> Int

-- | The determinant of (the linear part of) a Transformation.
determinant :: forall (v :: Type -> Type) n. (Additive v, Traversable v, Num n) => Transformation v n -> n

-- | Determine whether a Transformation includes a reflection
--   component, that is, whether it reverses orientation.
isReflection :: forall (v :: Type -> Type) n. (Additive v, Traversable v, Num n, Ord n) => Transformation v n -> Bool

-- | (v1 :-: v2) is a linear map paired with its inverse.
data u :-: v
infixr 7 :-:

-- | Create an invertible linear map from two functions which are assumed
--   to be linear inverses.
(<->) :: (u -> v) -> (v -> u) -> u :-: v

-- | Invert a linear map.
linv :: (u :-: v) -> v :-: u

-- | Apply a linear map to a vector.
lapp :: (u :-: v) -> u -> v

-- | 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).
data Transformation (v :: Type -> Type) n

-- | Invert a transformation.
inv :: forall (v :: Type -> Type) n. (Functor v, Num n) => Transformation v n -> Transformation v n

-- | Get the transpose of a transformation (ignoring the translation
--   component).
transp :: Transformation v n -> v n :-: v n

-- | Get the translational component of a transformation.
transl :: Transformation v n -> v n

-- | Drop the translational component of a transformation, leaving only the
--   linear part.
dropTransl :: forall (v :: Type -> Type) n. (Additive v, Num n) => Transformation v n -> Transformation 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.
apply :: Transformation v n -> v n -> v n

-- | Apply a transformation to a point.
papply :: forall (v :: Type -> Type) n. (Additive v, Num n) => Transformation v n -> Point v n -> Point v n

-- | Create a general affine transformation from an invertible linear
--   transformation and its transpose. The translational component is
--   assumed to be zero.
fromLinear :: (Additive v, Num n) => (v n :-: v n) -> (v n :-: v n) -> Transformation v n

-- | Create a translation.
translation :: v n -> Transformation v n

-- | Translate by a vector.
translate :: Transformable t => Vn t -> 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
--   
--   
moveTo :: forall (v :: Type -> Type) n t. (InSpace v n t, HasOrigin t) => Point v n -> t -> 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.
place :: forall (v :: Type -> Type) n t. (InSpace v n t, HasOrigin t) => t -> Point v n -> t

-- | Create a uniform scaling transformation.
scaling :: forall (v :: Type -> Type) n. (Additive v, Fractional n) => n -> Transformation v n

-- | Scale uniformly in every dimension by the given scalar.
scale :: forall (v :: Type -> Type) n a. (InSpace v n a, Eq n, Fractional n, Transformable a) => n -> a -> a

-- | Compute the "average" amount of scaling performed by a transformation.
--   Satisfies the properties
--   
--   
--   avgScale (scaling k) == k
--   avgScale (t1 <> t2)  == avgScale t1 * avgScale t2
--   
--   
avgScale :: forall (v :: Type -> Type) n. (Additive v, Traversable v, Floating n) => Transformation v n -> n

-- | Type class for things t which can be transformed.
class Transformable t

-- | Apply a transformation to an object.
transform :: Transformable t => Transformation (V t) (N t) -> t -> 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.
newtype TransInv t
TransInv :: t -> TransInv t

-- | Identity matrix.
eye :: (HasBasis v, Num n) => v (v n)

-- | Atomic names. AName is just an existential wrapper around
--   things which are Typeable, Ord and Show.
data AName

-- | A (qualified) name is a (possibly empty) sequence of atomic names.
data Name

-- | 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 (Typeable a, Ord a, Show a) => IsName a
toName :: IsName a => a -> Name

-- | Instances of Qualifiable are things which can be qualified by
--   prefixing them with a name.
class Qualifiable q

-- | Qualify with the given name.
(.>>) :: (Qualifiable q, IsName a) => a -> q -> q
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.
(.>) :: (IsName a1, IsName a2) => a1 -> a2 -> Name
infixr 5 .>

-- | Traversal over each name in a Name that matches the target
--   type.
--   
--   
--   >>> toListOf eachName (a .> False .> b) :: String
--   "ab"
--   >>> a .> True .> b & eachName %~ not
--   a .> 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
--   
eachName :: (Typeable a, Ord a, Show a) => Traversal' Name a

-- | A SubMap is a map associating names to subdiagrams. There can
--   be multiple associations for any given name.
newtype SubMap b (v :: Type -> Type) n m
SubMap :: Map Name [Subdiagram b v n m] -> SubMap b (v :: Type -> Type) n m

-- | Construct a SubMap from a list of associations between names
--   and subdiagrams.
fromNames :: forall a b (v :: Type -> Type) n m. IsName a => [(a, Subdiagram b v n m)] -> SubMap b v n m

-- | Add a name/diagram association to a submap.
rememberAs :: forall a b (v :: Type -> Type) n m. IsName a => a -> QDiagram b v n m -> SubMap b v n m -> SubMap 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.
lookupSub :: forall nm b (v :: Type -> Type) n m. IsName nm => nm -> SubMap b v n m -> Maybe [Subdiagram b v n m]

-- | Every attribute must be an instance of AttributeClass, which
--   simply guarantees Typeable and Semigroup constraints.
--   The Semigroup instance for an attribute determines how it will
--   combine with other attributes of the same type.
class (Typeable a, Semigroup a) => AttributeClass a

-- | 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.
data Attribute (v :: Type -> Type) n
[Attribute] :: forall a (v :: Type -> Type) n. AttributeClass a => a -> Attribute v n
[MAttribute] :: forall a n (v :: Type -> Type). AttributeClass a => Measured n a -> Attribute v n
[TAttribute] :: forall a (v :: Type -> Type) n. (AttributeClass a, Transformable a, V a ~ v, N a ~ n) => a -> Attribute v n

-- | A Style is a heterogeneous collection of attributes,
--   containing at most one attribute of any given type.
data Style (v :: Type -> Type) n

-- | Type class for things which have a style.
class HasStyle a

-- | Apply a style by combining it (on the left) with the existing
--   style.
applyStyle :: HasStyle a => Style (V a) (N a) -> a -> 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.
getAttr :: forall a (v :: Type -> Type) n. AttributeClass a => Style v n -> Maybe a

-- | Lens onto a plain attribute of a style.
atAttr :: forall a (v :: Type -> Type) n. AttributeClass a => Lens' (Style v n) (Maybe a)

-- | Lens onto a measured attribute of a style.
atMAttr :: forall a n (v :: Type -> Type). (AttributeClass a, Typeable n) => Lens' (Style v n) (Maybe (Measured n a))

-- | Lens onto a transformable attribute of a style.
atTAttr :: forall a (v :: Type -> Type) n. (V a ~ v, N a ~ n, AttributeClass a, Transformable a) => Lens' (Style v n) (Maybe a)

-- | 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.
applyAttr :: (AttributeClass a, HasStyle d) => 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.
applyMAttr :: (AttributeClass a, N d ~ n, HasStyle d) => Measured n 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.
applyTAttr :: (AttributeClass a, Transformable a, V a ~ V d, N a ~ N d, HasStyle d) => a -> d -> d

-- | 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) onto v is s' *^ v, then
--   s' <= 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.
newtype Envelope (v :: Type -> Type) n
Envelope :: Maybe (v n -> Max n) -> Envelope (v :: Type -> Type) n

-- | "Apply" an envelope by turning it into a function. Nothing is
--   returned iff the envelope is empty.
appEnvelope :: Envelope v n -> Maybe (v n -> n)

-- | A convenient way to transform an envelope, by specifying a
--   transformation on the underlying v n -> n function. The
--   empty envelope is unaffected.
onEnvelope :: ((v n -> n) -> v n -> n) -> Envelope v n -> Envelope v n

-- | Create an envelope from a v n -> n function.
mkEnvelope :: (v n -> n) -> Envelope v n

-- | Enveloped abstracts over things which have an envelope.
class (Metric V a, OrderedField N a) => Enveloped 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.
getEnvelope :: Enveloped a => a -> Envelope (V a) (N a)

-- | Compute the vector from the local origin to a separating hyperplane in
--   the given direction, or Nothing for the empty envelope.
envelopeVMay :: Enveloped a => Vn a -> a -> Maybe (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.
envelopeV :: Enveloped a => Vn a -> a -> Vn a

-- | Compute the point on a separating hyperplane in the given direction,
--   or Nothing 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.
--   Returns the origin for the empty envelope.
envelopeP :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> Point v n

-- | Compute the diameter of a enveloped object along a particular vector.
--   Returns zero for the empty envelope.
diameter :: (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.
radius :: (V a ~ v, N a ~ n, Enveloped a) => v n -> a -> n

-- | The smallest positive axis-parallel vector that bounds the
--   envelope of an object.
size :: (V a ~ v, N a ~ n, Enveloped a, HasBasis v) => a -> v n

-- | 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).
--   
newtype Trace (v :: Type -> Type) n
Trace :: (Point v n -> v n -> SortedList n) -> Trace (v :: Type -> Type) n

-- | 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.
data SortedList a

-- | A smart constructor for the SortedList type, which sorts the
--   input to ensure the SortedList invariant.
mkSortedList :: Ord a => [a] -> SortedList a

-- | Project the (guaranteed sorted) list out of a SortedList
--   wrapper.
getSortedList :: SortedList a -> [a]
appTrace :: Trace v n -> Point v n -> v n -> SortedList n
mkTrace :: (Point v n -> v n -> SortedList n) -> Trace v n

-- | Traced abstracts over things which have a trace.
class (Additive V a, Ord N a) => Traced a

-- | Compute the trace of an object.
getTrace :: Traced a => a -> Trace (V a) (N a)

-- | 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.
--   
traceV :: (n ~ N a, Num n, Traced a) => Point (V a) n -> V a n -> a -> Maybe (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.
--   
traceP :: (n ~ N a, Traced a, Num n) => Point (V a) n -> V a n -> a -> Maybe (Point (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.)
--   
maxTraceV :: (n ~ N a, Num n, Traced a) => Point (V a) n -> V a n -> a -> Maybe (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.)
--   
maxTraceP :: (n ~ N a, Num n, Traced a) => Point (V a) n -> V a n -> a -> Maybe (Point (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.
--   
rayTraceV :: (n ~ N a, Traced a, Num n) => Point (V a) n -> V a n -> a -> Maybe (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.
--   
rayTraceP :: (n ~ N a, Traced a, Num n) => Point (V a) n -> V a n -> a -> Maybe (Point (V a) n)

-- | Like rayTraceV, but computes a vector to the "largest" boundary
--   point instead of the smallest. Considers only positive boundary
--   points.
--   
maxRayTraceV :: (n ~ N a, Traced a, Num n) => Point (V a) n -> V a n -> a -> Maybe (V a n)

-- | Like rayTraceP, but computes 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)

-- | 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, Trails) are
--   transformable but are translationally invariant, i.e. have no origin.
class HasOrigin 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.
moveOriginTo :: HasOrigin t => Point (V t) (N t) -> t -> t

-- | Move the local origin by a relative vector.
moveOriginBy :: (V t ~ v, N t ~ n, HasOrigin t) => v n -> t -> t

-- | Class of things which can be placed "next to" other things, for some
--   appropriate notion of "next to".
class Juxtaposable 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.)
juxtapose :: Juxtaposable a => Vn a -> a -> a -> a

-- | Default implementation of juxtapose for things which are
--   instances of Enveloped and HasOrigin. If either envelope
--   is empty, the second object is returned unchanged.
juxtaposeDefault :: (Enveloped a, HasOrigin a) => Vn a -> a -> a -> a

-- | 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.
newtype Query (v :: Type -> Type) n m
Query :: (Point v n -> m) -> Query (v :: Type -> Type) n m
[runQuery] :: Query (v :: Type -> Type) n m -> Point v n -> m

-- | 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.
data Prim b (v :: Type -> Type) n
[Prim] :: forall p b. (Transformable p, Typeable p, Renderable p b) => p -> Prim b (V p) (N p)

-- | The fundamental diagram type. The type variables are as follows:
--   
--   
--   
- b represents the backend, such as SVG or
--   Cairo. Note that each backend also exports a type synonym
--   B for itself, so the type variable b may also
--   typically be instantiated by B, meaning "use whatever backend
--   is in scope".
--   
- v represents the vector space of the diagram. Typical
--   instantiations include V2 (for a two-dimensional diagram) or
--   V3 (for a three-dimensional diagram).
--   
- n represents the numerical field the diagram uses.
--   Typically this will be a concrete numeric type like
--   Double.
--   
- m is the monoidal type of "query annotations": each point
--   in the diagram has a value of type m associated to it, and
--   these values are combined according to the Monoid instance for
--   m. Most often, m is simply instantiated to
--   Any, associating a simple Bool value to each point
--   indicating whether the point is inside the diagram; Diagram is
--   a synonym for QDiagram with m thus instantiated to
--   Any.
--   
--   
--   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.
data QDiagram b (v :: Type -> Type) n m

-- | Diagram b is a synonym for QDiagram b (V b) (N b)
--   Any. 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 Functor instance of
--   QDiagram b v n or the value function.
type Diagram b = QDiagram b V b N b Any

-- | Create a diagram from a single primitive, along with an envelope,
--   trace, subdiagram map, and query function.
mkQD :: forall b (v :: Type -> Type) n m. 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 "point diagram", which has no content, no trace, an empty
--   query, and a point envelope.
pointDiagram :: forall (v :: Type -> Type) n b m. (Metric v, Fractional n) => Point v n -> QDiagram b v n m

-- | Lens onto the Envelope of a QDiagram.
envelope :: forall n (v :: Type -> Type) m b. (OrderedField n, Metric v, Monoid' m) => Lens' (QDiagram b v n m) (Envelope v n)

-- | Lens onto the Trace of a QDiagram.
trace :: forall (v :: Type -> Type) n m b. (Metric v, OrderedField n, Semigroup m) => Lens' (QDiagram b v n m) (Trace v n)

-- | Lens onto the SubMap of a QDiagram (i.e. an
--   association from names to subdiagrams).
subMap :: forall (v :: Type -> Type) m n b. (Metric v, Semigroup m, OrderedField n) => Lens' (QDiagram b v n m) (SubMap b v n m)

-- | Get a list of names of subdiagrams and their locations.
names :: forall (v :: Type -> Type) m n b. (Metric v, Semigroup m, OrderedField n) => QDiagram b v n m -> [(Name, [Point v n])]

-- | Get the query function associated with a diagram.
query :: forall m b (v :: Type -> Type) n. Monoid m => QDiagram b v n m -> Query 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).
nameSub :: forall nm (v :: Type -> Type) n m b. (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

-- | 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.
withName :: forall nm (v :: Type -> Type) m n b. (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.
withNameAll :: forall nm (v :: Type -> Type) m n b. (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.
withNames :: forall nm (v :: Type -> Type) m n b. (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" a diagram by hiding all the names, so they are no longer
--   visible to the outside.
localize :: forall b (v :: Type -> Type) n m. (Metric v, OrderedField n, Semigroup m) => 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.
href :: forall (v :: Type -> Type) n m b. (Metric v, OrderedField n, Semigroup m) => String -> QDiagram b v n m -> QDiagram b v n m

-- | Change the transparency of a Diagram as a group.
opacityGroup :: forall (v :: Type -> Type) n m b. (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 :: forall (v :: Type -> Type) n m b. (Metric v, OrderedField n, Semigroup m) => Double -> QDiagram b v n m -> QDiagram b v n m

-- | Replace the envelope of a diagram.
setEnvelope :: forall b (v :: Type -> Type) n m. (OrderedField n, Metric v, Monoid' m) => Envelope v n -> QDiagram b v n m -> QDiagram b v n m

-- | Replace the trace of a diagram.
setTrace :: forall b (v :: Type -> Type) n m. (OrderedField n, Metric v, Semigroup m) => Trace v n -> QDiagram b v n m -> QDiagram b v n m

-- | 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).
atop :: forall n (v :: Type -> Type) m b. (OrderedField n, Metric v, Semigroup m) => QDiagram b v n m -> QDiagram b v n m -> QDiagram b v n m
infixl 6 `atop`

-- | 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.).
data Subdiagram b (v :: Type -> Type) n m
Subdiagram :: QDiagram b v n m -> DownAnnots v n -> Subdiagram b (v :: Type -> Type) n m

-- | Turn a diagram into a subdiagram with no accumulated context.
mkSubdiagram :: forall b (v :: Type -> Type) n m. QDiagram b v n m -> Subdiagram 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.
getSub :: forall (v :: Type -> Type) n m b. (Metric v, OrderedField n, Semigroup m) => Subdiagram b v n m -> QDiagram b v n m

-- | Extract the "raw" content of a subdiagram, by throwing away the
--   context.
rawSub :: forall b (v :: Type -> Type) n m. Subdiagram b v n m -> QDiagram b v n m

-- | 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".
location :: forall (v :: Type -> Type) n b m. (Additive v, Num n) => Subdiagram b v n m -> Point v n

-- | 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.
subPoint :: forall (v :: Type -> Type) n b m. (Metric v, OrderedField n) => Point v n -> Subdiagram b v n m

-- | '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.
data Measured n a

-- | A measure is a Measured number.
type Measure n = Measured n n

-- | 
--   fromMeasured globalScale normalizedScale measure -> a
--   
fromMeasured :: Num n => n -> n -> Measured n a -> a

-- | Output units don't change.
output :: n -> Measure n

-- | Local units are scaled by the average scale of a transform.
local :: Num n => n -> Measure n

-- | Global units are scaled so that they are interpreted relative to the
--   size of the final rendered diagram.
global :: Num n => n -> Measure n

-- | Normalized units get scaled so that one normalized unit is the size of
--   the final diagram.
normalized :: Num n => n -> Measure n

-- | Scale the local units of a Measured thing.
scaleLocal :: Num n => n -> Measured n a -> Measured n a

-- | Calculate the larger of two measures.
atLeast :: Ord n => Measure n -> Measure n -> Measure n

-- | Calculate the smaller of two measures.
atMost :: Ord n => Measure n -> Measure n -> Measure n

-- | 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.
class Backend b (v :: Type -> Type) n where {
    
    -- | An intermediate representation used for rendering primitives.
    --   (Typically, this will be some sort of monad, but it need not be.) The
    --   <a>Renderable</a> class guarantees that a backend will be able to
    --   convert primitives into this type; how these rendered primitives are
    --   combined into an ultimate <a>Result</a> is completely up to the
    --   backend.
    data Render b (v :: Type -> Type) n;
    
    -- | The result of running/interpreting a rendering operation.
    type Result b (v :: Type -> Type) n;
    
    -- | Backend-specific rendering options.
    data Options b (v :: Type -> Type) n;
}

-- | 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.
adjustDia :: (Backend b v n, 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)

-- | 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.
renderRTree :: Backend b v n => b -> Options b v n -> RTree b v n Annotation -> Result b v n

-- | The Renderable type class connects backends to primitives which they
--   know how to render.
class Transformable t => Renderable t b

-- | Given a token representing the backend and a transformable object,
--   render it in the appropriate rendering context.
render :: Renderable t b => b -> t -> Render b (V t) (N t)

-- | Render a diagram.
renderDia :: forall b (v :: Type -> Type) n m. (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, 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.
renderDiaT :: forall b (v :: Type -> Type) n m. (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)

-- | 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.
data NullBackend

-- | 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 of image
--       The type variables n0, 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 in Image
--       Possible fix:
--         add an instance declaration for
--         (Renderable (DImage n0 External) b0)
--       In the first argument of width, namely
--         `(image (uncheckedImageRef "foo.png" 200 200))'
--       In the expression:
--         width (image (uncheckedImageRef "foo.png" 200 200))
--       In an equation for it:
--           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
--   D V2 Double, like so:
--   
--   
--   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 type V2 with actual type `V a0'
--       The type variable a0 is ambiguous
--       Possible fix: add a type signature that fixes these type variable(s)
--       In the expression: width (circle 1)
--       In an equation for it: 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
--   
--   
type D (v :: Type -> Type) n = QDiagram NullBackend v n Any

-- | HasLinearMap is a constraint synonym, just to help shorten some
--   of the ridiculously long constraint sets.
type HasLinearMap (v :: Type -> Type) = (HasBasis v, Traversable v)

-- | An Additive vector space whose representation is made up of
--   basis elements.
type HasBasis (v :: Type -> Type) = (Additive v, Representable v, Rep v ~ E v)

-- | 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 constraint as a convenient shorthand.
type OrderedField s = (Floating s, Ord s)

-- | Constraint for numeric types that are RealFloat and
--   Typeable, which often occur together. This is used to shorten
--   shorten type constraint contexts.
type TypeableFloat n = (Typeable n, RealFloat n)

-- | For base < 4.11, the Monoid' constraint is a synonym for
--   things which are instances of both Semigroup and Monoid.
--   For base version 4.11 and onwards, Monoid has
--   Semigroup as a superclass already, so for backwards
--   compatibility Monoid' is provided as a synonym for
--   Monoid.
type Monoid' = Monoid
