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


-- | Embedded domain-specific language for declarative graphics
--   
--   Diagrams is a flexible, extensible EDSL for creating graphics of many
--   types. Graphics can be created in arbitrary vector spaces and rendered
--   with multiple backends. diagrams-lib provides a standard library of
--   primitives and operations for creating diagrams. To get started using
--   it, see <a>Diagrams.Prelude</a>.
@package diagrams-lib
@version 0.7.1.1


-- | A <i>cubic spline</i> is a smooth, connected sequence of cubic curves
--   passing through a given sequence of points. This module implements a
--   straightforward spline generation algorithm based on solving
--   tridiagonal systems of linear equations.
module Diagrams.CubicSpline.Internal

-- | Solves a system of the form 'A*X=D' for <tt>x</tt> where <tt>A</tt> is
--   an <tt>n</tt> by <tt>n</tt> matrix with <tt>bs</tt> as the main
--   diagonal and <tt>as</tt> the diagonal below and <tt>cs</tt> the
--   diagonal above. See:
--   <a>http://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm</a>
solveTriDiagonal :: Fractional a => [a] -> [a] -> [a] -> [a] -> [a]

-- | Solves a system similar to the tri-diagonal system using a special
--   case of the Sherman-Morrison formula
--   <a>http://en.wikipedia.org/wiki/Sherman-Morrison_formula</a>. This
--   code is based on <i>Numerical Recpies in C</i>'s <tt>cyclic</tt>
--   function in section 2.7.
solveCyclicTriDiagonal :: Fractional a => [a] -> [a] -> [a] -> [a] -> a -> a -> [a]

-- | Use the tri-diagonal solver with the appropriate parameters for an
--   open cubic spline.
solveCubicSplineDerivatives :: Fractional a => [a] -> [a]

-- | Use the cyclic-tri-diagonal solver with the appropriate parameters for
--   a closed cubic spline.
solveCubicSplineDerivativesClosed :: Fractional a => [a] -> [a]

-- | Use the cyclic-tri-diagonal solver with the appropriate parameters for
--   a closed cubic spline.
solveCubicSplineCoefficients :: Fractional a => Bool -> [a] -> [[a]]


-- | Nice syntax for constructing and pattern-matching on literal points
--   and vectors.
--   
--   NOTE: to avoid clashing with the '(&amp;)' operator from the
--   <tt>lens</tt> package, this module is not re-exported by
--   <a>Diagrams.Prelude</a>. To make use of the contents of this module,
--   you must explicitly import it.
module Diagrams.Coordinates

-- | A pair of values, with a convenient infix (left-associative) data
--   constructor.
data (:&) a b
(:&) :: a -> b -> :& a b

-- | Types which are instances of the <tt>Coordinates</tt> class can be
--   constructed using <a>&amp;</a> (for example, a three-dimensional
--   vector could be constructed by <tt>1 &amp; 6 &amp; 3</tt>), and
--   deconstructed using <a>coords</a>. A common pattern is to use
--   <a>coords</a> in conjunction with the <tt>ViewPatterns</tt> extension,
--   like so:
--   
--   <pre>
--   foo :: Vector3 -&gt; ...
--   foo (coords -&gt; x :&amp; y :&amp; z) = ...
--   </pre>
class Coordinates c where type family FinalCoord c :: * type family PrevDim c :: * type family Decomposition c :: *
(&) :: Coordinates c => PrevDim c -> FinalCoord c -> c
coords :: Coordinates c => c -> Decomposition c
instance (Eq a, Eq b) => Eq (a :& b)
instance (Ord a, Ord b) => Ord (a :& b)
instance (Show a, Show b) => Show (a :& b)
instance Coordinates (a, b, c, d)
instance Coordinates (a, b, c)
instance Coordinates (a, b)


-- | Some miscellaneous utilities provided by the diagrams-lib package.
module Diagrams.Util

-- | Several functions exported by the diagrams library take a number of
--   arguments giving the user control to "tweak" various aspects of their
--   behavior. Rather than give such functions a long list of arguments,
--   and to make it possible for the user to selectively override only
--   certain arguments and use default values for others, such sets of
--   arguments are collected into a record with named fields (see
--   <tt>PolygonOpts</tt> in <a>Diagrams.TwoD.Shapes</a> for an example).
--   Such record types are made instances of the <a>Default</a> class,
--   which provides a single record structure (<a>def</a>) collecting the
--   "default" arguments to the function. <tt>with</tt> is a synonym for
--   <a>def</a>, which provides nice-looking syntax for simulating
--   optional, named arguments in Haskell. For example,
--   
--   <pre>
--   polygon with {sides = 7, edgeSkip = 2}
--   </pre>
--   
--   calls the <tt>polygon</tt> function with a single argument (note that
--   record update binds more tightly than function application!), namely,
--   <a>with</a> (the record of default arguments) where the <tt>sides</tt>
--   and <tt>edgeSkip</tt> fields have been updated.
with :: Default d => d

-- | <tt>applyAll</tt> takes a list of functions and applies them all to a
--   value, in sequence from the last function in the list to the first.
--   For example, <tt>applyAll [f1, f2, f3] a == f1 . f2 . f3 $ a</tt>.
applyAll :: [a -> a] -> a -> a

-- | Postfix function application, for conveniently applying attributes.
--   Unlike <tt>($)</tt>, <tt>(#)</tt> has a high precedence (8), so <tt>d
--   # foo # bar</tt> can be combined with other things using operators
--   like <tt>(|||)</tt> or <tt>(&lt;&gt;)</tt> without needing
--   parentheses.
(#) :: a -> (a -> b) -> b

-- | <tt>iterateN n f x</tt> returns the list of the first <tt>n</tt>
--   iterates of <tt>f</tt> starting at <tt>x</tt>, that is, the list
--   <tt>[x, f x, f (f x), ...]</tt> of length <tt>n</tt>. (Note that the
--   last element of the list will be <tt>f</tt> applied to <tt>x</tt>
--   <tt>(n-1)</tt> times.)
iterateN :: Int -> (a -> a) -> a -> [a]

-- | The circle constant, the ratio of a circle's circumference to its
--   <i>radius</i>. Note that <tt>pi = tau/2</tt>.
--   
--   For more information and a well-reasoned argument why we should all be
--   using tau instead of pi, see <i>The Tau Manifesto</i>,
--   <a>http://tauday.com/</a>.
--   
--   To hear what it sounds like (and to easily memorize the first 30
--   digits or so), try <a>http://youtu.be/3174T-3-59Q</a>.
tau :: Floating a => a

-- | A value of <tt>Proxy a</tt> carries no information; it's used only to
--   fix the type <tt>a</tt>.
data Proxy a
Proxy :: Proxy a

-- | Given an associative binary operation and a default value to use in
--   the case of an empty list, perform a <i>balanced</i> fold over a list.
--   For example,
--   
--   <pre>
--   foldB (+) z [a,b,c,d,e,f] == ((a+b) + (c+d)) + (e+f)
--   </pre>
foldB :: (a -> a -> a) -> a -> [a] -> a


-- | Exact solving of low-degree (n &lt;= 3) polynomials.
module Diagrams.Solve

-- | The quadratic formula.
quadForm :: (Floating d, Ord d) => d -> d -> d -> [d]

-- | Solve the cubic equation ax^3 + bx^2 + cx + d = 0, returning a list of
--   all real roots.
cubForm :: (Floating d, Ord d) => d -> d -> d -> d -> [d]


-- | Basic types for two-dimensional Euclidean space.
module Diagrams.TwoD.Types

-- | The two-dimensional Euclidean vector space R^2. This type is
--   intentionally abstract.
--   
--   <ul>
--   <li>To construct a vector, use <a>r2</a>, or <a>&amp;</a> (from
--   <a>Diagrams.Coordinates</a>):</li>
--   </ul>
--   
--   <pre>
--   r2 (3,4) :: R2
--   3 &amp; 4    :: R2
--   </pre>
--   
--   Note that <a>Diagrams.Coordinates</a> is not re-exported by
--   <a>Diagrams.Prelude</a> and must be explicitly imported.
--   
--   <ul>
--   <li>To construct the vector from the origin to a point <tt>p</tt>, use
--   <tt>p <a>.-.</a> <a>origin</a></tt>.</li>
--   <li>To convert a vector <tt>v</tt> into the point obtained by
--   following <tt>v</tt> from the origin, use <tt><a>origin</a> <a>.+^</a>
--   v</tt>.</li>
--   <li>To convert a vector back into a pair of components, use
--   <tt>unv2</tt> or <a>coords</a> (from <a>Diagrams.Coordinates</a>).
--   These are typically used in conjunction with the <tt>ViewPatterns</tt>
--   extension:</li>
--   </ul>
--   
--   <pre>
--   foo (unr2 -&gt; (x,y)) = ...
--   foo (coords -&gt; x :&amp; y) = ...
--   </pre>
data R2

-- | Construct a 2D vector from a pair of components. See also
--   <a>&amp;</a>.
r2 :: (Double, Double) -> R2

-- | Convert a 2D vector back into a pair of components. See also
--   <a>coords</a>.
unr2 :: R2 -> (Double, Double)

-- | Points in R^2. This type is intentionally abstract.
--   
--   <ul>
--   <li>To construct a point, use <a>p2</a>, or <a>&amp;</a> (see
--   <a>Diagrams.Coordinates</a>):</li>
--   </ul>
--   
--   <pre>
--   p2 (3,4)  :: P2
--   3 &amp; 4     :: P2
--   </pre>
--   
--   <ul>
--   <li>To construct a point from a vector <tt>v</tt>, use
--   <tt><a>origin</a> <a>.+^</a> v</tt>.</li>
--   <li>To convert a point <tt>p</tt> into the vector from the origin to
--   <tt>p</tt>, use <tt>p <a>.-.</a> <a>origin</a></tt>.</li>
--   <li>To convert a point back into a pair of coordinates, use
--   <a>unp2</a>, or <a>coords</a> (from <a>Diagrams.Coordinates</a>). It's
--   common to use these in conjunction with the <tt>ViewPatterns</tt>
--   extension:</li>
--   </ul>
--   
--   <pre>
--   foo (unp2 -&gt; (x,y)) = ...
--   foo (coords -&gt; x :&amp; y) = ...
--   </pre>
type P2 = Point R2

-- | Construct a 2D point from a pair of coordinates. See also
--   <a>&amp;</a>.
p2 :: (Double, Double) -> P2

-- | Convert a 2D point back into a pair of coordinates. See also
--   <a>coords</a>.
unp2 :: P2 -> (Double, Double)

-- | Transformations in R^2.
type T2 = Transformation R2

-- | Type class for types that measure angles.
class Num a => Angle a
toTurn :: Angle a => a -> Turn
fromTurn :: Angle a => Turn -> a

-- | Newtype wrapper used to represent angles as fractions of a circle. For
--   example, 1/3 turn = tau/3 radians = 120 degrees.
newtype Turn
Turn :: Double -> Turn
getTurn :: Turn -> Double

-- | Deprecated synonym for <a>Turn</a>, retained for backwards
--   compatibility.
type CircleFrac = Turn

-- | Newtype wrapper for representing angles in radians.
newtype Rad
Rad :: Double -> Rad
getRad :: Rad -> Double

-- | Newtype wrapper for representing angles in degrees.
newtype Deg
Deg :: Double -> Deg
getDeg :: Deg -> Double

-- | Deprecated synonym for <a>fullTurn</a>, retained for backwards
--   compatibility.
fullCircle :: Angle a => a

-- | Convert between two angle representations.
convertAngle :: (Angle a, Angle b) => a -> b
instance Typeable R2
instance AdditiveGroup R2
instance Eq R2
instance Ord R2
instance Num R2
instance Fractional R2
instance Read Turn
instance Show Turn
instance Eq Turn
instance Ord Turn
instance Enum Turn
instance Floating Turn
instance Fractional Turn
instance Num Turn
instance Real Turn
instance RealFloat Turn
instance RealFrac Turn
instance Read Rad
instance Show Rad
instance Eq Rad
instance Ord Rad
instance Enum Rad
instance Floating Rad
instance Fractional Rad
instance Num Rad
instance Real Rad
instance RealFloat Rad
instance RealFrac Rad
instance Read Deg
instance Show Deg
instance Eq Deg
instance Ord Deg
instance Enum Deg
instance Floating Deg
instance Fractional Deg
instance Num Deg
instance Real Deg
instance RealFloat Deg
instance RealFrac Deg
instance Angle Deg
instance Angle Rad
instance Angle Turn
instance Transformable R2
instance Coordinates R2
instance InnerSpace R2
instance HasBasis R2
instance VectorSpace R2
instance Newtype R2 (Double, Double)
instance Read R2
instance Show R2


-- | Basic types for three-dimensional Euclidean space.
module Diagrams.ThreeD.Types

-- | The three-dimensional Euclidean vector space R^3.
data R3

-- | Construct a 3D vector from a triple of components.
r3 :: (Double, Double, Double) -> R3

-- | Convert a 3D vector back into a triple of components.
unr3 :: R3 -> (Double, Double, Double)

-- | Points in R^3.
type P3 = Point R3

-- | Construct a 3D point from a triple of coordinates.
p3 :: (Double, Double, Double) -> P3

-- | Convert a 2D point back into a triple of coordinates.
unp3 :: P3 -> (Double, Double, Double)

-- | Transformations in R^3.
type T3 = Transformation R3
instance AdditiveGroup R3
instance Eq R3
instance Ord R3
instance Show R3
instance Read R3
instance Transformable R3
instance Coordinates R3
instance InnerSpace R3
instance HasBasis R3
instance VectorSpace R3
instance Newtype R3 (Double, Double, Double)


-- | Various three-dimensional shapes.
module Diagrams.ThreeD.Shapes
data Ellipsoid
Ellipsoid :: T3 -> Ellipsoid
sphere :: (Backend b R3, Renderable Ellipsoid b) => Diagram b R3
instance Renderable Ellipsoid NullBackend
instance IsPrim Ellipsoid
instance Transformable Ellipsoid


-- | Two-dimensional vectors.
module Diagrams.TwoD.Vector

-- | The unit vector in the positive X direction.
unitX :: R2

-- | The unit vector in the positive Y direction.
unitY :: R2

-- | The unit vector in the negative X direction.
unit_X :: R2

-- | The unit vector in the negative Y direction.
unit_Y :: R2

-- | Compute the direction of a vector, measured counterclockwise from the
--   positive x-axis as a fraction of a full turn. The zero vector is
--   arbitrarily assigned the direction 0.
direction :: Angle a => R2 -> a

-- | Convert an angle into a unit vector pointing in that direction.
fromDirection :: Angle a => a -> R2

-- | A convenient synonym for <a>fromDirection</a>.
e :: Angle a => a -> R2

-- | <tt>perp v</tt> is perpendicular to and has the same magnitude as
--   <tt>v</tt>. In particular <tt>perp v == rotateBy (1/4) v</tt>.
perp :: R2 -> R2

-- | <tt>leftTurn v1 v2</tt> tests whether the direction of <tt>v2</tt> is
--   a left turn from <tt>v1</tt> (that is, if the direction of <tt>v2</tt>
--   can be obtained from that of <tt>v1</tt> by adding an angle 0 &lt;=
--   theta &lt;= tau/2).
leftTurn :: R2 -> R2 -> Bool


-- | Utilities for working with sizes of two-dimensional objects.
module Diagrams.TwoD.Size

-- | Compute the width of an enveloped object.
width :: (Enveloped a, V a ~ R2) => a -> Double

-- | Compute the height of an enveloped object.
height :: (Enveloped a, V a ~ R2) => a -> Double

-- | Compute the width and height of an enveloped object.
size2D :: (Enveloped a, V a ~ R2) => a -> (Double, Double)

-- | Compute the size of an enveloped object as a <a>SizeSpec2D</a> value.
sizeSpec2D :: (Enveloped a, V a ~ R2) => a -> SizeSpec2D

-- | Compute the absolute x-coordinate range of an enveloped object in R2,
--   in the form (lo,hi). Return <tt>Nothing</tt> for objects with an empty
--   envelope.
extentX :: (Enveloped a, V a ~ R2) => a -> Maybe (Double, Double)

-- | Compute the absolute y-coordinate range of an enveloped object in R2,
--   in the form (lo,hi).
extentY :: (Enveloped a, V a ~ R2) => a -> Maybe (Double, Double)

-- | Compute the point at the center (in the x- and y-directions) of a
--   enveloped object. Return the origin for objects with an empty
--   envelope.
center2D :: (Enveloped a, V a ~ R2) => a -> P2

-- | A specification of a (requested) rectangular size.
data SizeSpec2D

-- | Specify an explicit width. The height should be determined
--   automatically (so as to preserve aspect ratio).
Width :: Double -> SizeSpec2D

-- | Specify an explicit height. The width should be determined
--   automatically (so as to preserve aspect ratio).
Height :: Double -> SizeSpec2D

-- | An explicit specification of a width and height.
Dims :: Double -> Double -> SizeSpec2D

-- | Absolute size: use whatever size an object already has; do not
--   rescale.
Absolute :: SizeSpec2D

-- | Create a size specification from a possibly-specified width and
--   height.
mkSizeSpec :: Maybe Double -> Maybe Double -> SizeSpec2D

-- | <tt>requiredScaleT spec sz</tt> returns a transformation (a uniform
--   scale) which can be applied to something of size <tt>sz</tt> to make
--   it fit the requested size <tt>spec</tt>, without changing the aspect
--   ratio.
requiredScaleT :: SizeSpec2D -> (Double, Double) -> Transformation R2

-- | <tt>requiredScale spec sz</tt> returns a scaling factor necessary to
--   make something of size <tt>sz</tt> fit the requested size
--   <tt>spec</tt>, without changing the aspect ratio. Hence an explicit
--   specification of both dimensions may not be honored if the aspect
--   ratios do not match; in that case the scaling will be as large as
--   possible so that the object still fits within the requested size.
requiredScale :: SizeSpec2D -> (Double, Double) -> Double

-- | Uniformly scale any enveloped object so that it fits within the given
--   size.
sized :: (Transformable a, Enveloped a, V a ~ R2) => SizeSpec2D -> a -> a

-- | Uniformly scale an enveloped object so that it "has the same size as"
--   (fits within the width and height of) some other object.
sizedAs :: (Transformable a, Enveloped a, V a ~ R2, Enveloped b, V b ~ R2) => b -> a -> a
instance Eq SizeSpec2D
instance Ord SizeSpec2D
instance Show SizeSpec2D


-- | Points in space. For more tools for working with points and vectors,
--   see <a>Data.AffineSpace</a> and <a>Diagrams.Coordinates</a>.
module Diagrams.Points
data Point v :: * -> *
origin :: AdditiveGroup v => Point v
(*.) :: VectorSpace v => Scalar v -> Point v -> Point v

-- | The centroid of a set of <i>n</i> points is their sum divided by
--   <i>n</i>.
centroid :: (VectorSpace v, Fractional (Scalar v)) => [Point v] -> Point v
instance Coordinates v => Coordinates (Point v)


-- | 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.
module Diagrams.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,
--   <a>http://hackage.haskell.org/package/graphics-drawingcombinators</a>.
newtype Query v m :: * -> * -> *
Query :: (Point v -> m) -> Query v m
runQuery :: Query v m -> Point v -> m

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

-- | Sample a diagram's query function at a given point.
sample :: Monoid m => QDiagram b v m -> Point v -> m

-- | Set the query value for <a>True</a> points in a diagram (<i>i.e.</i>
--   points "inside" the diagram); <a>False</a> points will be set to
--   <a>mempty</a>.
value :: Monoid m => m -> QDiagram b v Any -> QDiagram b v m

-- | Reset the query values of a diagram to <tt>True</tt>/<tt>False</tt>:
--   any values equal to <a>mempty</a> are set to <a>False</a>; any other
--   values are set to <a>True</a>.
resetValue :: (Eq m, Monoid m) => QDiagram b v m -> QDiagram b v Any

-- | Set all the query values of a diagram to <a>False</a>.
clearValue :: QDiagram b v m -> QDiagram b v Any


-- | Names can be given to subdiagrams, and subdiagrams can later be
--   queried by name. This module exports types for representing names and
--   subdiagrams, and various functions for working with them.
module Diagrams.Names

-- | Atomic names. <tt>AName</tt> is just an existential wrapper around
--   things which are <a>Typeable</a>, <a>Ord</a> and <a>Show</a>.
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
--   <a>Typeable</a> (to facilitate extracting them from existential
--   wrappers), <a>Ord</a> (for comparison and efficient storage) and
--   <a>Show</a>.
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 <tt>toName a1 &lt;&gt; toName
--   a2 &lt;&gt; toName a3</tt> you can just write <tt>a1 .&gt; a2 .&gt;
--   a3</tt>.
(.>) :: (IsName a1, IsName a2) => a1 -> a2 -> Name

-- | Instances of <a>Qualifiable</a> are things which can be qualified by
--   prefixing them with a name.
class Qualifiable q
(|>) :: (Qualifiable q, IsName a) => a -> q -> q

-- | A <tt>Subdiagram</tt> 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 m :: * -> * -> * -> *

-- | Turn a diagram into a subdiagram with no accumulated context.
mkSubdiagram :: QDiagram b v m -> Subdiagram b v m

-- | Create a "point subdiagram", that is, a <a>pointDiagram</a> (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
--   <tt>mkSubdiagram . pointDiagram</tt>, which would result in a
--   subdiagram with local origin at the parent origin, rather than at the
--   given point.
subPoint :: (HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Semigroup m) => Point v -> Subdiagram b v 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.
--   <tt>getSub</tt> simply applies the transformation and attributes to
--   the diagram to get the corresponding "top-level" diagram.
getSub :: (HasLinearMap v, InnerSpace v, Floating (Scalar v), Ord (Scalar v), Semigroup m) => Subdiagram b v m -> QDiagram b v m

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

-- | Get the location of a subdiagram; that is, the location of its local
--   origin <i>with respect to</i> the vector space of its parent diagram.
--   In other words, the point where its local origin "ended up".
location :: HasLinearMap v => Subdiagram b v m -> Point v

-- | A <a>SubMap</a> is a map associating names to subdiagrams. There can
--   be multiple associations for any given name.
data SubMap b v m :: * -> * -> * -> *

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

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

-- | Attach an atomic name to a diagram.
named :: (IsName n, HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Semigroup m) => n -> QDiagram b v m -> QDiagram b v m

-- | Attach an atomic name to a certain subdiagram, computed from the given
--   diagram.
nameSub :: (IsName n, HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Semigroup m) => (QDiagram b v m -> Subdiagram b v m) -> n -> QDiagram b v m -> QDiagram b v m

-- | Attach an atomic name to a certain point (which may be computed from
--   the given diagram), treated as a subdiagram with no content and a
--   point envelope.
namePoint :: (IsName n, HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Semigroup m) => (QDiagram b v m -> Point v) -> n -> QDiagram b v m -> QDiagram b v m

-- | "Localize" a diagram by hiding all the names, so they are no longer
--   visible to the outside.
localize :: (HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Semigroup m) => QDiagram b v m -> QDiagram b v m

-- | Get a list of names of subdiagrams and their locations.
names :: HasLinearMap v => QDiagram b v m -> [(Name, [Point v])]

-- | 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 :: IsName n => n -> (Subdiagram b v m -> QDiagram b v m -> QDiagram b v m) -> QDiagram b v m -> QDiagram b v 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 :: IsName n => n -> ([Subdiagram b v m] -> QDiagram b v m -> QDiagram b v m) -> QDiagram b v m -> QDiagram b v 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 :: IsName n => [n] -> ([Subdiagram b v m] -> QDiagram b v m -> QDiagram b v m) -> QDiagram b v m -> QDiagram b v m


-- | Bounding boxes are not very compositional (<i>e.g.</i> it is not
--   possible to do anything sensible with them under rotation), so they
--   are not used in the diagrams core. However, they do have their uses;
--   this module provides definitions and functions for working with them.
module Diagrams.BoundingBox

-- | A bounding box is an axis-aligned region determined by two points
--   indicating its "lower" and "upper" corners. It can also represent an
--   empty bounding box - the points are wrapped in <tt>Maybe</tt>.
data BoundingBox v

-- | An empty bounding box. This is the same thing as <tt>mempty</tt>, but
--   it doesn't require the same type constraints that the <tt>Monoid</tt>
emptyBox :: BoundingBox v

-- | Create a bounding box from a point that is component-wise
--   <tt>(&lt;=)</tt> than the other. If this is not the case, then
--   <tt>mempty</tt> is returned.
fromCorners :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => Point v -> Point v -> BoundingBox v

-- | Create a degenerate bounding "box" containing only a single point.
fromPoint :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => Point v -> BoundingBox v

-- | Create the smallest bounding box containing all the given points.
fromPoints :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => [Point v] -> BoundingBox v

-- | Create a bounding box for any enveloped object (such as a diagram or
--   path).
boundingBox :: (Enveloped a, HasBasis (V a), AdditiveGroup (V a), Ord (Basis (V a))) => a -> BoundingBox (V a)

-- | Queries whether the BoundingBox is empty.
isEmptyBox :: BoundingBox v -> Bool

-- | Gets the lower and upper corners that define the bounding box.
getCorners :: BoundingBox v -> Maybe (Point v, Point v)

-- | Computes all of the corners of the bounding box.
getAllCorners :: (HasBasis v, AdditiveGroup (Scalar v), Ord (Basis v)) => BoundingBox v -> [Point v]

-- | Get the size of the bounding box - the vector from the
--   (component-wise) lesser point to the greater point.
boxExtents :: AdditiveGroup v => BoundingBox v -> v

-- | Create a transformation mapping points from one bounding box to the
--   other.
boxTransform :: (AdditiveGroup v, HasLinearMap v, Fractional (Scalar v), AdditiveGroup (Scalar v), Ord (Basis v)) => BoundingBox v -> BoundingBox v -> Maybe (Transformation v)

-- | Transforms an enveloped thing to fit within a <tt>BoundingBox</tt>. If
--   it's empty, then the result is also <tt>mempty</tt>.
boxFit :: (Enveloped a, Transformable a, Monoid a, Ord (Basis (V a))) => BoundingBox (V a) -> a -> a

-- | Check whether a point is contained in a bounding box (including its
--   edges).
contains :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> Point v -> Bool

-- | Check whether a point is <i>strictly</i> contained in a bounding box.
contains' :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> Point v -> Bool

-- | Test whether the first bounding box is contained inside the second.
inside :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> BoundingBox v -> Bool

-- | Test whether the first bounding box is <i>strictly</i> contained
--   inside the second.
inside' :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> BoundingBox v -> Bool

-- | Test whether the first bounding box lies outside the second (although
--   they may intersect in their boundaries).
outside :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> BoundingBox v -> Bool

-- | Test whether the first bounding box lies <i>strictly</i> outside the
--   second (they do not intersect at all).
outside' :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> BoundingBox v -> Bool

-- | Form the smallest bounding box containing the given two bound union.
--   This function is just an alias for <tt>mappend</tt>.
union :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> BoundingBox v -> BoundingBox v

-- | Form the largest bounding box contained within this given two bounding
--   boxes, or <tt>Nothing</tt> if the two bounding boxes do not overlap at
--   all.
intersection :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> BoundingBox v -> BoundingBox v
instance Typeable1 NonEmptyBoundingBox
instance Typeable1 BoundingBox
instance (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => Monoid (BoundingBox v)
instance (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => Semigroup (BoundingBox v)
instance Eq v => Eq (NonEmptyBoundingBox v)
instance Data v => Data (NonEmptyBoundingBox v)
instance Eq v => Eq (BoundingBox v)
instance Data v => Data (BoundingBox v)
instance Show v => Show (BoundingBox v)
instance (InnerSpace v, HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v), Floating (Scalar v)) => Enveloped (BoundingBox v)
instance (VectorSpace v, HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => HasOrigin (BoundingBox v)
instance (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => Semigroup (NonEmptyBoundingBox v)


-- | Affine transformations, parameterized by any vector space. For
--   transformations on particular vector spaces, see <i>e.g.</i>
--   <a>Diagrams.TwoD.Transform</a>.
module Diagrams.Transform

-- | General (affine) transformations, represented by an invertible linear
--   map, its <i>transpose</i>, and a vector representing a translation
--   component.
--   
--   By the <i>transpose</i> 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 <i>normal vectors</i> transform according to L's inverse
--   transpose. This is exactly what we need when transforming bounding
--   functions, which are defined in terms of <i>perpendicular</i> (i.e.
--   normal) hyperplanes.
data Transformation v :: * -> *

-- | Invert a transformation.
inv :: HasLinearMap v => Transformation v -> Transformation v

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

-- | 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 :: HasLinearMap v => Transformation v -> v -> v

-- | Apply a transformation to a point.
papply :: HasLinearMap v => Transformation v -> Point v -> Point v

-- | Type class for things <tt>t</tt> which can be transformed.
class HasLinearMap (V t) => Transformable t
transform :: Transformable t => Transformation (V t) -> t -> t

-- | Create a translation.
translation :: HasLinearMap v => v -> Transformation v

-- | Translate by a vector.
translate :: (Transformable t, HasLinearMap (V t)) => V t -> t -> t

-- | Translate the object by the translation that sends the origin to the
--   given point. Note that this is dual to <a>moveOriginTo</a>, i.e. we
--   should have
--   
--   <pre>
--   moveTo (origin .^+ v) === moveOriginTo (origin .^- v)
--   </pre>
--   
--   For types which are also <tt>Transformable</tt>, this is essentially
--   the same as <tt>translate</tt>, i.e.
--   
--   <pre>
--   moveTo (origin .^+ v) === translate v
--   </pre>
moveTo :: HasOrigin t => Point (V t) -> t -> t

-- | A flipped variant of <a>moveTo</a>, provided for convenience. Useful
--   when writing a function which takes a point as an argument, such as
--   when using <tt>withName</tt> and friends.
place :: HasOrigin t => t -> Point (V t) -> t

-- | Create a uniform scaling transformation.
scaling :: (HasLinearMap v, Fractional (Scalar v)) => Scalar v -> Transformation v

-- | Scale uniformly in every dimension by the given scalar.
scale :: (Transformable t, Fractional (Scalar (V t)), Eq (Scalar (V t))) => Scalar (V t) -> t -> t

-- | Conjugate one transformation by another. <tt>conjugate t1 t2</tt> is
--   the transformation which performs first <tt>t1</tt>, then <tt>t2</tt>,
--   then the inverse of <tt>t1</tt>.
conjugate :: HasLinearMap v => Transformation v -> Transformation v -> Transformation v

-- | Carry out some transformation "under" another one: <tt>f
--   `<a>under</a>` t</tt> first applies <tt>t</tt>, then <tt>f</tt>, then
--   the inverse of <tt>t</tt>. For example, <tt><tt>scaleX</tt> 2
--   `<a>under</a>` <tt>rotationBy</tt> (-1/8 :: Turn)</tt> is the
--   transformation which scales by a factor of 2 along the diagonal line y
--   = x.
--   
--   Note that
--   
--   <pre>
--   (transform t2) <a>under</a> t1 == transform (conjugate t1 t2)
--   </pre>
--   
--   for all transformations <tt>t1</tt> and <tt>t2</tt>.
under :: Transformable a => (a -> a) -> Transformation (V a) -> a -> a

-- | 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 <tt>Transformable</tt> instead of
--   having a separate class for <a>HasOrigin</a>; indeed, for types which
--   are instances of both we should have the identity
--   
--   <pre>
--   moveOriginTo (origin .^+ v) === translate (negateV v)
--   </pre>
--   
--   The reason is that some things (e.g. vectors, <tt>Trail</tt>s) are
--   transformable but are translationally invariant, i.e. have no origin.
class VectorSpace (V t) => HasOrigin t
moveOriginTo :: HasOrigin t => Point (V t) -> t -> t

-- | Move the local origin by a relative vector.
moveOriginBy :: HasOrigin t => V t -> t -> t


-- | Transformations specific to two dimensions, with a few generic
--   transformations (uniform scaling, translation) also re-exported for
--   convenience.
module Diagrams.TwoD.Transform

-- | Create a transformation which performs a rotation about the local
--   origin by the given angle. See also <a>rotate</a>.
rotation :: Angle a => a -> T2

-- | Rotate about the local origin by the given angle. Positive angles
--   correspond to counterclockwise rotation, negative to clockwise. The
--   angle can be expressed using any type which is an instance of
--   <a>Angle</a>. For example, <tt>rotate (1/4 :: <a>Turn</a>)</tt>,
--   <tt>rotate (tau/4 :: <a>Rad</a>)</tt>, and <tt>rotate (90 ::
--   <a>Deg</a>)</tt> all represent the same transformation, namely, a
--   counterclockwise rotation by a right angle. To rotate about some point
--   other than the local origin, see <a>rotateAbout</a>.
--   
--   Note that writing <tt>rotate (1/4)</tt>, with no type annotation, will
--   yield an error since GHC cannot figure out which sort of angle you
--   want to use. In this common situation you can use <a>rotateBy</a>,
--   which is specialized to take a <a>Turn</a> argument.
rotate :: (Transformable t, V t ~ R2, Angle a) => a -> t -> t

-- | A synonym for <a>rotate</a>, specialized to only work with
--   <tt>Turn</tt> arguments; it can be more convenient to write
--   <tt>rotateBy (1/4)</tt> than <tt><a>rotate</a> (1/4 ::
--   <a>Turn</a>)</tt>.
rotateBy :: (Transformable t, V t ~ R2) => Turn -> t -> t

-- | <tt>rotationAbout p</tt> is a rotation about the point <tt>p</tt>
--   (instead of around the local origin).
rotationAbout :: Angle a => P2 -> a -> T2

-- | <tt>rotateAbout p</tt> is like <a>rotate</a>, except it rotates around
--   the point <tt>p</tt> instead of around the local origin.
rotateAbout :: (Transformable t, V t ~ R2, Angle a) => P2 -> a -> t -> t

-- | Construct a transformation which scales by the given factor in the x
--   (horizontal) direction.
scalingX :: Double -> T2

-- | Scale a diagram by the given factor in the x (horizontal) direction.
--   To scale uniformly, use <a>scale</a>.
scaleX :: (Transformable t, V t ~ R2) => Double -> t -> t

-- | Construct a transformation which scales by the given factor in the y
--   (vertical) direction.
scalingY :: Double -> T2

-- | Scale a diagram by the given factor in the y (vertical) direction. To
--   scale uniformly, use <a>scale</a>.
scaleY :: (Transformable t, V t ~ R2) => Double -> t -> t

-- | Create a uniform scaling transformation.
scaling :: (HasLinearMap v, Fractional (Scalar v)) => Scalar v -> Transformation v

-- | Scale uniformly in every dimension by the given scalar.
scale :: (Transformable t, Fractional (Scalar (V t)), Eq (Scalar (V t))) => Scalar (V t) -> t -> t

-- | <tt>scaleToX w</tt> scales a diagram in the x (horizontal) direction
--   by whatever factor required to make its width <tt>w</tt>.
--   <tt>scaleToX</tt> should not be applied to diagrams with a width of 0,
--   such as <tt>vrule</tt>.
scaleToX :: (Enveloped t, Transformable t, V t ~ R2) => Double -> t -> t

-- | <tt>scaleToY h</tt> scales a diagram in the y (vertical) direction by
--   whatever factor required to make its height <tt>h</tt>.
--   <tt>scaleToY</tt> should not be applied to diagrams with a height of
--   0, such as <tt>hrule</tt>.
scaleToY :: (Enveloped t, Transformable t, V t ~ R2) => Double -> t -> t

-- | <tt>scaleUToX w</tt> scales a diagram <i>uniformly</i> by whatever
--   factor required to make its width <tt>w</tt>. <tt>scaleUToX</tt>
--   should not be applied to diagrams with a width of 0, such as
--   <tt>vrule</tt>.
scaleUToX :: (Enveloped t, Transformable t, V t ~ R2) => Double -> t -> t

-- | <tt>scaleUToY h</tt> scales a diagram <i>uniformly</i> by whatever
--   factor required to make its height <tt>h</tt>. <tt>scaleUToY</tt>
--   should not be applied to diagrams with a height of 0, such as
--   <tt>hrule</tt>.
scaleUToY :: (Enveloped t, Transformable t, V t ~ R2) => Double -> t -> t

-- | Construct a transformation which translates by the given distance in
--   the x (horizontal) direction.
translationX :: Double -> T2

-- | Translate a diagram by the given distance in the x (horizontal)
--   direction.
translateX :: (Transformable t, V t ~ R2) => Double -> t -> t

-- | Construct a transformation which translates by the given distance in
--   the y (vertical) direction.
translationY :: Double -> T2

-- | Translate a diagram by the given distance in the y (vertical)
--   direction.
translateY :: (Transformable t, V t ~ R2) => Double -> t -> t

-- | Create a translation.
translation :: HasLinearMap v => v -> Transformation v

-- | Translate by a vector.
translate :: (Transformable t, HasLinearMap (V t)) => V t -> t -> t

-- | Construct a transformation which flips a diagram from left to right,
--   i.e. sends the point (x,y) to (-x,y).
reflectionX :: T2

-- | Flip a diagram from left to right, i.e. send the point (x,y) to
--   (-x,y).
reflectX :: (Transformable t, V t ~ R2) => t -> t

-- | Construct a transformation which flips a diagram from top to bottom,
--   i.e. sends the point (x,y) to (x,-y).
reflectionY :: T2

-- | Flip a diagram from top to bottom, i.e. send the point (x,y) to
--   (x,-y).
reflectY :: (Transformable t, V t ~ R2) => t -> t

-- | <tt>reflectionAbout p v</tt> is a reflection in the line determined by
--   the point <tt>p</tt> and vector <tt>v</tt>.
reflectionAbout :: P2 -> R2 -> T2

-- | <tt>reflectAbout p v</tt> reflects a diagram in the line determined by
--   the point <tt>p</tt> and the vector <tt>v</tt>.
reflectAbout :: (Transformable t, V t ~ R2) => P2 -> R2 -> t -> t

-- | <tt>shearingX d</tt> is the linear transformation which is the
--   identity on y coordinates and sends <tt>(0,1)</tt> to <tt>(d,1)</tt>.
shearingX :: Double -> T2

-- | <tt>shearX d</tt> performs a shear in the x-direction which sends
--   <tt>(0,1)</tt> to <tt>(d,1)</tt>.
shearX :: (Transformable t, V t ~ R2) => Double -> t -> t

-- | <tt>shearingY d</tt> is the linear transformation which is the
--   identity on x coordinates and sends <tt>(1,0)</tt> to <tt>(1,d)</tt>.
shearingY :: Double -> T2

-- | <tt>shearY d</tt> performs a shear in the y-direction which sends
--   <tt>(1,0)</tt> to <tt>(1,d)</tt>.
shearY :: (Transformable t, V t ~ R2) => Double -> t -> t

-- | The <tt>ScaleInv</tt> wrapper creates two-dimensional
--   <i>scale-invariant</i> objects. Intuitively, a scale-invariant object
--   is affected by transformations like translations and rotations, but
--   not by scales.
--   
--   However, this is problematic when it comes to <i>non-uniform</i>
--   scales (<i>e.g.</i> <tt>scaleX 2 . scaleY 3</tt>) since they can
--   introduce a perceived rotational component. The prototypical example
--   is an arrowhead on the end of a path, which should be scale-invariant.
--   However, applying a non-uniform scale to the path but not the
--   arrowhead would leave the arrowhead pointing in the wrong direction.
--   
--   Moreover, for objects whose local origin is not at the local origin of
--   the parent diagram, any scale can result in a translational component
--   as well.
--   
--   The solution is to also store a point (indicating the location,
--   <i>i.e.</i> the local origin) and a unit vector (indicating the
--   <i>direction</i>) along with a scale-invariant object. A
--   transformation to be applied is decomposed into rotational and
--   translational components as follows:
--   
--   <ul>
--   <li>The transformation is applied to the direction vector, and the
--   difference in angle between the original direction vector and its
--   image under the transformation determines the rotational component.
--   The rotation is applied with respect to the stored location, rather
--   than the global origin.</li>
--   <li>The vector from the location to the image of the location under
--   the transformation determines the translational component.</li>
--   </ul>
data ScaleInv t
ScaleInv :: t -> R2 -> P2 -> ScaleInv t
unScaleInv :: ScaleInv t -> t
scaleInvDir :: ScaleInv t -> R2
scaleInvLoc :: ScaleInv t -> P2

-- | Create a scale-invariant object pointing in the given direction,
--   located at the origin.
scaleInv :: t -> R2 -> ScaleInv t

-- | Create a diagram from a single scale-invariant primitive. The vector
--   argument specifies the direction in which the primitive is "pointing"
--   (for the purpose of keeping it rotated correctly under non-uniform
--   scaling). The primitive is assumed to be "located" at the origin (for
--   the purpose of translating it correctly under scaling).
--   
--   Note that the resulting diagram will have an <i>empty</i> envelope,
--   trace, and query. The reason is that the envelope, trace, and query
--   cannot be cached---applying a transformation would cause the cached
--   envelope, etc. to get "out of sync" with the scale-invariant object.
--   The intention, at any rate, is that scale-invariant things will be
--   used only as "decorations" (<i>e.g.</i> arrowheads) which should not
--   affect the envelope, trace, and query.
scaleInvPrim :: (Transformable t, Renderable t b, V t ~ R2, Monoid m) => t -> R2 -> QDiagram b R2 m

-- | Get the matrix equivalent of the linear transform, (as a pair of
--   columns) and the translation vector. This is mostly useful for
--   implementing backends.
onBasis :: Transformation R2 -> ((R2, R2), R2)
instance Show t => Show (ScaleInv t)
instance (Renderable t b, V t ~ R2) => Renderable (ScaleInv t) b
instance (V t ~ R2, Transformable t) => IsPrim (ScaleInv t)
instance (V t ~ R2, Transformable t) => Transformable (ScaleInv t)
instance (V t ~ R2, HasOrigin t) => HasOrigin (ScaleInv t)


-- | Type classes for things which are parameterized in some way,
--   <i>e.g.</i> segments and trails.
module Diagrams.Parametric

-- | The standard tolerance used by <tt>std...</tt> functions (like
--   <a>stdArcLength</a> and <a>stdArcLengthToParam</a>, currently set at
--   <tt>1e-6</tt>.
stdTolerance :: Fractional a => a

-- | Codomain of parametric classes. This is usually either <tt>(V p)</tt>,
--   for relative vector results, or <tt>(Point (V p))</tt>, for functions
--   with absolute coordinates.

-- | Type class for parametric functions.
class Parametric p
atParam :: Parametric p => p -> Scalar (V p) -> Codomain p

-- | Type class for parametric functions with a bounded domain. The default
--   bounds are <tt>[0,1]</tt>.
--   
--   Note that this domain indicates the main "interesting" portion of the
--   function. It must be defined within this range, but for some instances
--   may still have sensible values outside.
class DomainBounds p where domainLower = const 0 domainUpper = const 1
domainLower :: DomainBounds p => p -> Scalar (V p)
domainUpper :: DomainBounds p => p -> Scalar (V p)

-- | Type class for querying the values of a parametric object at the ends
--   of its domain.
class (Parametric p, DomainBounds p) => EndValues p where atStart x = x `atParam` domainLower x atEnd x = x `atParam` domainUpper x
atStart :: EndValues p => p -> Codomain p
atEnd :: EndValues p => p -> Codomain p

-- | Type class for parametric objects which can be split into subobjects.
--   
--   Minimal definition: Either <a>splitAtParam</a> or <a>section</a>.
class DomainBounds p => Sectionable p where splitAtParam x t = (section x (domainLower x) t, section x t (domainUpper x)) section x t1 t2 = snd (splitAtParam (fst (splitAtParam x t2)) (t1 / t2)) reverseDomain x = section x (domainUpper x) (domainLower x)
splitAtParam :: Sectionable p => p -> Scalar (V p) -> (p, p)
section :: Sectionable p => p -> Scalar (V p) -> Scalar (V p) -> p
reverseDomain :: Sectionable p => p -> p

-- | Type class for parametric things with a notion of arc length.
class Parametric p => HasArcLength p where arcLength eps = midpoint . arcLengthBounded eps stdArcLength = arcLength stdTolerance stdArcLengthToParam = arcLengthToParam stdTolerance
arcLengthBounded :: HasArcLength p => Scalar (V p) -> p -> Interval (Scalar (V p))
arcLength :: HasArcLength p => Scalar (V p) -> p -> Scalar (V p)
stdArcLength :: HasArcLength p => p -> Scalar (V p)
arcLengthToParam :: HasArcLength p => Scalar (V p) -> p -> Scalar (V p) -> Scalar (V p)
stdArcLengthToParam :: HasArcLength p => p -> Scalar (V p) -> Scalar (V p)

-- | Adjust the length of a parametric object such as a segment or trail.
--   The second parameter is an option record which controls how the
--   adjustment should be performed; see <a>AdjustOpts</a>.
adjust :: (DomainBounds a, Sectionable a, HasArcLength a, Fractional (Scalar (V a))) => a -> AdjustOpts (V a) -> a

-- | How should a segment, trail, or path be adjusted?
data AdjustOpts v
AO :: AdjustMethod v -> AdjustSide -> Scalar v -> Proxy v -> AdjustOpts v
adjMethod :: AdjustOpts v -> AdjustMethod v
adjSide :: AdjustOpts v -> AdjustSide
adjEps :: AdjustOpts v -> Scalar v
adjOptsvProxy__ :: AdjustOpts v -> Proxy v

-- | What method should be used for adjusting a segment, trail, or path?
data AdjustMethod v

-- | Extend by the given parameter value (use a negative parameter to
--   shrink)
ByParam :: (Scalar v) -> AdjustMethod v

-- | Extend by the given arc length (use a negative length to shrink)
ByAbsolute :: (Scalar v) -> AdjustMethod v

-- | Extend or shrink to the given arc length
ToAbsolute :: (Scalar v) -> AdjustMethod v

-- | Which side of a segment, trail, or path should be adjusted?
data AdjustSide

-- | Adjust only the beginning
Start :: AdjustSide

-- | Adjust only the end
End :: AdjustSide

-- | Adjust both sides equally
Both :: AdjustSide
instance Show AdjustSide
instance Read AdjustSide
instance Eq AdjustSide
instance Ord AdjustSide
instance Bounded AdjustSide
instance Enum AdjustSide
instance Fractional (Scalar v) => Default (AdjustOpts v)
instance Default AdjustSide
instance Fractional (Scalar v) => Default (AdjustMethod v)


-- | "Located" things, <i>i.e.</i> things with a concrete location:
--   intuitively, <tt>Located a ~ (a, Point)</tt>. Wrapping a
--   translationally invariant thing (<i>e.g.</i> a <tt>Segment</tt> or
--   <tt>Trail</tt>) in <tt>Located</tt> pins it down to a particular
--   location and makes it no longer translationally invariant.
module Diagrams.Located

-- | "Located" things, <i>i.e.</i> things with a concrete location:
--   intuitively, <tt>Located a ~ (Point, a)</tt>. Wrapping a
--   translationally invariant thing (<i>e.g.</i> a <tt>Segment</tt> or
--   <tt>Trail</tt>) in <a>Located</a> pins it down to a particular
--   location and makes it no longer translationally invariant.
--   
--   <tt>Located</tt> is intentionally abstract. To construct
--   <tt>Located</tt> values, use <a>at</a>. To destruct, use
--   <a>viewLoc</a>, <a>unLoc</a>, or <a>loc</a>. To map, use
--   <a>mapLoc</a>.
--   
--   Much of the utility of having a concrete type for the <tt>Located</tt>
--   concept lies in the type class instances we can give it. The
--   <a>HasOrigin</a>, <a>Transformable</a>, <a>Enveloped</a>,
--   <a>Traced</a>, and <tt>TrailLike</tt> instances are particularly
--   useful; see the documented instances below for more information.
data Located a

-- | Construct a <tt>Located a</tt> from a value of type <tt>a</tt> and a
--   location. <tt>at</tt> is intended to be used infix, like <tt>x `at`
--   origin</tt>.
at :: a -> Point (V a) -> Located a

-- | Deconstruct a <tt>Located a</tt> into a location and a value of type
--   <tt>a</tt>. <tt>viewLoc</tt> can be especially useful in conjunction
--   with the <tt>ViewPatterns</tt> extension.
viewLoc :: Located a -> (Point (V a), a)

-- | Project the value of type <tt>a</tt> out of a <tt>Located a</tt>,
--   discarding the location.
unLoc :: Located a -> a

-- | Project out the location of a <tt>Located</tt> value.
loc :: Located a -> Point (V a)

-- | <a>Located</a> is not a <tt>Functor</tt>, since changing the type
--   could change the type of the associated vector space, in which case
--   the associated location would no longer have the right type.
--   <a>mapLoc</a> has an extra constraint specifying that the vector space
--   must stay the same.
--   
--   (Technically, one can say that for every vector space <tt>v</tt>,
--   <tt>Located</tt> is a little-f (endo)functor on the category of types
--   with associated vector space <tt>v</tt>; but that is not covered by
--   the standard <tt>Functor</tt> class.)
mapLoc :: V a ~ V b => (a -> b) -> Located a -> Located b
instance (Show (V a), Show a) => Show (Located a)
instance (Ord (V a), Ord a) => Ord (Located a)
instance (Eq (V a), Eq a) => Eq (Located a)
instance (HasArcLength a, Fractional (Scalar (V a)), V a ~ V (Codomain a)) => HasArcLength (Located a)
instance (Codomain a ~ V a, Fractional (Scalar (V a)), AdditiveGroup (V a), Sectionable a, Parametric a) => Sectionable (Located a)
instance (V a ~ V (Codomain a), EndValues a) => EndValues (Located a)
instance DomainBounds a => DomainBounds (Located a)
instance (V a ~ V (Codomain a), Parametric a) => Parametric (Located a)
instance Qualifiable a => Qualifiable (Located a)
instance Traced a => Traced (Located a)
instance Enveloped a => Juxtaposable (Located a)
instance Enveloped a => Enveloped (Located a)
instance Transformable a => Transformable (Located a)
instance VectorSpace (V a) => HasOrigin (Located a)


-- | A <i>segment</i> is a translation-invariant, atomic path. Currently,
--   there are two types: linear (<i>i.e.</i> just a straight line to the
--   endpoint) and cubic Bézier curves (<i>i.e.</i> a curve to an endpoint
--   with two control points). This module contains tools for creating and
--   manipulating segments, as well as a definition of segments with a
--   fixed location (useful for backend implementors).
--   
--   Generally speaking, casual users of diagrams should not need this
--   module; the higher-level functionality provided by
--   <a>Diagrams.Trail</a>, <a>Diagrams.TrailLike</a>, and
--   <a>Diagrams.Path</a> should usually suffice. However, directly
--   manipulating segments can occasionally be useful.
module Diagrams.Segment

-- | Type tag for open segments.
data Open

-- | Type tag for closed segments.
data Closed

-- | The <i>offset</i> of a segment is the vector from its starting point
--   to its end. The offset for an <i>open</i> segment is determined by the
--   context, <i>i.e.</i> its endpoint is not fixed. The offset for a
--   <i>closed</i> segment is stored explicitly, <i>i.e.</i> its endpoint
--   is at a fixed offset from its start.
data Offset c v
OffsetOpen :: Offset Open v
OffsetClosed :: v -> Offset Closed v

-- | Compute the offset from the start of a segment to the end. Note that
--   in the case of a Bézier segment this is <i>not</i> the same as the
--   length of the curve itself; for that, see <a>arcLength</a>.
segOffset :: Segment Closed v -> v

-- | The atomic constituents of the concrete representation currently used
--   for trails are <i>segments</i>, currently limited to single straight
--   lines or cubic Bézier curves. Segments are <i>translationally
--   invariant</i>, that is, they have no particular "location" and are
--   unaffected by translations. They are, however, affected by other
--   transformations such as rotations and scales.
data Segment c v

-- | A linear segment with given offset.
Linear :: (Offset c v) -> Segment c v

-- | A cubic Bézier segment specified by three offsets from the starting
--   point to the first control point, second control point, and ending
--   point, respectively.
Cubic :: v -> v -> (Offset c v) -> Segment c v

-- | <tt><a>straight</a> v</tt> constructs a translationally invariant
--   linear segment with direction and length given by the vector
--   <tt>v</tt>.
straight :: v -> Segment Closed v

-- | <tt>bezier3 c1 c2 x</tt> constructs a translationally invariant cubic
--   Bézier curve where the offsets from the first endpoint to the first
--   and second control point and endpoint are respectively given by
--   <tt>c1</tt>, <tt>c2</tt>, and <tt>x</tt>.
bezier3 :: v -> v -> v -> Segment Closed v

-- | <tt>bézier3</tt> is the same as <tt>bezier3</tt>, but with more
--   snobbery.
bézier3 :: v -> v -> v -> Segment Closed v

-- | Reverse the direction of a segment.
reverseSegment :: AdditiveGroup v => Segment Closed v -> Segment Closed v

-- | <tt>FixedSegment</tt>s are like <a>Segment</a>s except that they have
--   absolute locations. <tt>FixedSegment v</tt> is isomorphic to
--   <tt>Located (Segment Closed v)</tt>, as witnessed by <a>mkFixedSeg</a>
--   and <a>fromFixedSeg</a>, but <tt>FixedSegment</tt> is convenient when
--   one needs the absolute locations of the vertices and control points.
data FixedSegment v
FLinear :: (Point v) -> (Point v) -> FixedSegment v
FCubic :: (Point v) -> (Point v) -> (Point v) -> (Point v) -> FixedSegment v

-- | Create a <a>FixedSegment</a> from a located <a>Segment</a>.
mkFixedSeg :: AdditiveGroup v => Located (Segment Closed v) -> FixedSegment v

-- | Convert a <a>FixedSegment</a> back into a located <a>Segment</a>.
fromFixedSeg :: AdditiveGroup v => FixedSegment v -> Located (Segment Closed v)

-- | A type to track the count of segments in a <tt>Trail</tt>.
newtype SegCount
SegCount :: Sum Int -> SegCount
getSegCount :: SegCount -> Sum Int

-- | A type to represent the total arc length of a chain of segments. The
--   first component is a "standard" arc length, computed to within a
--   tolerance of <tt>10e-6</tt>. The second component is a generic arc
--   length function taking the tolerance as an argument.
newtype ArcLength v
ArcLength :: (Sum (Interval (Scalar v)), Scalar v -> Sum (Interval (Scalar v))) -> ArcLength v
getArcLength :: ArcLength v -> (Sum (Interval (Scalar v)), Scalar v -> Sum (Interval (Scalar v)))

-- | Project out the cached arc length, stored together with error bounds.
getArcLengthCached :: ArcLength v -> Interval (Scalar v)

-- | Project out the generic arc length function taking the tolerance as an
--   argument.
getArcLengthFun :: ArcLength v -> Scalar v -> Interval (Scalar v)

-- | Given a specified tolerance, project out the cached arc length if it
--   is accurate enough; otherwise call the generic arc length function
--   with the given tolerance.
getArcLengthBounded :: (Num (Scalar v), Ord (Scalar v)) => Scalar v -> ArcLength v -> Interval (Scalar v)

-- | A type to represent the total cumulative offset of a chain of
--   segments.
newtype TotalOffset v
TotalOffset :: v -> TotalOffset v
getTotalOffset :: TotalOffset v -> v

-- | A type to represent the offset and envelope of a chain of segments.
--   They have to be paired into one data structure, since combining the
--   envelopes of two consecutive chains needs to take the offset of the
--   the offset of the first into account.
data OffsetEnvelope v
OffsetEnvelope :: TotalOffset v -> Envelope v -> OffsetEnvelope v
oeOffset :: OffsetEnvelope v -> TotalOffset v
oeEnvelope :: OffsetEnvelope v -> Envelope v

-- | <tt>SegMeasure</tt> collects up all the measurements over a chain of
--   segments.
type SegMeasure v = SegCount ::: (ArcLength v ::: (OffsetEnvelope v ::: ()))
instance (Num (Scalar v), Ord (Scalar v)) => Monoid (ArcLength v)
instance (Num (Scalar v), Ord (Scalar v)) => Semigroup (ArcLength v)
instance Ord v => Ord (Offset c v)
instance Eq v => Eq (Offset c v)
instance Show v => Show (Offset c v)
instance Show v => Show (Segment c v)
instance Functor (Segment c)
instance Eq v => Eq (Segment c v)
instance Ord v => Ord (Segment c v)
instance Show v => Show (FixedSegment v)
instance Semigroup SegCount
instance Monoid SegCount
instance (OrderedField (Scalar v), InnerSpace v) => Measured (SegMeasure v) (Segment Closed v)
instance (InnerSpace v, OrderedField (Scalar v)) => Measured (SegMeasure v) (SegMeasure v)
instance (InnerSpace v, OrderedField (Scalar v)) => Semigroup (OffsetEnvelope v)
instance AdditiveGroup v => Monoid (TotalOffset v)
instance AdditiveGroup v => Semigroup (TotalOffset v)
instance VectorSpace v => Parametric (FixedSegment v)
instance (InnerSpace v, OrderedField (Scalar v)) => Enveloped (FixedSegment v)
instance VectorSpace v => HasOrigin (FixedSegment v)
instance HasLinearMap v => Transformable (FixedSegment v)
instance (InnerSpace v, Floating (Scalar v), Ord (Scalar v), AdditiveGroup v) => HasArcLength (Segment Closed v)
instance (VectorSpace v, Fractional (Scalar v)) => Sectionable (Segment Closed v)
instance (InnerSpace v, OrderedField (Scalar v)) => Enveloped (Segment Closed v)
instance (VectorSpace v, Num (Scalar v)) => EndValues (Segment Closed v)
instance Num (Scalar v) => DomainBounds (Segment Closed v)
instance (VectorSpace v, Num (Scalar v)) => Parametric (Segment Closed v)
instance HasLinearMap v => Renderable (Segment c v) NullBackend
instance HasLinearMap v => Transformable (Segment c v)
instance HasLinearMap v => Transformable (Offset c v)
instance Functor (Offset c)


-- | Compute curvature for segments in two dimensions.
module Diagrams.TwoD.Curvature

-- | Curvature measures how curved the segment is at a point. One intuition
--   for the concept is how much you would turn the wheel when driving a
--   car along the curve. When the wheel is held straight there is zero
--   curvature. When turning a corner to the left we will have positive
--   curvature. When turning to the right we will have negative curvature.
--   
--   Another way to measure this idea is to find the largest circle that we
--   can push up against the curve and have it touch (locally) at exactly
--   the point and not cross the curve. This is a tangent circle. The
--   radius of that circle is the "Radius of Curvature" and it is the
--   reciprocal of curvature. Note that if the circle is on the "left" of
--   the curve, we have a positive radius, and if it is to the right we
--   have a negative radius. Straight segments have an infinite radius
--   which leads us to our representation. We result in a pair of numerator
--   and denominator so we can include infinity and zero for both the
--   radius and the curvature.
--   
--   Lets consider the following curve:
--   
--   
--   The curve starts with positive curvature,
--   
--   
--   approaches zero curvature
--   
--   
--   then has negative curvature
--   
--   
--   <pre>
--   {-# LANGUAGE GADTs #-}
--   
--   import Diagrams.TwoD.Curvature
--   import Data.Monoid.Inf
--   import Diagrams.Coordinates
--   
--   segmentA = Cubic (12 &amp; 0) (8 &amp; 10) (OffsetClosed (20 &amp; 8))
--   
--   curveA = lw 0.1 . stroke . fromSegments $ [segmentA]
--   
--   diagramA = pad 1.1 . centerXY $ curveA
--   
--   diagramPos = diagramWithRadius 0.2
--   
--   diagramZero = diagramWithRadius 0.5
--   
--   diagramNeg = diagramWithRadius 0.8
--   
--   diagramWithRadius t = pad 1.1 . centerXY
--            $ curveA
--           &lt;&gt; showCurvature segmentA t
--            # withEnvelope (curveA :: D R2)
--            # lw 0.05 # lc red
--   
--   showCurvature bez@(Cubic b c (OffsetClosed d)) t
--     | v == 0    = mempty
--     | otherwise = go (radiusOfCurvature bez t)
--     where
--       v@(x,y) = unr2 $ firstDerivative b c d t
--       vp = (-y) &amp; x
--   
--       firstDerivative b c d t = let tt = t*t in (3*(3*tt-4*t+1))*^b + (3*(2-3*t)*t)*^c + (3*tt)*^d
--   
--       go Infinity   = mempty
--       go (Finite r) = (circle (abs r) # translate vpr
--                    &lt;&gt; stroke (origin ~~ (origin .+^ vpr)))
--                     # moveTo (origin .+^ atParam bez t)
--         where
--           vpr = r2 (normalized vp ^* r)
--   </pre>
curvature :: Segment Closed R2 -> Double -> PosInf Double

-- | Reciprocal of <tt>curvature</tt>.
radiusOfCurvature :: Segment Closed R2 -> Double -> PosInf Double

-- | With <tt>squaredCurvature</tt> we can compute values in spaces that do
--   not support <a>sqrt</a> and it is just as useful for relative ordering
--   of curvatures or looking for zeros.
squaredCurvature :: Segment Closed R2 -> Double -> PosInf Double

-- | Reciprocal of <tt>squaredCurvature</tt>
squaredRadiusOfCurvature :: Segment Closed R2 -> Double -> PosInf Double


-- | This module defines <i>trails</i>, translationally invariant paths
--   through space. Trails form a central part of the diagrams-lib API, so
--   the documentation for this module merits careful study.
--   
--   Related modules include:
--   
--   <ul>
--   <li>The <tt>TrailLike</tt> class (<a>Diagrams.TrailLike</a>) exposes a
--   generic API for building a wide range of things out of trails.</li>
--   <li><tt>Path</tt>s (<a>Diagrams.Path</a>) are collections of
--   <a>Located</a> (<a>Diagrams.Located</a>) trails.</li>
--   <li>Trails are composed of <a>Segment</a>s (see
--   <a>Diagrams.Segment</a>), though most users should not need to work
--   with segments directly.</li>
--   </ul>
module Diagrams.Trail

-- | Intuitively, a trail is a single, continuous path through space.
--   However, a trail has no fixed starting point; it merely specifies
--   <i>how</i> to move through space, not <i>where</i>. For example, "take
--   three steps forward, then turn right twenty degrees and take two more
--   steps" is an intuitive analog of a trail; these instructions specify a
--   path through space from any given starting location. To be precise,
--   trails are <i>translation-invariant</i>; applying a translation to a
--   trail has no effect.
--   
--   A <tt><a>Located</a> Trail</tt>, on the other hand, is a trail paired
--   with some concrete starting location ("start at the big tree on the
--   corner, then take three steps forward, ..."). See the
--   <a>Diagrams.Located</a> module for help working with <a>Located</a>
--   values.
--   
--   Formally, the semantics of a trail is a continuous (though not
--   necessarily differentiable) function from the real interval [0,1] to
--   vectors in some vector space. (In contrast, a <a>Located</a> trail is
--   a continuous function from [0,1] to <i>points</i> in some
--   <i>affine</i> space.)
--   
--   There are two types of trails:
--   
--   <ul>
--   <li>A "line" (think of the "train", "subway", or "bus" variety, rather
--   than the "straight" variety...) is a trail with two distinct
--   endpoints. Actually, a line can have the same start and end points,
--   but it is still <i>drawn</i> as if it had distinct endpoints: the two
--   endpoints will have the appropriate end caps, and the trail will not
--   be filled. Lines have a <tt>Monoid</tt> instance where
--   <tt>mappend</tt> corresponds to concatenation, <i>i.e.</i> chaining
--   one line after the other.</li>
--   <li>A "loop" is required to end in the same place it starts (that is,
--   t(0) = t(1)). Loops are filled and are drawn as one continuous loop,
--   with the appropriate join at the start/endpoint rather than end caps.
--   Loops do not have a <tt>Monoid</tt> instance.</li>
--   </ul>
--   
--   To convert between lines and loops, see <a>glueLine</a>,
--   <a>closeLine</a>, and <a>cutLoop</a>.
--   
--   To construct trails, see <a>emptyTrail</a>, <a>trailFromSegments</a>,
--   <a>trailFromVertices</a>, <a>trailFromOffsets</a>, and friends. You
--   can also get any type of trail from any function which returns a
--   <tt>TrailLike</tt> (<i>e.g.</i> functions in
--   <a>Diagrams.TwoD.Shapes</a>, and many others; see
--   <a>Diagrams.TrailLike</a>).
--   
--   To extract information from trails, see <a>withLine</a>,
--   <a>isLoop</a>, <a>trailSegments</a>, <a>trailOffsets</a>,
--   <a>trailVertices</a>, and friends.
data Trail' l v
Line :: SegTree v -> Trail' Line v
Loop :: SegTree v -> Segment Open v -> Trail' Loop v

-- | Make a line into a loop by "gluing" the endpoint to the starting
--   point. In particular, the offset of the final segment is modified so
--   that it ends at the starting point of the entire trail. Typically, you
--   would first construct a line which you know happens to end where it
--   starts, and then call <a>glueLine</a> to turn it into a loop.
--   
--   
--   <pre>
--   import Diagrams.Coordinates
--   glueLineEx = pad 1.1 . hcat' with {sep = 1}
--     $ [almostClosed # strokeLine, almostClosed # glueLine # strokeLoop]
--   
--   almostClosed :: Trail' Line R2
--   almostClosed = fromOffsets [2 &amp; (-1), (-3) &amp; (-0.5), (-2) &amp; 1, 1 &amp; 0.5]
--   </pre>
--   
--   <tt>glueLine</tt> is left inverse to <a>cutLoop</a>, that is,
--   
--   <pre>
--   glueLine . cutLoop === id
--   </pre>
glueLine :: (InnerSpace v, OrderedField (Scalar v)) => Trail' Line v -> Trail' Loop v

-- | Make a line into a loop by adding a new linear segment from the line's
--   end to its start.
--   
--   <tt>closeLine</tt> does not have any particularly nice theoretical
--   properties, but can be useful <i>e.g.</i> when you want to make a
--   closed polygon out of a list of points where the initial point is not
--   repeated at the end. To use <a>glueLine</a>, one would first have to
--   duplicate the initial vertex, like
--   
--   <pre>
--   <a>glueLine</a> . <a>lineFromVertices</a> $ ps ++ [head ps]
--   </pre>
--   
--   Using <tt>closeLine</tt>, however, one can simply
--   
--   <pre>
--   closeLine . lineFromVertices $ ps
--   </pre>
--   
--   
--   <pre>
--   closeLineEx = pad 1.1 . centerXY . hcat' with {sep = 1}
--     $ [almostClosed # strokeLine, almostClosed # closeLine # strokeLoop]
--   </pre>
closeLine :: Trail' Line v -> Trail' Loop v

-- | Turn a loop into a line by "cutting" it at the common start/end point,
--   resulting in a line which just happens to start and end at the same
--   place.
--   
--   <tt>cutLoop</tt> is right inverse to <a>glueLine</a>, that is,
--   
--   <pre>
--   glueLine . cutLoop === id
--   </pre>
cutLoop :: (InnerSpace v, OrderedField (Scalar v)) => Trail' Loop v -> Trail' Line v

-- | <tt>Trail</tt> is a wrapper around <tt>Trail'</tt>, hiding whether the
--   underlying <tt>Trail'</tt> is a line or loop (though which it is can
--   be recovered; see <i>e.g.</i> <a>withTrail</a>).
data Trail v
Trail :: Trail' l v -> Trail v

-- | Convert a <a>Trail'</a> into a <a>Trail</a>, hiding the type-level
--   distinction between lines and loops.
wrapTrail :: Trail' l v -> Trail v

-- | Convert a line into a <a>Trail</a>. This is the same as
--   <a>wrapTrail</a>, but with a more specific type, which can
--   occasionally be convenient for fixing the type of a polymorphic
--   expression.
wrapLine :: Trail' Line v -> Trail v

-- | Convert a loop into a <a>Trail</a>. This is the same as
--   <a>wrapTrail</a>, but with a more specific type, which can
--   occasionally be convenient for fixing the type of a polymorphic
--   expression.
wrapLoop :: Trail' Loop v -> Trail v

-- | Modify a <tt>Trail</tt>, specifying two separate transformations for
--   the cases of a line or a loop.
onTrail :: (Trail' Line v -> Trail' l1 v) -> (Trail' Loop v -> Trail' l2 v) -> (Trail v -> Trail v)

-- | Modify a <tt>Trail</tt> by specifying a transformation on lines. If
--   the trail is a line, the transformation will be applied directly. If
--   it is a loop, it will first be cut using <a>cutLoop</a>, the
--   transformation applied, and then glued back into a loop with
--   <a>glueLine</a>. That is,
--   
--   <pre>
--   onLine f === onTrail f (glueLine . f . cutLoop)
--   </pre>
--   
--   Note that there is no corresponding <tt>onLoop</tt> function, because
--   there is no nice way in general to convert a line into a loop, operate
--   on it, and then convert back.
onLine :: (InnerSpace v, OrderedField (Scalar v)) => (Trail' Line v -> Trail' Line v) -> Trail v -> Trail v

-- | <tt>glueTrail</tt> is a variant of <a>glueLine</a> which works on
--   <a>Trail</a>s. It performs <a>glueLine</a> on lines and is the
--   identity on loops.
glueTrail :: (InnerSpace v, OrderedField (Scalar v)) => Trail v -> Trail v

-- | <tt>closeTrail</tt> is a variant of <a>closeLine</a> for <a>Trail</a>,
--   which performs <a>closeLine</a> on lines and is the identity on loops.
closeTrail :: Trail v -> Trail v

-- | <tt>cutTrail</tt> is a variant of <a>cutLoop</a> for <a>Trail</a>; it
--   is the is the identity on lines and performs <a>cutLoop</a> on loops.
cutTrail :: (InnerSpace v, OrderedField (Scalar v)) => Trail v -> Trail v

-- | The empty line, which is the identity for concatenation of lines.
emptyLine :: (InnerSpace v, OrderedField (Scalar v)) => Trail' Line v

-- | A wrapped variant of <a>emptyLine</a>.
emptyTrail :: (InnerSpace v, OrderedField (Scalar v)) => Trail v

-- | Construct a line containing only linear segments from a list of
--   vertices. Note that only the relative offsets between the vertices
--   matters; the information about their absolute position will be
--   discarded. That is, for all vectors <tt>v</tt>,
--   
--   <pre>
--   lineFromVertices === lineFromVertices . <a>translate</a> v
--   </pre>
--   
--   If you want to retain the position information, you should instead use
--   the more general <tt>fromVertices</tt> function to construct, say, a
--   <tt><a>Located</a> (<a>Trail'</a> <a>Line</a> v)</tt> or a
--   <tt><a>Located</a> (<a>Trail</a> v)</tt>.
--   
--   
--   <pre>
--   import Diagrams.Coordinates
--   lineFromVerticesEx = pad 1.1 . centerXY . strokeLine
--     $ lineFromVertices [origin, 0 &amp; 1, 1 &amp; 2, 5 &amp; 1]
--   </pre>
lineFromVertices :: (InnerSpace v, OrderedField (Scalar v)) => [Point v] -> Trail' Line v

-- | <tt>trailFromVertices === <a>wrapTrail</a> .
--   <a>lineFromVertices</a></tt>, for conveniently constructing a
--   <tt>Trail</tt> instead of a <tt>Trail' Line</tt>.
trailFromVertices :: (InnerSpace v, OrderedField (Scalar v)) => [Point v] -> Trail v

-- | Construct a line containing only linear segments from a list of
--   vectors, where each vector represents the offset from one vertex to
--   the next. See also <tt>fromOffsets</tt>.
--   
--   
--   <pre>
--   import Diagrams.Coordinates
--   lineFromOffsetsEx = strokeLine $ lineFromOffsets [ 2 &amp; 1, 2 &amp; (-1), 2 &amp; 0.5 ]
--   </pre>
lineFromOffsets :: (InnerSpace v, OrderedField (Scalar v)) => [v] -> Trail' Line v

-- | <tt>trailFromOffsets === <a>wrapTrail</a> .
--   <a>lineFromOffsets</a></tt>, for conveniently constructing a
--   <tt>Trail</tt> instead of a <tt>Trail' Line</tt>.
trailFromOffsets :: (InnerSpace v, OrderedField (Scalar v)) => [v] -> Trail v

-- | Construct a line from a list of closed segments.
lineFromSegments :: (InnerSpace v, OrderedField (Scalar v)) => [Segment Closed v] -> Trail' Line v

-- | <tt>trailFromSegments === <a>wrapTrail</a> .
--   <a>lineFromSegments</a></tt>, for conveniently constructing a
--   <tt>Trail</tt> instead of a <tt>Trail'</tt>.
trailFromSegments :: (InnerSpace v, OrderedField (Scalar v)) => [Segment Closed v] -> Trail v

-- | A generic eliminator for <a>Trail'</a>, taking functions specifying
--   what to do in the case of a line or a loop.
withTrail' :: (Trail' Line v -> r) -> (Trail' Loop v -> r) -> Trail' l v -> r

-- | A generic eliminator for <a>Trail</a>, taking functions specifying
--   what to do in the case of a line or a loop.
withTrail :: (Trail' Line v -> r) -> (Trail' Loop v -> r) -> Trail v -> r

-- | An eliminator for <tt>Trail</tt> based on eliminating lines: if the
--   trail is a line, the given function is applied; if it is a loop, it is
--   first converted to a line with <a>cutLoop</a>. That is,
--   
--   <pre>
--   withLine f === <a>withTrail</a> f (f . <a>cutLoop</a>)
--   </pre>
withLine :: (InnerSpace v, OrderedField (Scalar v)) => (Trail' Line v -> r) -> Trail v -> r

-- | Test whether a line is empty.
isLineEmpty :: (InnerSpace v, OrderedField (Scalar v)) => Trail' Line v -> Bool

-- | Test whether a trail is empty. Note that loops are never empty.
isTrailEmpty :: (InnerSpace v, OrderedField (Scalar v)) => Trail v -> Bool

-- | Determine whether a trail is a line.
isLine :: Trail v -> Bool

-- | Determine whether a trail is a loop.
isLoop :: Trail v -> Bool

-- | Extract the segments of a trail. If the trail is a loop it will first
--   have <a>cutLoop</a> applied.
trailSegments :: (InnerSpace v, OrderedField (Scalar v)) => Trail v -> [Segment Closed v]

-- | Extract the segments comprising a line.
lineSegments :: Trail' Line v -> [Segment Closed v]

-- | Extract the segments comprising a loop: a list of closed segments, and
--   one final open segment.
loopSegments :: Trail' Loop v -> ([Segment Closed v], Segment Open v)

-- | Modify a line by applying a function to its list of segments.
onLineSegments :: (InnerSpace v, OrderedField (Scalar v)) => ([Segment Closed v] -> [Segment Closed v]) -> Trail' Line v -> Trail' Line v

-- | Extract the offsets of the segments of a trail.
trailOffsets :: (InnerSpace v, OrderedField (Scalar v)) => Trail v -> [v]

-- | Compute the offset from the start of a trail to the end. Satisfies
--   
--   <pre>
--   trailOffset === sumV . trailOffsets
--   </pre>
--   
--   but is more efficient.
--   
--   
--   <pre>
--   trailOffsetEx = (strokeLine almostClosed &lt;&gt; showOffset) # centerXY # pad 1.1
--     where showOffset = fromOffsets [trailOffset (wrapLine almostClosed)]
--                      # stroke # lc red # lw 0.05
--   </pre>
trailOffset :: (InnerSpace v, OrderedField (Scalar v)) => Trail v -> v

-- | Extract the offsets of the segments of a line.
lineOffsets :: (InnerSpace v, OrderedField (Scalar v)) => Trail' Line v -> [v]

-- | Compute the offset from the start of a line to the end. (Note, there
--   is no corresponding <tt>loopOffset</tt> function because by definition
--   it would be constantly zero.)
lineOffset :: (InnerSpace v, OrderedField (Scalar v)) => Trail' Line v -> v

-- | Extract the offsets of the segments of a loop.
loopOffsets :: (InnerSpace v, OrderedField (Scalar v)) => Trail' Loop v -> [v]

-- | Extract the vertices of a concretely located trail. Note that for
--   loops, the starting vertex will <i>not</i> be repeated at the end. If
--   you want this behavior, you can use <a>cutTrail</a> to make the loop
--   into a line first, which happens to repeat the same vertex at the
--   start and end, <i>e.g.</i> with <tt>trailVertices . mapLoc
--   cutTrail</tt>.
--   
--   Note that it does not make sense to ask for the vertices of a
--   <a>Trail</a> by itself; if you want the vertices of a trail with the
--   first vertex at, say, the origin, you can use <tt>trailVertices .
--   (<a>at</a> origin)</tt>.
trailVertices :: (InnerSpace v, OrderedField (Scalar v)) => Located (Trail v) -> [Point v]

-- | Extract the vertices of a concretely located line. See
--   <a>trailVertices</a> for more information.
lineVertices :: (InnerSpace v, OrderedField (Scalar v)) => Located (Trail' Line v) -> [Point v]

-- | Extract the vertices of a concretely located loop. Note that the
--   initial vertex is not repeated at the end. See <a>trailVertices</a>
--   for more information.
loopVertices :: (InnerSpace v, OrderedField (Scalar v)) => Located (Trail' Loop v) -> [Point v]

-- | Convert a concretely located trail into a list of fixed segments.
fixTrail :: (InnerSpace v, OrderedField (Scalar v)) => Located (Trail v) -> [FixedSegment v]

-- | Reverse a trail. Semantically, if a trail given by a function t from
--   [0,1] to vectors, then the reverse of t is given by t'(s) = t(1-s).
--   <tt>reverseTrail</tt> is an involution, that is,
--   
--   <pre>
--   reverseTrail . reverseTrail === id
--   </pre>
reverseTrail :: (InnerSpace v, OrderedField (Scalar v)) => Trail v -> Trail v

-- | Reverse a concretely located trail. The endpoint of the original trail
--   becomes the starting point of the reversed trail, so the original and
--   reversed trails comprise exactly the same set of points.
--   <tt>reverseLocTrail</tt> is an involution, <i>i.e.</i>
--   
--   <pre>
--   reverseLocTrail . reverseLocTrail === id
--   </pre>
reverseLocTrail :: (InnerSpace v, OrderedField (Scalar v)) => Located (Trail v) -> Located (Trail v)

-- | Reverse a line. See <a>reverseTrail</a>.
reverseLine :: (InnerSpace v, OrderedField (Scalar v)) => Trail' Line v -> Trail' Line v

-- | Reverse a concretely located line. See <a>reverseLocTrail</a>.
reverseLocLine :: (InnerSpace v, OrderedField (Scalar v)) => Located (Trail' Line v) -> Located (Trail' Line v)

-- | Reverse a loop. See <a>reverseTrail</a>.
reverseLoop :: (InnerSpace v, OrderedField (Scalar v)) => Trail' Loop v -> Trail' Loop v

-- | Reverse a concretely located loop. See <a>reverseLocTrail</a>. Note
--   that this is guaranteed to preserve the location.
reverseLocLoop :: (InnerSpace v, OrderedField (Scalar v)) => Located (Trail' Loop v) -> Located (Trail' Loop v)

-- | Type tag for trails with distinct endpoints.
data Line

-- | Type tag for "loopy" trails which return to their starting point.
data Loop

-- | A <tt>SegTree</tt> represents a sequence of closed segments, stored in
--   a fingertree so we can easily recover various monoidal measures of the
--   segments (number of segments, arc length, envelope...) and also easily
--   slice and dice them according to the measures (<i>e.g.</i>, split off
--   the smallest number of segments from the beginning which have a
--   combined arc length of at least 5).
newtype SegTree v
SegTree :: FingerTree (SegMeasure v) (Segment Closed v) -> SegTree v
getSegTree :: SegTree v -> FingerTree (SegMeasure v) (Segment Closed v)

-- | Given a default result (to be used in the case of an empty trail), and
--   a function to map a single measure to a result, extract the given
--   measure for a trail and use it to compute a result. Put another way,
--   lift a function on a single measure (along with a default value) to a
--   function on an entire trail.
trailMeasure :: (InnerSpace v, OrderedField (Scalar v), SegMeasure v :>: m, Measured (SegMeasure v) t) => a -> (m -> a) -> t -> a

-- | Compute the number of segments of anything measured by
--   <a>SegMeasure</a> (<i>e.g.</i> <tt>SegMeasure</tt> itself,
--   <tt>Segment</tt>, <tt>SegTree</tt>, <tt>Trail</tt>s...)
numSegs :: (Floating (Scalar v), Num c, Ord (Scalar v), InnerSpace v, Measured (SegMeasure v) a) => a -> c

-- | Compute the total offset of anything measured by <a>SegMeasure</a>.
offset :: (Floating (Scalar v), Ord (Scalar v), InnerSpace v, Measured (SegMeasure v) t) => t -> v
instance Show v => Show (Trail v)
instance Ord v => Ord (Trail' l v)
instance Eq v => Eq (Trail' l v)
instance Show v => Show (Trail' l v)
instance (HasLinearMap v, InnerSpace v, OrderedField (Scalar v)) => Transformable (SegTree v)
instance (OrderedField (Scalar v), InnerSpace v) => Measured (SegMeasure v) (SegTree v)
instance (OrderedField (Scalar v), InnerSpace v) => Monoid (SegTree v)
instance Eq v => Eq (SegTree v)
instance Ord v => Ord (SegTree v)
instance Show v => Show (SegTree v)
instance (InnerSpace v, OrderedField (Scalar v), RealFrac (Scalar v)) => HasArcLength (Trail v)
instance (InnerSpace v, RealFrac (Scalar v), Floating (Scalar v)) => Sectionable (Trail v)
instance (InnerSpace v, OrderedField (Scalar v), RealFrac (Scalar v)) => EndValues (Trail v)
instance Num (Scalar v) => DomainBounds (Trail v)
instance (InnerSpace v, OrderedField (Scalar v), RealFrac (Scalar v)) => Parametric (Trail v)
instance (InnerSpace v, OrderedField (Scalar v)) => Enveloped (Trail v)
instance (HasLinearMap v, InnerSpace v, OrderedField (Scalar v)) => Transformable (Trail v)
instance (OrderedField (Scalar v), InnerSpace v) => Monoid (Trail v)
instance (OrderedField (Scalar v), InnerSpace v) => Semigroup (Trail v)
instance Ord v => Ord (Trail v)
instance Eq v => Eq (Trail v)
instance (InnerSpace v, OrderedField (Scalar v), RealFrac (Scalar v)) => HasArcLength (Trail' l v)
instance (InnerSpace v, RealFrac (Scalar v), Floating (Scalar v)) => Sectionable (Trail' Line v)
instance (InnerSpace v, OrderedField (Scalar v), RealFrac (Scalar v)) => EndValues (Trail' l v)
instance Num (Scalar v) => DomainBounds (Trail' l v)
instance (InnerSpace v, OrderedField (Scalar v), RealFrac (Scalar v)) => Parametric (Trail' l v)
instance (HasLinearMap v, InnerSpace v, OrderedField (Scalar v)) => Renderable (Trail' o v) NullBackend
instance (InnerSpace v, OrderedField (Scalar v)) => Enveloped (Trail' l v)
instance (HasLinearMap v, InnerSpace v, OrderedField (Scalar v)) => Transformable (Trail' l v)
instance (OrderedField (Scalar v), InnerSpace v) => Monoid (Trail' Line v)
instance (OrderedField (Scalar v), InnerSpace v) => Semigroup (Trail' Line v)
instance (InnerSpace v, OrderedField (Scalar v), RealFrac (Scalar v)) => HasArcLength (SegTree v)
instance (InnerSpace v, RealFrac (Scalar v), Floating (Scalar v)) => Sectionable (SegTree v)
instance (InnerSpace v, OrderedField (Scalar v), RealFrac (Scalar v), Num (Scalar v)) => EndValues (SegTree v)
instance Num (Scalar v) => DomainBounds (SegTree v)
instance (InnerSpace v, OrderedField (Scalar v), RealFrac (Scalar v)) => Parametric (SegTree v)
instance (HasLinearMap (V a), InnerSpace (V a), OrderedField (Scalar (V a)), Measured m a, Transformable a) => Transformable (FingerTree m a)


-- | The <a>TrailLike</a> class abstracts over anything which can be
--   constructed from a concretely located <a>Trail</a>, including lines,
--   loops, trails, paths, vertex lists, and diagrams.
module Diagrams.TrailLike

-- | A type class for trail-like things, <i>i.e.</i> things which can be
--   constructed from a concretely located <a>Trail</a>. Instances include
--   lines, loops, trails, paths, lists of vertices, two-dimensional
--   <a>Diagram</a>s, and <a>Located</a> variants of all the above.
--   
--   Usually, type variables with <a>TrailLike</a> constraints are used as
--   the <i>output</i> types of functions, like
--   
--   <pre>
--   foo :: (TrailLike t) =&gt; ... -&gt; t
--   </pre>
--   
--   Functions with such a type can be used to construct trails, paths,
--   diagrams, lists of points, and so on, depending on the context.
--   
--   To write a function with a signature like the above, you can of course
--   call <a>trailLike</a> directly; more typically, one would use one of
--   the provided functions like <a>fromOffsets</a>, <a>fromVertices</a>,
--   <a>fromSegments</a>, or <a>~~</a>.
class (InnerSpace (V t), OrderedField (Scalar (V t))) => TrailLike t
trailLike :: TrailLike t => Located (Trail (V t)) -> t

-- | Construct a trail-like thing from a list of segments, with the origin
--   as the location.
--   
--   XXX example/picture
fromSegments :: TrailLike t => [Segment Closed (V t)] -> t

-- | Construct a trail-like thing from a located list of segments.
fromLocSegments :: TrailLike t => Located [Segment Closed (V t)] -> t

-- | Construct a trail-like thing of linear segments from a list of
--   offsets, with the origin as the location.
--   
--   XXX example/picture
fromOffsets :: TrailLike t => [V t] -> t

-- | Construct a trail-like thing of linear segments from a located list of
--   offsets.
fromLocOffsets :: (V (V t) ~ V t, TrailLike t) => Located [V t] -> t

-- | Construct a trail-like thing connecting the given vertices with linear
--   segments, with the first vertex as the location. If no vertices are
--   given, the empty trail is used with the origin as the location.
--   
--   XXX example/picture
fromVertices :: TrailLike t => [Point (V t)] -> t

-- | Create a linear trail between two given points.
(~~) :: TrailLike t => Point (V t) -> Point (V t) -> t

-- | Given a concretely located trail, "explode" it by turning each segment
--   into its own separate trail. Useful for (say) applying a different
--   style to each segment.
explodeTrail :: (VectorSpace (V t), TrailLike t) => Located (Trail (V t)) -> [t]
instance TrailLike t => TrailLike (Located t)
instance TrailLike t => TrailLike (TransInv t)
instance (InnerSpace v, OrderedField (Scalar v)) => TrailLike (Trail v)
instance (InnerSpace v, OrderedField (Scalar v)) => TrailLike (Trail' Loop v)
instance (InnerSpace v, OrderedField (Scalar v)) => TrailLike (Trail' Line v)
instance (InnerSpace v, OrderedField (Scalar v)) => TrailLike [Point v]


-- | Segments in two dimensions are special since we may meaningfully
--   compute their point of intersection with a ray.
module Diagrams.TwoD.Segment
instance Traced (FixedSegment R2)
instance Traced (Segment Closed R2)


-- | The <i>alignment</i> of an object refers to the position of its local
--   origin with respect to its envelope. This module defines the
--   <a>Alignable</a> class for things which can be aligned, as well as a
--   default implementation in terms of <a>HasOrigin</a> and
--   <a>Enveloped</a>, along with several utility methods for alignment.
module Diagrams.Align

-- | Class of things which can be aligned.
class Alignable a
alignBy :: Alignable a => V a -> Scalar (V a) -> a -> a

-- | Default implementation of <a>alignBy</a> for types with
--   <a>HasOrigin</a> and <a>Enveloped</a> instances.
alignByDefault :: (HasOrigin a, Enveloped a, Num (Scalar (V a))) => V a -> Scalar (V a) -> a -> a

-- | <tt>align v</tt> aligns an enveloped object along the edge in the
--   direction of <tt>v</tt>. That is, it moves the local origin in the
--   direction of <tt>v</tt> until it is on the edge of the envelope. (Note
--   that if the local origin is outside the envelope to begin with, it may
--   have to move "backwards".)
align :: (Alignable a, Num (Scalar (V a))) => V a -> a -> a

-- | <tt>center v</tt> centers an enveloped object along the direction of
--   <tt>v</tt>.
center :: (Alignable a, Num (Scalar (V a))) => V a -> a -> a
instance (HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Monoid' m) => Alignable (QDiagram b v m)
instance (Enveloped b, HasOrigin b) => Alignable (Map k b)
instance (Enveloped b, HasOrigin b, Ord b) => Alignable (Set b)
instance (Enveloped b, HasOrigin b) => Alignable [b]
instance (InnerSpace v, OrderedField (Scalar v)) => Alignable (Envelope v)


-- | This module defines <i>paths</i>, which are collections of concretely
--   located <a>Trail</a>s. Many drawing systems (cairo, svg, ...) have a
--   similar notion of "path". Note that paths with multiple trails are
--   necessary for being able to draw <i>e.g.</i> filled objects with holes
--   in them.
module Diagrams.Path

-- | A <i>path</i> is a (possibly empty) list of <a>Located</a>
--   <a>Trail</a>s. Hence, unlike trails, paths are not translationally
--   invariant, and they form a monoid under <i>superposition</i> (placing
--   one path on top of another) rather than concatenation.
newtype Path v
Path :: [Located (Trail v)] -> Path v
pathTrails :: Path v -> [Located (Trail v)]

-- | Convert a trail to a path beginning at the origin.
pathFromTrail :: (InnerSpace v, OrderedField (Scalar v)) => Trail v -> Path v

-- | Convert a trail to a path with a particular starting point.
pathFromTrailAt :: (InnerSpace v, OrderedField (Scalar v)) => Trail v -> Point v -> Path v

-- | Convert a located trail to a singleton path. This is equivalent to
--   <a>trailLike</a>, but provided with a more specific name and type for
--   convenience.
pathFromLocTrail :: (InnerSpace v, OrderedField (Scalar v)) => Located (Trail v) -> Path v

-- | Extract the vertices of a path, resulting in a separate list of
--   vertices for each component trail (see <a>trailVertices</a>).
pathVertices :: (InnerSpace v, OrderedField (Scalar v)) => Path v -> [[Point v]]

-- | Compute the total offset of each trail comprising a path (see
--   <a>trailOffset</a>).
pathOffsets :: (InnerSpace v, OrderedField (Scalar v)) => Path v -> [v]

-- | Compute the <i>centroid</i> of a path (<i>i.e.</i> the average
--   location of its vertices).
pathCentroid :: (InnerSpace v, OrderedField (Scalar v)) => Path v -> Point v

-- | Convert a path into a list of lists of <a>FixedSegment</a>s.
fixPath :: (InnerSpace v, OrderedField (Scalar v)) => Path v -> [[FixedSegment v]]

-- | Scale a path using its centroid (see <a>pathCentroid</a>) as the base
--   point for the scale.
scalePath :: (HasLinearMap v, InnerSpace v, OrderedField (Scalar v)) => Scalar v -> Path v -> Path v

-- | Reverse all the component trails of a path.
reversePath :: (InnerSpace v, OrderedField (Scalar v)) => Path v -> Path v

-- | "Explode" a path by exploding every component trail (see
--   <a>explodeTrail</a>).
explodePath :: (VectorSpace (V t), TrailLike t) => Path (V t) -> [[t]]

-- | Partition a path into two paths based on a predicate on trails: the
--   first containing all the trails for which the predicate returns
--   <tt>True</tt>, and the second containing the remaining trails.
partitionPath :: (Located (Trail v) -> Bool) -> Path v -> (Path v, Path v)
instance Ord v => Ord (Path v)
instance Eq v => Eq (Path v)
instance Show v => Show (Path v)
instance Semigroup (Path v)
instance Monoid (Path v)
instance (HasLinearMap v, InnerSpace v, OrderedField (Scalar v)) => Renderable (Path v) NullBackend
instance (InnerSpace v, OrderedField (Scalar v)) => Alignable (Path v)
instance (InnerSpace v, OrderedField (Scalar v)) => Juxtaposable (Path v)
instance (InnerSpace v, OrderedField (Scalar v)) => Enveloped (Path v)
instance (HasLinearMap v, InnerSpace v, OrderedField (Scalar v)) => IsPrim (Path v)
instance (HasLinearMap v, InnerSpace v, OrderedField (Scalar v)) => Transformable (Path v)
instance (InnerSpace v, OrderedField (Scalar v)) => TrailLike (Path v)
instance VectorSpace v => HasOrigin (Path v)
instance Newtype (Path v) [Located (Trail v)]


-- | Higher-level tools for combining diagrams.
module Diagrams.Combinators

-- | Use the envelope from some object as the envelope for a diagram, in
--   place of the diagram's default envelope.
withEnvelope :: (HasLinearMap (V a), Enveloped a, Monoid' m) => a -> QDiagram b (V a) m -> QDiagram b (V a) m

-- | Use the trace from some object as the trace for a diagram, in place of
--   the diagram's default trace.
withTrace :: (HasLinearMap (V a), Traced a, OrderedField (Scalar (V a)), InnerSpace (V a), Monoid' m) => a -> QDiagram b (V a) m -> QDiagram b (V a) m

-- | <tt>phantom x</tt> produces a "phantom" diagram, which has the same
--   envelope and trace as <tt>x</tt> but produces no output.
phantom :: (Backend b (V a), Enveloped a, Traced a, Monoid' m) => a -> QDiagram b (V a) m

-- | <tt>strut v</tt> is a diagram which produces no output, but with
--   respect to alignment and envelope acts like a 1-dimensional segment
--   oriented along the vector <tt>v</tt>, with local origin at its center.
--   (Note, however, that it has an empty trace; for 2D struts with a
--   nonempty trace see <tt>strutR2</tt>, <tt>strutX</tt>, and
--   <tt>strutY</tt> from <a>Diagrams.TwoD.Combinators</a>.) Useful for
--   manually creating separation between two diagrams.
strut :: (Backend b v, InnerSpace v, OrderedField (Scalar v), Monoid' m) => v -> QDiagram b v m

-- | <tt>pad s</tt> "pads" a diagram, expanding its envelope by a factor of
--   <tt>s</tt> (factors between 0 and 1 can be used to shrink the
--   envelope). Note that the envelope will expand with respect to the
--   local origin, so if the origin is not centered the padding may appear
--   "uneven". If this is not desired, the origin can be centered (using,
--   e.g., <tt>centerXY</tt> for 2D diagrams) before applying <tt>pad</tt>.
pad :: (Backend b v, InnerSpace v, OrderedField (Scalar v), Monoid' m) => Scalar v -> QDiagram b v m -> QDiagram b v m

-- | <tt>extrudeEnvelope v d</tt> asymmetrically "extrudes" the envelope of
--   a diagram in the given direction. All parts of the envelope within 90
--   degrees of this direction are modified, offset outwards by the
--   magnitude of the vector.
--   
--   This works by offsetting the envelope distance proportionally to the
--   cosine of the difference in angle, and leaving it unchanged when this
--   factor is negative.
extrudeEnvelope :: (Ord (Scalar v), Num (Scalar v), AdditiveGroup (Scalar v), Floating (Scalar v), HasLinearMap v, InnerSpace v, Monoid' m) => v -> QDiagram b v m -> QDiagram b v m

-- | <tt>intrudeEnvelope v d</tt> asymmetrically "intrudes" the envelope of
--   a diagram away from the given direction. All parts of the envelope
--   within 90 degrees of this direction are modified, offset inwards by
--   the magnitude of the vector.
--   
--   Note that this could create strange inverted envelopes, where <tt>
--   diameter v d &lt; 0 </tt>.
intrudeEnvelope :: (Ord (Scalar v), Num (Scalar v), AdditiveGroup (Scalar v), Floating (Scalar v), HasLinearMap v, InnerSpace v, Monoid' m) => v -> QDiagram b v m -> QDiagram b v m

-- | A convenient synonym for <a>mappend</a> 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 :: (HasLinearMap v, OrderedField (Scalar v), InnerSpace v, Semigroup m) => QDiagram b v m -> QDiagram b v m -> QDiagram b v m

-- | <tt>beneath</tt> is just a convenient synonym for <tt><a>flip</a>
--   <a>atop</a></tt>; that is, <tt>d1 `beneath` d2</tt> is the diagram
--   with <tt>d2</tt> superimposed on top of <tt>d1</tt>.
beneath :: (HasLinearMap v, OrderedField (Scalar v), InnerSpace v, Monoid' m) => QDiagram b v m -> QDiagram b v m -> QDiagram b v m

-- | Place two monoidal objects (<i>i.e.</i> diagrams, paths,
--   animations...) next to each other along the given vector. In
--   particular, place the second object so that the vector points from the
--   local origin of the first object to the local origin of the second
--   object, at a distance so that their envelopes are just tangent. The
--   local origin of the new, combined object is the local origin of the
--   first object (unless the first object is the identity element, in
--   which case the second object is returned unchanged).
--   
--   
--   <pre>
--   besideEx = beside (r2 (20,30))
--                     (circle 1 # fc orange)
--                     (circle 1.5 # fc purple)
--              # showOrigin
--              # centerXY # pad 1.1
--   </pre>
--   
--   Note that <tt>beside v</tt> is associative, so objects under
--   <tt>beside v</tt> form a semigroup for any given vector <tt>v</tt>. In
--   fact, they also form a monoid: <a>mempty</a> is clearly a right
--   identity (<tt>beside v d1 mempty === d1</tt>), and there should also
--   be a special case to make it a left identity, as described above.
--   
--   In older versions of diagrams, <tt>beside</tt> put the local origin of
--   the result at the point of tangency between the two inputs. That
--   semantics can easily be recovered by performing an alignment on the
--   first input before combining. That is, if <tt>beside'</tt> denotes the
--   old semantics,
--   
--   <pre>
--   beside' v x1 x2 = beside v (x1 # align v) x2
--   </pre>
--   
--   To get something like <tt>beside v x1 x2</tt> whose local origin is
--   identified with that of <tt>x2</tt> instead of <tt>x1</tt>, use
--   <tt>beside (negateV v) x2 x1</tt>.
beside :: (Juxtaposable a, Semigroup a) => V a -> a -> a -> a

-- | <tt>appends x ys</tt> appends each of the objects in <tt>ys</tt> to
--   the object <tt>x</tt> in the corresponding direction. Note that each
--   object in <tt>ys</tt> is positioned beside <tt>x</tt> <i>without</i>
--   reference to the other objects in <tt>ys</tt>, so this is not the same
--   as iterating <a>beside</a>.
appends :: (Juxtaposable a, Monoid' a) => a -> [(V a, a)] -> a

-- | Position things absolutely: combine a list of objects (e.g. diagrams
--   or paths) by assigning them absolute positions in the vector space of
--   the combined object.
position :: (HasOrigin a, Monoid' a) => [(Point (V a), a)] -> a

-- | Combine a list of diagrams (or paths) by using them to "decorate" a
--   trail, placing the local origin of one object at each successive
--   vertex of the trail. The first vertex of the trail is placed at the
--   origin. If the trail and list of objects have different lengths, the
--   extra tail of the longer one is ignored.
decorateTrail :: (InnerSpace (V a), OrderedField (Scalar (V a)), HasOrigin a, Monoid' a) => Trail (V a) -> [a] -> a

-- | Combine a list of diagrams (or paths) by using them to "decorate" a
--   concretely located trail, placing the local origin of one object at
--   each successive vertex of the trail. If the trail and list of objects
--   have different lengths, the extra tail of the longer one is ignored.
decorateLocatedTrail :: (InnerSpace (V a), OrderedField (Scalar (V a)), HasOrigin a, Monoid' a) => Located (Trail (V a)) -> [a] -> a

-- | Combine a list of diagrams (or paths) by using them to "decorate" a
--   path, placing the local origin of one object at each successive vertex
--   of the path. If the path and list of objects have different lengths,
--   the extra tail of the longer one is ignored.
decoratePath :: (InnerSpace (V a), OrderedField (Scalar (V a)), HasOrigin a, Monoid' a) => Path (V a) -> [a] -> a

-- | <tt>cat v</tt> positions a list of objects so that their local origins
--   lie along a line in the direction of <tt>v</tt>. Successive objects
--   will have their envelopes just touching. The local origin of the
--   result will be the same as the local origin of the first object.
--   
--   See also <a>cat'</a>, which takes an extra options record allowing
--   certain aspects of the operation to be tweaked.
cat :: (Juxtaposable a, Monoid' a, HasOrigin a, InnerSpace (V a), OrderedField (Scalar (V a))) => V a -> [a] -> a

-- | Like <a>cat</a>, but taking an extra <a>CatOpts</a> arguments allowing
--   the user to specify
--   
--   <ul>
--   <li>The spacing method: catenation (uniform spacing between envelopes)
--   or distribution (uniform spacing between local origins). The default
--   is catenation.</li>
--   <li>The amount of separation between successive diagram
--   envelopes/origins (depending on the spacing method). The default is
--   0.</li>
--   </ul>
--   
--   <a>CatOpts</a> is an instance of <a>Default</a>, so <a>with</a> may be
--   used for the second argument, as in <tt>cat' (1,2) with {sep =
--   2}</tt>.
--   
--   Note that <tt>cat' v with {catMethod = Distrib} === mconcat</tt>
--   (distributing with a separation of 0 is the same as superimposing).
cat' :: (Juxtaposable a, Monoid' a, HasOrigin a, InnerSpace (V a), OrderedField (Scalar (V a))) => V a -> CatOpts (V a) -> [a] -> a

-- | Options for <a>cat'</a>.
data CatOpts v
CatOpts :: CatMethod -> Scalar v -> Proxy v -> CatOpts v

-- | Which <a>CatMethod</a> should be used: normal catenation (default), or
--   distribution?
catMethod :: CatOpts v -> CatMethod

-- | How much separation should be used between successive diagrams
--   (default: 0)? When <tt>catMethod = Cat</tt>, this is the distance
--   between <i>envelopes</i>; when <tt>catMethod = Distrib</tt>, this is
--   the distance between <i>origins</i>.
sep :: CatOpts v -> Scalar v

-- | This field exists solely to aid type inference; please ignore it.
catOptsvProxy__ :: CatOpts v -> Proxy v

-- | Methods for concatenating diagrams.
data CatMethod

-- | Normal catenation: simply put diagrams next to one another (possibly
--   with a certain distance in between each). The distance between
--   successive diagram <i>envelopes</i> will be consistent; the distance
--   between <i>origins</i> may vary if the diagrams are of different
--   sizes.
Cat :: CatMethod

-- | Distribution: place the local origins of diagrams at regular
--   intervals. With this method, the distance between successive
--   <i>origins</i> will be consistent but the distance between envelopes
--   may not be. Indeed, depending on the amount of separation, diagrams
--   may overlap.
Distrib :: CatMethod
instance Num (Scalar v) => Default (CatOpts v)


-- | "Envelopes", aka functional bounding regions. See
--   <a>Diagrams.Core.Envelope</a> for internal implementation details.
module Diagrams.Envelope

-- | Every diagram comes equipped with an <i>envelope</i>. What is an
--   envelope?
--   
--   Consider first the idea of a <i>bounding box</i>. 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 <i>every</i>
--   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 <i>extensional</i> representation of such a
--   "bounding region". Instead of storing some sort of direct
--   representation, we store a <i>function</i> 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 <tt>v</tt>, the envelope computes a scalar
--   <tt>s</tt> such that
--   
--   <ul>
--   <li>for every point <tt>u</tt> inside the diagram, if the projection
--   of <tt>(u - origin)</tt> onto <tt>v</tt> is <tt>s' *^ v</tt>, then
--   <tt>s' &lt;= s</tt>.</li>
--   <li><tt>s</tt> is the smallest such scalar.</li>
--   </ul>
--   
--   There is also a special "empty envelope".
--   
--   The idea for envelopes came from Sebastian Setzer; see
--   <a>http://byorgey.wordpress.com/2009/10/28/collecting-attributes/#comment-2030</a>.
--   See also Brent Yorgey, <i>Monoids: Theme and Variations</i>, published
--   in the 2012 Haskell Symposium:
--   <a>http://www.cis.upenn.edu/~byorgey/pub/monoid-pearl.pdf</a>; video:
--   <a>http://www.youtube.com/watch?v=X-8NCkD2vOw</a>.
data Envelope v :: * -> *

-- | <tt>Enveloped</tt> abstracts over things which have an envelope.
class (InnerSpace (V a), OrderedField (Scalar (V a))) => Enveloped a

-- | Get the envelope of a diagram.
envelope :: Ord (Scalar v) => QDiagram b v m -> Envelope v

-- | Replace the envelope of a diagram.
setEnvelope :: (OrderedField (Scalar v), InnerSpace v, HasLinearMap v, Monoid' m) => Envelope v -> QDiagram b v m -> QDiagram b v m

-- | Use the envelope from some object as the envelope for a diagram, in
--   place of the diagram's default envelope.
withEnvelope :: (HasLinearMap (V a), Enveloped a, Monoid' m) => a -> QDiagram b (V a) m -> QDiagram b (V a) m

-- | <tt>phantom x</tt> produces a "phantom" diagram, which has the same
--   envelope and trace as <tt>x</tt> but produces no output.
phantom :: (Backend b (V a), Enveloped a, Traced a, Monoid' m) => a -> QDiagram b (V a) m

-- | <tt>pad s</tt> "pads" a diagram, expanding its envelope by a factor of
--   <tt>s</tt> (factors between 0 and 1 can be used to shrink the
--   envelope). Note that the envelope will expand with respect to the
--   local origin, so if the origin is not centered the padding may appear
--   "uneven". If this is not desired, the origin can be centered (using,
--   e.g., <tt>centerXY</tt> for 2D diagrams) before applying <tt>pad</tt>.
pad :: (Backend b v, InnerSpace v, OrderedField (Scalar v), Monoid' m) => Scalar v -> QDiagram b v m -> QDiagram b v m

-- | <tt>extrudeEnvelope v d</tt> asymmetrically "extrudes" the envelope of
--   a diagram in the given direction. All parts of the envelope within 90
--   degrees of this direction are modified, offset outwards by the
--   magnitude of the vector.
--   
--   This works by offsetting the envelope distance proportionally to the
--   cosine of the difference in angle, and leaving it unchanged when this
--   factor is negative.
extrudeEnvelope :: (Ord (Scalar v), Num (Scalar v), AdditiveGroup (Scalar v), Floating (Scalar v), HasLinearMap v, InnerSpace v, Monoid' m) => v -> QDiagram b v m -> QDiagram b v m

-- | <tt>intrudeEnvelope v d</tt> asymmetrically "intrudes" the envelope of
--   a diagram away from the given direction. All parts of the envelope
--   within 90 degrees of this direction are modified, offset inwards by
--   the magnitude of the vector.
--   
--   Note that this could create strange inverted envelopes, where <tt>
--   diameter v d &lt; 0 </tt>.
intrudeEnvelope :: (Ord (Scalar v), Num (Scalar v), AdditiveGroup (Scalar v), Floating (Scalar v), HasLinearMap v, InnerSpace v, Monoid' m) => v -> QDiagram b v m -> QDiagram b v m

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

-- | Compute the point on a separating hyperplane in the given direction,
--   or <tt>Nothing</tt> for the empty envelope.
envelopePMay :: Enveloped a => V a -> a -> Maybe (Point (V a))

-- | Compute the point on a separating hyperplane in the given direction.
--   Returns the origin for the empty envelope.
envelopeP :: Enveloped a => V a -> a -> Point (V a)

-- | Compute the diameter of a enveloped object along a particular vector.
--   Returns zero for the empty envelope.
diameter :: Enveloped a => V a -> a -> Scalar (V a)

-- | Compute the "radius" (1/2 the diameter) of an enveloped object along a
--   particular vector.
radius :: Enveloped a => V a -> a -> Scalar (V a)


-- | "Traces", aka embedded raytracers, for finding points on the edge of a
--   diagram. See <a>Diagrams.Core.Trace</a> for internal implementation
--   details.
module Diagrams.Trace

-- | Every diagram comes equipped with a <i>trace</i>. Intuitively, the
--   trace for a diagram is like a raytracer: given a line (represented as
--   a base point and a direction), the trace computes the distance from
--   the base point along the line to the first intersection with the
--   diagram. The distance can be negative if the intersection is in the
--   opposite direction from the base point, or infinite if the ray never
--   intersects the diagram. Note: to obtain the distance to the
--   <i>furthest</i> intersection instead of the <i>closest</i>, just
--   negate the direction vector and then negate the result.
--   
--   Note that the output should actually be interpreted not as an absolute
--   distance, but as a multiplier relative to the input vector. That is,
--   if the input vector is <tt>v</tt> and the returned scalar is
--   <tt>s</tt>, the distance from the base point to the intersection is
--   given by <tt>s * magnitude v</tt>.
data Trace v :: * -> *

-- | <tt>Traced</tt> abstracts over things which have a trace.
class (Ord (Scalar (V a)), VectorSpace (V a)) => Traced a

-- | Get the trace of a diagram.
trace :: (Ord (Scalar v), VectorSpace v, HasLinearMap v) => QDiagram b v m -> Trace v

-- | Replace the trace of a diagram.
setTrace :: (OrderedField (Scalar v), InnerSpace v, HasLinearMap v, Semigroup m) => Trace v -> QDiagram b v m -> QDiagram b v m

-- | Use the trace from some object as the trace for a diagram, in place of
--   the diagram's default trace.
withTrace :: (HasLinearMap (V a), Traced a, OrderedField (Scalar (V a)), InnerSpace (V a), Monoid' m) => a -> QDiagram b (V a) m -> QDiagram b (V a) m

-- | Compute the vector from the given point to the boundary of the given
--   object in the given direction, or <tt>Nothing</tt> if there is no
--   intersection.
traceV :: Traced a => Point (V a) -> V a -> a -> Maybe (V a)

-- | Given a base point and direction, compute the closest point on the
--   boundary of the given object, or <tt>Nothing</tt> if there is no
--   intersection in the given direction.
traceP :: Traced a => Point (V a) -> V a -> a -> Maybe (Point (V a))

-- | Like <a>traceV</a>, but computes a vector to the *furthest* point on
--   the boundary instead of the closest.
maxTraceV :: Traced a => Point (V a) -> V a -> a -> Maybe (V a)

-- | Like <a>traceP</a>, but computes the *furthest* point on the boundary
--   instead of the closest.
maxTraceP :: Traced a => Point (V a) -> V a -> a -> Maybe (Point (V a))

-- | Compute the furthest point on the boundary of a subdiagram, beginning
--   from the location (local origin) of the subdiagram and moving in the
--   direction of the given vector. If there is no such point, the origin
--   is returned; see also <a>boundaryFromMay</a>.
boundaryFrom :: (HasLinearMap v, Ord (Scalar v)) => Subdiagram b v m -> v -> Point v

-- | Compute the furthest point on the boundary of a subdiagram, beginning
--   from the location (local origin) of the subdiagram and moving in the
--   direction of the given vector, or <tt>Nothing</tt> if there is no such
--   point.
boundaryFromMay :: (HasLinearMap v, Ord (Scalar v)) => Subdiagram b v m -> v -> Maybe (Point v)


-- | A <i>cubic spline</i> is a smooth, connected sequence of cubic curves
--   passing through a given sequence of points. This module provides the
--   <a>cubicSpline</a> method, which can be used to create closed or open
--   cubic splines from a list of points. For access to the internals of
--   the spline generation algorithm (including in particular a solver for
--   cyclic tridiagonal systems of linear equations), see
--   <a>Diagrams.CubicSpline.Internal</a>.
module Diagrams.CubicSpline

-- | Construct a spline path-like thing of cubic segments from a list of
--   vertices, with the first vertex as the starting point. The first
--   argument specifies whether the path should be closed.
--   
--   
--   <pre>
--   pts = map p2 [(0,0), (2,3), (5,-2), (-4,1), (0,3)]
--   dot = circle 0.2 # fc blue # lw 0
--   mkPath closed = position (zip pts (repeat dot))
--                &lt;&gt; cubicSpline closed pts # lw 0.05
--   cubicSplineEx = (mkPath False ||| strutX 2 ||| mkPath True)
--                 # centerXY # pad 1.1
--   </pre>
--   
--   For more information, see
--   <a>http://mathworld.wolfram.com/CubicSpline.html</a>.
cubicSpline :: (TrailLike t, Fractional (V t)) => Bool -> [Point (V t)] -> t


-- | Two-dimensional arcs, approximated by cubic bezier curves.
module Diagrams.TwoD.Arc

-- | Given a start angle <tt>s</tt> and an end angle <tt>e</tt>,
--   <tt><a>arc</a> s e</tt> is the path of a radius one arc
--   counterclockwise between the two angles. The origin of the arc is its
--   center.
arc :: (Angle a, TrailLike t, V t ~ R2) => a -> a -> t

-- | Given a radus <tt>r</tt>, a start angle <tt>s</tt> and an end angle
--   <tt>e</tt>, <tt><a>arc'</a> r s e</tt> is the path of a radius
--   <tt>(abs r)</tt> arc between the two angles. If a negative radius is
--   given, the arc will be clockwise, otherwise it will be
--   counterclockwise. The origin of the arc is its center.
arc' :: (Angle a, TrailLike p, V p ~ R2) => Double -> a -> a -> p

-- | Like <a>arc</a> but clockwise.
arcCW :: (Angle a, TrailLike t, V t ~ R2) => a -> a -> t

-- | Given a start angle <tt>s</tt> and an end angle <tt>e</tt>,
--   <tt><a>arcT</a> s e</tt> is the <a>Trail</a> of a radius one arc
--   counterclockwise between the two angles.
arcT :: Angle a => a -> a -> Trail R2

-- | <tt>bezierFromSweep s</tt> constructs a series of <a>Cubic</a>
--   segments that start in the positive y direction and sweep counter
--   clockwise through <tt>s</tt> radians. If <tt>s</tt> is negative, it
--   will start in the negative y direction and sweep clockwise. When
--   <tt>s</tt> is less than 0.0001 the empty list results. If the sweep is
--   greater than tau then it is truncated to tau.
bezierFromSweep :: Rad -> [Segment Closed R2]

-- | Create a circular wedge of the given radius, beginning at the first
--   angle and extending counterclockwise to the second.
wedge :: (Angle a, TrailLike p, V p ~ R2) => Double -> a -> a -> p


-- | Two-dimensional ellipses (and, as a special case, circles).
module Diagrams.TwoD.Ellipse

-- | A circle of radius 1, with center at the origin.
unitCircle :: (TrailLike t, V t ~ R2) => t

-- | A circle of the given radius, centered at the origin. As a path, it
--   begins at (r,0).
circle :: (TrailLike t, V t ~ R2, Transformable t) => Double -> t

-- | <tt>ellipse e</tt> constructs an ellipse with eccentricity <tt>e</tt>
--   by scaling the unit circle in the X direction. The eccentricity must
--   be within the interval [0,1).
ellipse :: (TrailLike t, V t ~ R2, Transformable t) => Double -> t

-- | <tt>ellipseXY x y</tt> creates an axis-aligned ellipse, centered at
--   the origin, with radius <tt>x</tt> along the x-axis and radius
--   <tt>y</tt> along the y-axis.
ellipseXY :: (TrailLike t, V t ~ R2, Transformable t) => Double -> Double -> t


-- | Paths in two dimensions are special since we may stroke them to create
--   a 2D diagram, and (eventually) perform operations such as intersection
--   and union. They also have a trace, whereas paths in higher dimensions
--   do not.
module Diagrams.TwoD.Path

-- | Convert a path into a diagram. The resulting diagram has the names 0,
--   1, ... assigned to each of the path's vertices.
--   
--   See also <a>stroke'</a>, which takes an extra options record allowing
--   its behavior to be customized.
--   
--   Note that a bug in GHC 7.0.1 causes a context stack overflow when
--   inferring the type of <tt>stroke</tt>. The solution is to give a type
--   signature to expressions involving <tt>stroke</tt>, or (recommended)
--   upgrade GHC (the bug is fixed in 7.0.2 onwards).
stroke :: Renderable (Path R2) b => Path R2 -> Diagram b R2

-- | A variant of <a>stroke</a> that takes an extra record of options to
--   customize its behavior. In particular:
--   
--   <ul>
--   <li>Names can be assigned to the path's vertices</li>
--   </ul>
--   
--   <a>StrokeOpts</a> is an instance of <a>Default</a>, so <tt>stroke'
--   <tt>with</tt> { ... }</tt> syntax may be used.
stroke' :: (Renderable (Path R2) b, IsName a) => StrokeOpts a -> Path R2 -> Diagram b R2

-- | A composition of <a>stroke</a> and <a>pathFromTrail</a> for
--   conveniently converting a trail directly into a diagram.
--   
--   Note that a bug in GHC 7.0.1 causes a context stack overflow when
--   inferring the type of <a>stroke</a> and hence of <tt>strokeT</tt> as
--   well. The solution is to give a type signature to expressions
--   involving <tt>strokeT</tt>, or (recommended) upgrade GHC (the bug is
--   fixed in 7.0.2 onwards).
strokeT :: Renderable (Path R2) b => Trail R2 -> Diagram b R2

-- | A composition of <a>stroke'</a> and <a>pathFromTrail</a> for
--   conveniently converting a trail directly into a diagram.
strokeT' :: (Renderable (Path R2) b, IsName a) => StrokeOpts a -> Trail R2 -> Diagram b R2

-- | A composition of <a>strokeT</a> and <a>wrapLine</a> for conveniently
--   converting a line directly into a diagram.
strokeLine :: Renderable (Path R2) b => Trail' Line R2 -> Diagram b R2

-- | A composition of <a>strokeT</a> and <a>wrapLoop</a> for conveniently
--   converting a loop directly into a diagram.
strokeLoop :: Renderable (Path R2) b => Trail' Loop R2 -> Diagram b R2

-- | A convenience function for converting a <tt>Located Trail</tt>
--   directly into a diagram; <tt>strokeLocT = stroke . trailLike</tt>.
strokeLocT :: Renderable (Path R2) b => Located (Trail R2) -> Diagram b R2

-- | A convenience function for converting a <tt>Located</tt> line directly
--   into a diagram; <tt>strokeLocLine = stroke . trailLike . mapLoc
--   wrapLine</tt>.
strokeLocLine :: Renderable (Path R2) b => Located (Trail' Line R2) -> Diagram b R2

-- | A convenience function for converting a <tt>Located</tt> loop directly
--   into a diagram; <tt>strokeLocLoop = stroke . trailLike . mapLoc
--   wrapLoop</tt>.
strokeLocLoop :: Renderable (Path R2) b => Located (Trail' Loop R2) -> Diagram b R2

-- | Enumeration of algorithms or "rules" for determining which points lie
--   in the interior of a (possibly self-intersecting) closed path.
data FillRule

-- | Interior points are those with a nonzero <i>winding</i> <i>number</i>.
--   See <a>http://en.wikipedia.org/wiki/Nonzero-rule</a>.
Winding :: FillRule

-- | Interior points are those where a ray extended infinitely in a
--   particular direction crosses the path an odd number of times. See
--   <a>http://en.wikipedia.org/wiki/Even-odd_rule</a>.
EvenOdd :: FillRule
newtype FillRuleA
FillRuleA :: (Last FillRule) -> FillRuleA

-- | Extract the fill rule from a <a>FillRuleA</a> attribute.
getFillRule :: FillRuleA -> FillRule

-- | Specify the fill rule that should be used for determining which points
--   are inside a path.
fillRule :: HasStyle a => FillRule -> a -> a

-- | A record of options that control how a path is stroked.
--   <tt>StrokeOpts</tt> is an instance of <a>Default</a>, so a
--   <tt>StrokeOpts</tt> records can be created using <tt><tt>with</tt> {
--   ... }</tt> notation.
data StrokeOpts a
StrokeOpts :: [[a]] -> FillRule -> StrokeOpts a

-- | Atomic names that should be assigned to the vertices of the path so
--   that they can be referenced later. If there are not enough names, the
--   extra vertices are not assigned names; if there are too many, the
--   extra names are ignored. Note that this is a <i>list of lists</i> of
--   names, since paths can consist of multiple trails. The first list of
--   names are assigned to the vertices of the first trail, the second list
--   to the second trail, and so on.
--   
--   The default value is the empty list.
vertexNames :: StrokeOpts a -> [[a]]

-- | The fill rule used for determining which points are inside the path.
--   The default is <a>Winding</a>. NOTE: for now, this only affects the
--   resulting diagram's <a>Query</a>, <i>not</i> how it will be drawn! To
--   set the fill rule determining how it is to be drawn, use the
--   <a>fillRule</a> function.
queryFillRule :: StrokeOpts a -> FillRule

-- | Test whether the given point is inside the given (closed) path, by
--   testing whether the point's <i>winding number</i> is nonzero. Note
--   that <tt>False</tt> is <i>always</i> returned for <i>open</i> paths,
--   regardless of the winding number.
isInsideWinding :: P2 -> Path R2 -> Bool

-- | Test whether the given point is inside the given (closed) path, by
--   testing whether a ray extending from the point in the positive x
--   direction crosses the path an even (outside) or odd (inside) number of
--   times. Note that <tt>False</tt> is <i>always</i> returned for
--   <i>open</i> paths, regardless of the number of crossings.
isInsideEvenOdd :: P2 -> Path R2 -> Bool

-- | <tt>Clip</tt> tracks the accumulated clipping paths applied to a
--   diagram. Note that the semigroup structure on <tt>Clip</tt> is list
--   concatenation, so applying multiple clipping paths is sensible. The
--   clipping region is the intersection of all the applied clipping paths.
newtype Clip
Clip :: [Path R2] -> Clip
getClip :: Clip -> [Path R2]

-- | Clip a diagram by the given path:
--   
--   <ul>
--   <li>Only the parts of the diagram which lie in the interior of the
--   path will be drawn.</li>
--   <li>The envelope of the diagram is unaffected.</li>
--   </ul>
clipBy :: (HasStyle a, V a ~ R2) => Path R2 -> a -> a
instance Typeable FillRuleA
instance Typeable Clip
instance Eq FillRule
instance Semigroup FillRuleA
instance Semigroup Clip
instance Transformable Clip
instance AttributeClass Clip
instance AttributeClass FillRuleA
instance Default (StrokeOpts a)
instance Renderable (Path R2) b => TrailLike (QDiagram b R2 Any)
instance Traced (Path R2)
instance Traced (Trail R2)


-- | This module defines a general API for creating various types of
--   polygons.
module Diagrams.TwoD.Polygons

-- | Method used to determine the vertices of a polygon.
data PolyType

-- | A "polar" polygon.
--   
--   <ul>
--   <li>The first argument is a list of <i>central</i> <i>angles</i> from
--   each vertex to the next.</li>
--   <li>The second argument is a list of <i>radii</i> from the origin to
--   each successive vertex.</li>
--   </ul>
--   
--   To construct an <i>n</i>-gon, use a list of <i>n-1</i> angles and
--   <i>n</i> radii. Extra angles or radii are ignored.
--   
--   Cyclic polygons (with all vertices lying on a circle) can be
--   constructed using a second argument of <tt>(repeat r)</tt>.
PolyPolar :: [a] -> [Double] -> PolyType

-- | A polygon determined by the distance between successive vertices and
--   the angles formed by each three successive vertices. In other words, a
--   polygon specified by "turtle graphics": go straight ahead x1 units;
--   turn by angle a1; go straght ahead x2 units; turn by angle a2; etc.
--   The polygon will be centered at the <i>centroid</i> of its vertices.
--   
--   <ul>
--   <li>The first argument is a list of <i>vertex</i> <i>angles</i>,
--   giving the angle at each vertex from the previous vertex to the next.
--   The first angle in the list is the angle at the <i>second</i> vertex;
--   the first edge always starts out heading in the positive y direction
--   from the first vertex.</li>
--   <li>The second argument is a list of distances between successive
--   vertices.</li>
--   </ul>
--   
--   To construct an <i>n</i>-gon, use a list of <i>n-2</i> angles and
--   <i>n-1</i> edge lengths. Extra angles or lengths are ignored.
PolySides :: [a] -> [Double] -> PolyType

-- | A regular polygon with the given number of sides (first argument) and
--   the given radius (second argument).
PolyRegular :: Int -> Double -> PolyType

-- | Determine how a polygon should be oriented.
data PolyOrientation

-- | No special orientation; the first vertex will be at (1,0). This is the
--   default.
NoOrient :: PolyOrientation

-- | Orient <i>horizontally</i>, so the bottommost edge is parallel to the
--   x-axis.
OrientH :: PolyOrientation

-- | Orient <i>vertically</i>, so the leftmost edge is parallel to the
--   y-axis.
OrientV :: PolyOrientation

-- | Orient so some edge is <i>facing</i> <i>in</i> <i>the</i>
--   <i>direction</i> <i>of</i>, that is, perpendicular to, the given
--   vector.
OrientTo :: R2 -> PolyOrientation

-- | Options for specifying a polygon.
data PolygonOpts
PolygonOpts :: PolyType -> PolyOrientation -> P2 -> PolygonOpts

-- | Specification for the polygon's vertices.
polyType :: PolygonOpts -> PolyType

-- | Should a rotation be applied to the polygon in order to orient it in a
--   particular way?
polyOrient :: PolygonOpts -> PolyOrientation

-- | Should a translation be applied to the polygon in order to place the
--   center at a particular location?
polyCenter :: PolygonOpts -> P2

-- | Generate the polygon described by the given options.
polygon :: (TrailLike t, V t ~ R2) => PolygonOpts -> t

-- | Generate a polygon. See <a>PolygonOpts</a> for more information.
polyTrail :: PolygonOpts -> Located (Trail R2)

-- | Generate the located trail of a polygon specified by polar data
--   (central angles and radii). See <a>PolyPolar</a>.
polyPolarTrail :: Angle a => [a] -> [Double] -> Located (Trail R2)

-- | Generate the vertices of a polygon specified by side length and
--   angles, and a starting point for the trail such that the origin is at
--   the centroid of the vertices. See <a>PolySides</a>.
polySidesTrail :: Angle a => [a] -> [Double] -> Located (Trail R2)

-- | Generate the vertices of a regular polygon. See <a>PolyRegular</a>.
polyRegularTrail :: Int -> Double -> Located (Trail R2)

-- | Generate a transformation to orient a trail. <tt>orient v t</tt>
--   generates the smallest rotation such that one of the segments adjacent
--   to the vertex furthest in the direction of <tt>v</tt> is perpendicular
--   to <tt>v</tt>.
orient :: R2 -> Located (Trail R2) -> T2

-- | Options for creating "star" polygons, where the edges connect possibly
--   non-adjacent vertices.
data StarOpts

-- | Specify the order in which the vertices should be connected by a
--   function that maps each vertex index to the index of the vertex that
--   should come next. Indexing of vertices begins at 0.
StarFun :: (Int -> Int) -> StarOpts

-- | Specify a star polygon by a "skip". A skip of 1 indicates a normal
--   polygon, where edges go between successive vertices. A skip of 2 means
--   that edges will connect every second vertex, skipping one in between.
--   Generally, a skip of <i>n</i> means that edges will connect every
--   <i>n</i>th vertex.
StarSkip :: Int -> StarOpts

-- | Create a generalized <i>star</i> <i>polygon</i>. The <a>StarOpts</a>
--   are used to determine in which order the given vertices should be
--   connected. The intention is that the second argument of type
--   <tt>[P2]</tt> could be generated by a call to <a>polygon</a>,
--   <tt>regPoly</tt>, or the like, since a list of vertices is
--   <a>TrailLike</a>. But of course the list can be generated any way you
--   like. A <tt><a>Path</a> <a>R2</a></tt> is returned (instead of any
--   <a>TrailLike</a>) because the resulting path may have more than one
--   component, for example if the vertices are to be connected in several
--   disjoint cycles.
star :: StarOpts -> [P2] -> Path R2

-- | Pieces of a function graph can either be cycles or "hairs".
data GraphPart a
Cycle :: [a] -> GraphPart a
Hair :: [a] -> GraphPart a

-- | <tt>orbits f n</tt> computes the graph of <tt>f</tt> on the integers
--   mod <tt>n</tt>.
orbits :: (Int -> Int) -> Int -> [GraphPart Int]

-- | Generate a function graph from the given function and labels.
mkGraph :: (Int -> Int) -> [a] -> [GraphPart a]
instance Eq PolyOrientation
instance Ord PolyOrientation
instance Show PolyOrientation
instance Read PolyOrientation
instance Show a => Show (GraphPart a)
instance Functor GraphPart
instance Default PolygonOpts


-- | Various two-dimensional shapes.
module Diagrams.TwoD.Shapes

-- | Create a centered horizontal (L-R) line of the given length.
--   
--   
--   <pre>
--   hruleEx = vcat' with {sep = 0.2} (map hrule [1..5])
--           # centerXY # pad 1.1
--   </pre>
hrule :: (TrailLike t, V t ~ R2) => Double -> t

-- | Create a centered vertical (T-B) line of the given length.
--   
--   
--   <pre>
--   vruleEx = hcat' with {sep = 0.2} (map vrule [1, 1.2 .. 2])
--           # centerXY # pad 1.1
--   </pre>
vrule :: (TrailLike t, V t ~ R2) => Double -> t

-- | Create a regular polygon. The first argument is the number of sides,
--   and the second is the <i>length</i> of the sides. (Compare to the
--   <a>polygon</a> function with a <a>PolyRegular</a> option, which
--   produces polygons of a given <i>radius</i>).
--   
--   The polygon will be oriented with one edge parallel to the x-axis.
regPoly :: (TrailLike t, V t ~ R2) => Int -> Double -> t

-- | An equilateral triangle, with sides of the given length and base
--   parallel to the x-axis.
--   
triangle :: (TrailLike t, V t ~ R2) => Double -> t

-- | A synonym for <a>triangle</a>, provided for backwards compatibility.
eqTriangle :: (TrailLike t, V t ~ R2) => Double -> t

-- | A square with its center at the origin and sides of the given length,
--   oriented parallel to the axes.
--   
square :: (TrailLike t, Transformable t, V t ~ R2) => Double -> t

-- | A regular pentagon, with sides of the given length and base parallel
--   to the x-axis.
--   
pentagon :: (TrailLike t, V t ~ R2) => Double -> t

-- | A regular hexagon, with sides of the given length and base parallel to
--   the x-axis.
--   
hexagon :: (TrailLike t, V t ~ R2) => Double -> t

-- | A regular septagon, with sides of the given length and base parallel
--   to the x-axis.
--   
septagon :: (TrailLike t, V t ~ R2) => Double -> t

-- | A regular octagon, with sides of the given length and base parallel to
--   the x-axis.
--   
octagon :: (TrailLike t, V t ~ R2) => Double -> t

-- | A regular nonagon, with sides of the given length and base parallel to
--   the x-axis.
--   
nonagon :: (TrailLike t, V t ~ R2) => Double -> t

-- | A regular decagon, with sides of the given length and base parallel to
--   the x-axis.
--   
decagon :: (TrailLike t, V t ~ R2) => Double -> t

-- | A regular hendecagon, with sides of the given length and base parallel
--   to the x-axis.
--   
hendecagon :: (TrailLike t, V t ~ R2) => Double -> t

-- | A regular dodecagon, with sides of the given length and base parallel
--   to the x-axis.
--   
dodecagon :: (TrailLike t, V t ~ R2) => Double -> t

-- | A square with its center at the origin and sides of length 1, oriented
--   parallel to the axes.
--   
unitSquare :: (TrailLike t, V t ~ R2) => t

-- | <tt>rect w h</tt> is an axis-aligned rectangle of width <tt>w</tt> and
--   height <tt>h</tt>, centered at the origin.
--   
rect :: (TrailLike t, Transformable t, V t ~ R2) => Double -> Double -> t

-- | <tt>roundedRect w h r</tt> generates a closed trail, or closed path
--   centered at the origin, of an axis-aligned rectangle with width
--   <tt>w</tt>, height <tt>h</tt>, and circular rounded corners of radius
--   <tt>r</tt>. If <tt>r</tt> is negative the corner will be cut out in a
--   reverse arc. If the size of <tt>r</tt> is larger than half the smaller
--   dimension of <tt>w</tt> and <tt>h</tt>, then it will be reduced to fit
--   in that range, to prevent the corners from overlapping. The trail or
--   path begins with the right edge and proceeds counterclockwise. If you
--   need to specify a different radius for each corner individually, use
--   <a>roundedRect'</a> instead.
--   
--   
--   <pre>
--   roundedRectEx = pad 1.1 . centerXY $ hcat' with { sep = 0.2 }
--     [ roundedRect  0.5 0.4 0.1
--     , roundedRect  0.5 0.4 (-0.1)
--     , roundedRect' 0.7 0.4 with { radiusTL = 0.2
--                                 , radiusTR = -0.2
--                                 , radiusBR = 0.1 }
--     ]
--   </pre>
roundedRect :: (TrailLike t, V t ~ R2) => Double -> Double -> Double -> t
data RoundedRectOpts
RoundedRectOpts :: Double -> Double -> Double -> Double -> RoundedRectOpts
radiusTL :: RoundedRectOpts -> Double
radiusTR :: RoundedRectOpts -> Double
radiusBL :: RoundedRectOpts -> Double
radiusBR :: RoundedRectOpts -> Double

-- | <tt>roundedRect'</tt> works like <tt>roundedRect</tt> but allows you
--   to set the radius of each corner indivually, using
--   <tt>RoundedRectOpts</tt>. The default corner radius is 0. Each radius
--   can also be negative, which results in the curves being reversed to be
--   inward instead of outward.
roundedRect' :: (TrailLike t, V t ~ R2) => Double -> Double -> RoundedRectOpts -> t
instance Default RoundedRectOpts


-- | Importing external images into diagrams.
module Diagrams.TwoD.Image

-- | An external image primitive, representing an image the backend should
--   import from another file when rendering.
data Image
Image :: FilePath -> SizeSpec2D -> T2 -> Image
imgFile :: Image -> FilePath
imgSize :: Image -> SizeSpec2D
imgTransf :: Image -> T2

-- | Take an external image from the specified file and turn it into a
--   diagram with the specified width and height, centered at the origin.
--   Note that the image's aspect ratio will be preserved; if the specified
--   width and height have a different ratio than the image's aspect ratio,
--   there will be extra space in one dimension.
image :: Renderable Image b => FilePath -> Double -> Double -> Diagram b R2
instance Renderable Image NullBackend
instance HasOrigin Image
instance IsPrim Image
instance Transformable Image


-- | Compute offsets to segments in two dimensions.
module Diagrams.TwoD.Offset

-- | Compute the offset of a segment. Given a segment compute the offset
--   curve that is a fixed distance from the original curve. For linear
--   segments nothing special happens, the same linear segment is returned
--   with a point that is offset by a perpendicular vector of the given
--   offset length.
--   
--   Cubic segments require a search for a subdivision of cubic segments
--   that gives an approximation of the offset within the given epsilon
--   tolerance. We must do this because the offset of a cubic is not a
--   cubic itself (the degree of the curve increases). Cubics do, however,
--   approach constant curvature as we subdivide. In light of this we scale
--   the handles of the offset cubic segment in proportion to the radius of
--   curvature difference between the original subsegment and the offset
--   which will have a radius increased by the offset parameter.
--   
--   In the following example the blue lines are the original segments and
--   the alternating green and red lines are the resulting offset trail
--   segments.
--   
--   
--   Note that when the original curve has a cusp, the offset curve forms a
--   radius around the cusp, and when there is a loop in the original
--   curve, there can be two cusps in the offset curve.
offsetSegment :: Double -> Double -> Segment Closed R2 -> (Point R2, Trail R2)


-- | Alignment combinators specialized for two dimensions. See
--   <a>Diagrams.Align</a> for more general alignment combinators.
--   
--   The basic idea is that alignment is achieved by moving diagrams' local
--   origins relative to their envelopes. For example, to align several
--   diagrams along their tops, we first move their local origins to the
--   upper edge of their envelopes (using e.g. <tt>map
--   <tt>alignTop</tt></tt>), and then put them together with their local
--   origins along a horizontal line (using e.g. <tt>hcat</tt> from
--   <a>Diagrams.TwoD.Combinators</a>).
module Diagrams.TwoD.Align

-- | Align along the left edge, i.e. translate the diagram in a horizontal
--   direction so that the local origin is on the left edge of the
--   envelope.
alignL :: (Alignable a, V a ~ R2) => a -> a

-- | Align along the right edge.
alignR :: (Alignable a, V a ~ R2) => a -> a

-- | Align along the top edge.
alignT :: (Alignable a, V a ~ R2) => a -> a

-- | Align along the bottom edge.
alignB :: (Alignable a, V a ~ R2) => a -> a
alignTL :: (Alignable a, V a ~ R2) => a -> a
alignTR :: (Alignable a, V a ~ R2) => a -> a
alignBL :: (Alignable a, V a ~ R2) => a -> a
alignBR :: (Alignable a, V a ~ R2) => a -> a

-- | <tt>alignX</tt> moves the local origin horizontally as follows:
--   
--   <ul>
--   <li><tt>alignX (-1)</tt> moves the local origin to the left edge of
--   the envelope;</li>
--   <li><tt>align 1</tt> moves the local origin to the right edge;</li>
--   <li>any other argument interpolates linearly between these. For
--   example, <tt>alignX 0</tt> centers, <tt>alignX 2</tt> moves the origin
--   one "radius" to the right of the right edge, and so on.</li>
--   </ul>
alignX :: (Alignable a, V a ~ R2) => Double -> a -> a

-- | Like <a>alignX</a>, but moving the local origin vertically, with an
--   argument of <tt>1</tt> corresponding to the top edge and <tt>(-1)</tt>
--   corresponding to the bottom edge.
alignY :: (Alignable a, V a ~ R2) => Double -> a -> a

-- | Center the local origin along the X-axis.
centerX :: (Alignable a, V a ~ R2) => a -> a

-- | Center the local origin along the Y-axis.
centerY :: (Alignable a, V a ~ R2) => a -> a

-- | Center along both the X- and Y-axes.
centerXY :: (Alignable a, V a ~ R2) => a -> a


-- | A few utilities and class instances for <a>Active</a> (from the
--   <tt>active</tt> package). In particular, this module defines
--   
--   <ul>
--   <li>An instance of <a>V</a> for <a>Active</a>: <tt><a>V</a>
--   (<a>Active</a> a) = <a>V</a> a</tt></li>
--   <li><a>HasOrigin</a>, <a>Transformable</a>, and <a>HasStyle</a>
--   instances for <a>Active</a> which all work pointwise.</li>
--   <li>A <a>TrailLike</a> instance for <tt><a>Active</a> p</tt> where
--   <tt>p</tt> is also <a>TrailLike</a>, which simply lifts a pathlike
--   thing to a constant active value.</li>
--   <li>A <a>Juxtaposable</a> instance for <tt><a>Active</a> a</tt> where
--   <tt>a</tt> is also <a>Juxtaposable</a>. An active value can be
--   juxtaposed against another by doing the juxtaposition pointwise over
--   time. The era of <tt>juxtapose v a1 a2</tt> will be the same as the
--   era of <tt>a2</tt>, unless <tt>a2</tt> is constant, in which case it
--   will be the era of <tt>a1</tt>. (Note that <tt>juxtapose v a1 a2</tt>
--   and <tt>liftA2 (juxtapose v) a1 a2</tt> therefore have different
--   semantics: the second is an active value whose era is the
--   <i>combination</i> of the eras of <tt>a1</tt> and <tt>a2</tt>).</li>
--   <li>An <a>Alignable</a> instance for <tt><a>Active</a> a</tt> where
--   <tt>a</tt> is also <a>Alignable</a>; the active value is aligned
--   pointwise over time.</li>
--   </ul>
module Diagrams.Animation.Active
instance Alignable a => Alignable (Active a)
instance Juxtaposable a => Juxtaposable (Active a)
instance TrailLike t => TrailLike (Active t)
instance HasStyle a => HasStyle (Active a)
instance Transformable a => Transformable (Active a)
instance HasOrigin a => HasOrigin (Active a)


-- | An animation is a time-varying diagram, together with start and end
--   times. Most of the tools for working with animations can actually be
--   found in the <tt>active</tt> package, which defines the <a>Active</a>
--   type.
--   
--   XXX more documentation and examples should go here
module Diagrams.Animation

-- | A value of type <tt>QAnimation b v m</tt> is an animation (a
--   time-varying diagram with start and end times) that can be rendered by
--   backspace <tt>b</tt>, with vector space <tt>v</tt> and monoidal
--   annotations of type <tt>m</tt>.
type QAnimation b v m = Active (QDiagram b v m)

-- | A value of type <tt>Animation b v</tt> is an animation (a time-varying
--   diagram with start and end times) in vector space <tt>v</tt> that can
--   be rendered by backspace <tt>b</tt>.
--   
--   Note that <tt>Animation</tt> is actually a synonym for
--   <tt>QAnimation</tt> where the type of the monoidal annotations has
--   been fixed to <a>Any</a> (the default).
type Animation b v = QAnimation b v Any

-- | Automatically assign fixed a envelope to the entirety of an animation
--   by sampling the envelope at a number of points in time and taking the
--   union of all the sampled envelopes to form the "hull". This hull is
--   then used uniformly throughout the animation.
--   
--   This is useful when you have an animation that grows and shrinks in
--   size or shape over time, but you want it to take up a fixed amount of
--   space, <i>e.g.</i> so that the final rendered movie does not zoom in
--   and out, or so that it occupies a fixed location with respect to
--   another animation, when combining animations with something like
--   <tt>|||</tt>.
--   
--   By default, 30 samples per time unit are used; to adjust this number
--   see <a>animEnvelope'</a>.
--   
--   See also <a>animRect</a> for help constructing a background to go
--   behind an animation.
animEnvelope :: (Backend b v, OrderedField (Scalar v), InnerSpace v, Monoid' m) => QAnimation b v m -> QAnimation b v m

-- | Like <a>animEnvelope</a>, but with an adjustible sample rate. The
--   first parameter is the number of samples per time unit to use. Lower
--   rates will be faster but less accurate; higher rates are more accurate
--   but slower.
animEnvelope' :: (Backend b v, OrderedField (Scalar v), InnerSpace v, Monoid' m) => Rational -> QAnimation b v m -> QAnimation b v m

-- | <tt>animRect</tt> works similarly to <a>animEnvelope</a> for 2D
--   diagrams, but instead of adjusting the envelope, simply returns the
--   smallest bounding rectangle which encloses the entire animation.
--   Useful for <i>e.g.</i> creating a background to go behind an
--   animation.
--   
--   Uses 30 samples per time unit by default; to adjust this number see
--   <a>animRect'</a>.
animRect :: (TrailLike t, Enveloped t, Transformable t, Monoid t, V t ~ R2) => QAnimation b R2 m -> t

-- | Like <a>animRect</a>, but with an adjustible sample rate. The first
--   parameter is the number of samples per time unit to use. Lower rates
--   will be faster but less accurate; higher rates are more accurate but
--   slower.
animRect' :: (TrailLike t, Enveloped t, Transformable t, Monoid t, V t ~ R2) => Rational -> QAnimation b R2 m -> t


-- | Diagrams may have <i>attributes</i> which affect the way they are
--   rendered. This module defines some common attributes; particular
--   backends may also define more backend-specific attributes.
--   
--   Every attribute type must have a <i>semigroup</i> structure, that is,
--   an associative binary operation for combining two attributes into one.
--   Unless otherwise noted, all the attributes defined here use the
--   <a>Last</a> structure, that is, combining two attributes simply keeps
--   the second one and throws away the first. This means that child
--   attributes always override parent attributes.
module Diagrams.Attributes

-- | The <a>Color</a> type class encompasses color representations which
--   can be used by the Diagrams library. Instances are provided for both
--   the <a>Colour</a> and <a>AlphaColour</a> types from the
--   <a>Data.Colour</a> library.
class Color c
toAlphaColour :: Color c => c -> AlphaColour Double

-- | An existential wrapper for instances of the <a>Color</a> class.
data SomeColor
SomeColor :: c -> SomeColor

-- | The color with which lines (strokes) are drawn. Note that child colors
--   always override parent colors; that is, <tt><a>lineColor</a> c1 .
--   <a>lineColor</a> c2 $ d</tt> is equivalent to <tt><a>lineColor</a> c2
--   $ d</tt>. More precisely, the semigroup structure on line color
--   attributes is that of <a>Last</a>.
data LineColor
getLineColor :: LineColor -> SomeColor

-- | Set the line (stroke) color. This function is polymorphic in the color
--   type (so it can be used with either <a>Colour</a> or
--   <a>AlphaColour</a>), but this can sometimes create problems for type
--   inference, so the <a>lc</a> and <a>lcA</a> variants are provided with
--   more concrete types.
lineColor :: (Color c, HasStyle a) => c -> a -> a

-- | Apply a <a>lineColor</a> attribute.
lineColorA :: HasStyle a => LineColor -> a -> a

-- | A synonym for <a>lineColor</a>, specialized to <tt><a>Colour</a>
--   Double</tt> (i.e. opaque colors).
lc :: HasStyle a => Colour Double -> a -> a

-- | A synonym for <a>lineColor</a>, specialized to <tt><a>AlphaColour</a>
--   Double</tt> (i.e. colors with transparency).
lcA :: HasStyle a => AlphaColour Double -> a -> a

-- | The color with which shapes are filled. Note that child colors always
--   override parent colors; that is, <tt><a>fillColor</a> c1 .
--   <a>fillColor</a> c2 $ d</tt> is equivalent to <tt><a>lineColor</a> c2
--   $ d</tt>. More precisely, the semigroup structure on fill color
--   attributes is that of <a>Last</a>.
data FillColor
getFillColor :: FillColor -> SomeColor

-- | Set a "recommended" fill color, to be used only if no explicit calls
--   to <a>fillColor</a> (or <a>fc</a>, or <a>fcA</a>) are used.
recommendFillColor :: (Color c, HasStyle a) => c -> a -> a

-- | Set the fill color. This function is polymorphic in the color type (so
--   it can be used with either <a>Colour</a> or <a>AlphaColour</a>), but
--   this can sometimes create problems for type inference, so the
--   <a>fc</a> and <a>fcA</a> variants are provided with more concrete
--   types.
fillColor :: (Color c, HasStyle a) => c -> a -> a

-- | A synonym for <a>fillColor</a>, specialized to <tt><a>Colour</a>
--   Double</tt> (i.e. opaque colors).
fc :: HasStyle a => Colour Double -> a -> a

-- | A synonym for <a>fillColor</a>, specialized to <tt><a>AlphaColour</a>
--   Double</tt> (i.e. colors with transparency).
fcA :: HasStyle a => AlphaColour Double -> a -> a

-- | Although the individual colors in a diagram can have transparency, the
--   opacity/transparency of a diagram as a whole can be specified with the
--   <tt>Opacity</tt> attribute. The opacity is a value between 1
--   (completely opaque, the default) and 0 (completely transparent).
--   Opacity is multiplicative, that is, <tt><a>opacity</a> o1 .
--   <a>opacity</a> o2 === <a>opacity</a> (o1 * o2)</tt>. In other words,
--   for example, <tt>opacity 0.8</tt> means "decrease this diagram's
--   opacity to 80% of its previous opacity".
data Opacity
getOpacity :: Opacity -> Double

-- | Multiply the opacity (see <a>Opacity</a>) by the given value. For
--   example, <tt>opacity 0.8</tt> means "decrease this diagram's opacity
--   to 80% of its previous opacity".
opacity :: HasStyle a => Double -> a -> a

-- | Convert to an RGB space while preserving the alpha channel.
toRGBAUsingSpace :: Color c => RGBSpace Double -> c -> (Double, Double, Double, Double)

-- | Convert to sRGBA.
colorToSRGBA :: Color c => c -> (Double, Double, Double, Double)

-- | Convert to sRGBA.

-- | <i>Deprecated: Renamed to colorToSRGBA. </i>
colorToRGBA :: Color c => c -> (Double, Double, Double, Double)

-- | The width of lines. By default, the line width is measured with
--   respect to the <i>final</i> coordinate system of a rendered diagram,
--   as opposed to the local coordinate systems in effect at the time the
--   line width was set for various subdiagrams. This is so that it is easy
--   to combine a variety of shapes (some created by scaling) and have them
--   all drawn using a consistent line width. However, sometimes it is
--   desirable for scaling to affect line width; the <a>freeze</a>
--   operation is provided for this purpose. The line width of frozen
--   diagrams is affected by transformations.
--   
--   Line widths specified on child nodes always override line widths
--   specified at parent nodes.
data LineWidth
getLineWidth :: LineWidth -> Double

-- | Set the line (stroke) width.
lineWidth :: HasStyle a => Double -> a -> a

-- | Apply a <a>LineWidth</a> attribute.
lineWidthA :: HasStyle a => LineWidth -> a -> a

-- | A convenient synonym for <a>lineWidth</a>.
lw :: HasStyle a => Double -> a -> a

-- | What sort of shape should be placed at the endpoints of lines?
data LineCap

-- | Lines end precisely at their endpoints.
LineCapButt :: LineCap

-- | Lines are capped with semicircles centered on endpoints.
LineCapRound :: LineCap

-- | Lines are capped with a squares centered on endpoints.
LineCapSquare :: LineCap
data LineCapA
getLineCap :: LineCapA -> LineCap

-- | Set the line end cap attribute.
lineCap :: HasStyle a => LineCap -> a -> a

-- | How should the join points between line segments be drawn?
data LineJoin

-- | Use a "miter" shape (whatever that is).
LineJoinMiter :: LineJoin

-- | Use rounded join points.
LineJoinRound :: LineJoin

-- | Use a "bevel" shape (whatever that is). Are these... carpentry terms?
LineJoinBevel :: LineJoin
data LineJoinA
getLineJoin :: LineJoinA -> LineJoin

-- | Set the segment join style.
lineJoin :: HasStyle a => LineJoin -> a -> a

-- | Miter limit attribute affecting the <a>LineJoinMiter</a> joins. For
--   some backends this value may have additional effects.
newtype LineMiterLimit
LineMiterLimit :: (Last Double) -> LineMiterLimit
getLineMiterLimit :: LineMiterLimit -> Double

-- | Set the miter limit for joins with <a>LineJoinMiter</a>.
lineMiterLimit :: HasStyle a => Double -> a -> a

-- | Apply a <a>LineMiterLimit</a> attribute.
lineMiterLimitA :: HasStyle a => LineMiterLimit -> a -> a

-- | Create lines that are dashing... er, dashed.
data Dashing
Dashing :: [Double] -> Double -> Dashing
data DashingA
getDashing :: DashingA -> Dashing

-- | Set the line dashing style.
dashing :: HasStyle a => [Double] -> Double -> a -> a
instance Typeable SomeColor
instance Typeable LineColor
instance Typeable FillColor
instance Typeable Opacity
instance Typeable LineWidth
instance Typeable LineCap
instance Typeable LineCapA
instance Typeable LineJoin
instance Typeable LineJoinA
instance Typeable LineMiterLimit
instance Typeable Dashing
instance Typeable DashingA
instance Semigroup LineColor
instance Semigroup FillColor
instance Semigroup Opacity
instance Semigroup LineWidth
instance Eq LineCap
instance Show LineCap
instance Semigroup LineCapA
instance Eq LineCapA
instance Eq LineJoin
instance Show LineJoin
instance Semigroup LineJoinA
instance Eq LineJoinA
instance Semigroup LineMiterLimit
instance Eq Dashing
instance Semigroup DashingA
instance Eq DashingA
instance AttributeClass DashingA
instance Default LineMiterLimit
instance AttributeClass LineMiterLimit
instance Default LineJoin
instance AttributeClass LineJoinA
instance Default LineCap
instance AttributeClass LineCapA
instance Default LineWidth
instance AttributeClass LineWidth
instance AttributeClass Opacity
instance Color FillColor
instance Color LineColor
instance Color SomeColor
instance (Floating a, Real a) => Color (AlphaColour a)
instance (Floating a, Real a) => Color (Colour a)
instance AttributeClass FillColor
instance Default LineColor
instance AttributeClass LineColor


-- | Diagram combinators specialized to two dimensions. For more general
--   combinators, see <a>Diagrams.Combinators</a>.
module Diagrams.TwoD.Combinators

-- | Place two diagrams (or other objects) vertically adjacent to one
--   another, with the first diagram above the second. Since Haskell
--   ignores whitespace in expressions, one can thus write
--   
--   <pre>
--    c
--   ===
--    d
--   </pre>
--   
--   to place <tt>c</tt> above <tt>d</tt>. The local origin of the
--   resulting combined diagram is the same as the local origin of the
--   first. <tt>(===)</tt> is associative and has <a>mempty</a> as an
--   identity. See the documentation of <a>beside</a> for more information.
(===) :: (Juxtaposable a, V a ~ R2, Semigroup a) => a -> a -> a

-- | Place two diagrams (or other juxtaposable objects) horizontally
--   adjacent to one another, with the first diagram to the left of the
--   second. The local origin of the resulting combined diagram is the same
--   as the local origin of the first. <tt>(===)</tt> is associative and
--   has <a>mempty</a> as an identity. See the documentation of
--   <a>beside</a> for more information.
(|||) :: (Juxtaposable a, V a ~ R2, Semigroup a) => a -> a -> a

-- | Place two diagrams (or other juxtaposable objects) adjacent to one
--   another, with the second diagram placed along a line at angle
--   <tt>th</tt> from the first. The local origin of the resulting combined
--   diagram is the same as the local origin of the first. See the
--   documentation of <a>beside</a> for more information.
atAngle :: (Juxtaposable a, V a ~ R2, Semigroup a, Angle b) => b -> a -> a -> a

-- | Lay out a list of juxtaposable objects in a row from left to right, so
--   that their local origins lie along a single horizontal line, with
--   successive envelopes tangent to one another.
--   
--   <ul>
--   <li>For more control over the spacing, see <a>hcat'</a>.</li>
--   <li>To align the diagrams vertically (or otherwise), use alignment
--   combinators (such as <a>alignT</a> or <a>alignB</a>) from
--   <a>Diagrams.TwoD.Align</a> before applying <a>hcat</a>.</li>
--   <li>For non-axis-aligned layout, see <a>cat</a>.</li>
--   </ul>
hcat :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2) => [a] -> a

-- | A variant of <a>hcat</a> taking an extra <a>CatOpts</a> record to
--   control the spacing. See the <a>cat'</a> documentation for a
--   description of the possibilities.
hcat' :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2) => CatOpts R2 -> [a] -> a

-- | Lay out a list of juxtaposable objects in a column from top to bottom,
--   so that their local origins lie along a single vertical line, with
--   successive envelopes tangent to one another.
--   
--   <ul>
--   <li>For more control over the spacing, see <a>vcat'</a>.</li>
--   <li>To align the diagrams horizontally (or otherwise), use alignment
--   combinators (such as <a>alignL</a> or <a>alignR</a>) from
--   <a>Diagrams.TwoD.Align</a> before applying <a>vcat</a>.</li>
--   <li>For non-axis-aligned layout, see <a>cat</a>.</li>
--   </ul>
vcat :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2) => [a] -> a

-- | A variant of <a>vcat</a> taking an extra <a>CatOpts</a> record to
--   control the spacing. See the <a>cat'</a> documentation for a
--   description of the possibilities.
vcat' :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2) => CatOpts R2 -> [a] -> a

-- | <tt>strutR2 v</tt> is a two-dimensional diagram which produces no
--   output, but with respect to alignment, envelope, <i>and trace</i> acts
--   like a 1-dimensional segment oriented along the vector <tt>v</tt>,
--   with local origin at its center. If you don't care about the trace
--   then there's no difference between <tt>strutR2</tt> and the more
--   general <a>strut</a>.
strutR2 :: (Backend b R2, Monoid' m) => R2 -> QDiagram b R2 m

-- | <tt>strutX w</tt> is an empty diagram with width <tt>w</tt>, height 0,
--   and a centered local origin. Note that <tt>strutX (-w)</tt> behaves
--   the same as <tt>strutX w</tt>.
strutX :: (Backend b R2, Monoid' m) => Double -> QDiagram b R2 m

-- | <tt>strutY h</tt> is an empty diagram with height <tt>h</tt>, width 0,
--   and a centered local origin. Note that <tt>strutY (-h)</tt> behaves
--   the same as <tt>strutY h</tt>.
strutY :: (Backend b R2, Monoid' m) => Double -> QDiagram b R2 m

-- | <tt>padX s</tt> "pads" a diagram in the x-direction, expanding its
--   envelope horizontally by a factor of <tt>s</tt> (factors between 0 and
--   1 can be used to shrink the envelope). Note that the envelope will
--   expand with respect to the local origin, so if the origin is not
--   centered horizontally the padding may appear "uneven". If this is not
--   desired, the origin can be centered (using <a>centerX</a>) before
--   applying <tt>padX</tt>.
padX :: (Backend b R2, Monoid' m) => Double -> QDiagram b R2 m -> QDiagram b R2 m

-- | <tt>padY s</tt> "pads" a diagram in the y-direction, expanding its
--   envelope vertically by a factor of <tt>s</tt> (factors between 0 and 1
--   can be used to shrink the envelope). Note that the envelope will
--   expand with respect to the local origin, so if the origin is not
--   centered vertically the padding may appear "uneven". If this is not
--   desired, the origin can be centered (using <a>centerY</a>) before
--   applying <tt>padY</tt>.
padY :: (Backend b R2, Monoid' m) => Double -> QDiagram b R2 m -> QDiagram b R2 m

-- | <tt>extrudeLeft s</tt> "extrudes" a diagram in the negative
--   x-direction, offsetting its envelope by the provided distance. When
--   <tt> s &lt; 0 </tt>, the envelope is inset instead.
--   
--   See the documentation for <a>extrudeEnvelope</a> for more information.
extrudeLeft :: (Semigroup m, Monoid m) => Double -> QDiagram b R2 m -> QDiagram b R2 m

-- | <tt>extrudeRight s</tt> "extrudes" a diagram in the positive
--   x-direction, offsetting its envelope by the provided distance. When
--   <tt> s &lt; 0 </tt>, the envelope is inset instead.
--   
--   See the documentation for <a>extrudeEnvelope</a> for more information.
extrudeRight :: (Semigroup m, Monoid m) => Double -> QDiagram b R2 m -> QDiagram b R2 m

-- | <tt>extrudeBottom s</tt> "extrudes" a diagram in the negative
--   y-direction, offsetting its envelope by the provided distance. When
--   <tt> s &lt; 0 </tt>, the envelope is inset instead.
--   
--   See the documentation for <a>extrudeEnvelope</a> for more information.
extrudeBottom :: (Semigroup m, Monoid m) => Double -> QDiagram b R2 m -> QDiagram b R2 m

-- | <tt>extrudeTop s</tt> "extrudes" a diagram in the positive
--   y-direction, offsetting its envelope by the provided distance. When
--   <tt> s &lt; 0 </tt>, the envelope is inset instead.
--   
--   See the documentation for <a>extrudeEnvelope</a> for more information.
extrudeTop :: (Semigroup m, Monoid m) => Double -> QDiagram b R2 m -> QDiagram b R2 m

-- | <tt>view p v</tt> sets the envelope of a diagram to a rectangle whose
--   lower-left corner is at <tt>p</tt> and whose upper-right corner is at
--   <tt>p .+^ v</tt>. Useful for selecting the rectangular portion of a
--   diagram which should actually be "viewed" in the final render, if you
--   don't want to see the entire diagram.
view :: (Backend b R2, Monoid' m) => P2 -> R2 -> QDiagram b R2 m -> QDiagram b R2 m

-- | Construct a bounding rectangle for an enveloped object, that is, the
--   smallest axis-aligned rectangle which encloses the object.
boundingRect :: (Enveloped t, Transformable t, TrailLike t, Monoid t, V t ~ R2, Enveloped a, V a ~ R2) => a -> t

-- | "Set the background color" of a diagram. That is, place a diagram atop
--   a bounding rectangle of the given color.
bg :: Renderable (Path R2) b => Colour Double -> Diagram b R2 -> Diagram b R2


-- | Very basic text primitives along with associated attributes.
module Diagrams.TwoD.Text

-- | A text primitive consists of the string contents and alignment
--   specification, along with a transformation mapping from the local
--   vector space of the text to the vector space in which it is embedded.
data Text
Text :: T2 -> TextAlignment -> String -> Text

-- | <tt>TextAlignment</tt> specifies the alignment of the text's origin.
data TextAlignment
BaselineText :: TextAlignment
BoxAlignedText :: Double -> Double -> TextAlignment

-- | Create a primitive text diagram from the given string, with center
--   alignment, equivalent to <tt><a>alignedText</a> 0.5 0.5</tt>.
--   
--   Note that it <i>takes up no space</i>, as text size information is not
--   available.
text :: Renderable Text b => String -> Diagram b R2

-- | Create a primitive text diagram from the given string, origin at the
--   top left corner of the text's bounding box, equivalent to
--   <tt><a>alignedText</a> 0 1</tt>.
--   
--   Note that it <i>takes up no space</i>.
topLeftText :: Renderable Text b => String -> Diagram b R2

-- | Create a primitive text diagram from the given string, with the origin
--   set to a point interpolated within the bounding box. The first
--   parameter varies from 0 (left) to 1 (right), and the second parameter
--   from 0 (bottom) to 1 (top).
--   
--   The height of this box is determined by the font's potential ascent
--   and descent, rather than the height of the particular string.
--   
--   Note that it <i>takes up no space</i>.
alignedText :: Renderable Text b => Double -> Double -> String -> Diagram b R2

-- | Create a primitive text diagram from the given string, with the origin
--   set to be on the baseline, at the beginning (although not bounding).
--   This is the reference point of showText in the Cairo graphics library.
--   
--   Note that it <i>takes up no space</i>.
baselineText :: Renderable Text b => String -> Diagram b R2

-- | The <tt>Font</tt> attribute specifies the name of a font family. Inner
--   <tt>Font</tt> attributes override outer ones.
newtype Font
Font :: (Last String) -> Font

-- | Extract the font family name from a <tt>Font</tt> attribute.
getFont :: Font -> String

-- | Specify a font family to be used for all text within a diagram.
font :: HasStyle a => String -> a -> a

-- | The <tt>FontSize</tt> attribute specifies the size of a font's
--   em-square, measured with respect to the current local vector space.
--   Inner <tt>FontSize</tt> attributes override outer ones.
newtype FontSize
FontSize :: (Last Double) -> FontSize

-- | Extract the size from a <tt>FontSize</tt> attribute.
getFontSize :: FontSize -> Double

-- | Set the font size, that is, the size of the font's em-square as
--   measured within the current local vector space. The default size is
--   <tt>1</tt>.
fontSize :: HasStyle a => Double -> a -> a

-- | Apply a <a>FontSize</a> attribute.
fontSizeA :: HasStyle a => FontSize -> a -> a
data FontSlant
FontSlantNormal :: FontSlant
FontSlantItalic :: FontSlant
FontSlantOblique :: FontSlant

-- | The <tt>FontSlantA</tt> attribute specifies the slant (normal, italic,
--   or oblique) that should be used for all text within a diagram. Inner
--   <tt>FontSlantA</tt> attributes override outer ones.
data FontSlantA

-- | Extract the font slant from a <a>FontSlantA</a> attribute.
getFontSlant :: FontSlantA -> FontSlant

-- | Specify the slant (normal, italic, or oblique) that should be used for
--   all text within a diagram. See also <a>italic</a> and <a>oblique</a>
--   for useful special cases.
fontSlant :: HasStyle a => FontSlant -> a -> a

-- | Set all text in italics.
italic :: HasStyle a => a -> a

-- | Set all text using an oblique slant.
oblique :: HasStyle a => a -> a
data FontWeight
FontWeightNormal :: FontWeight
FontWeightBold :: FontWeight

-- | The <tt>FontWeightA</tt> attribute specifies the weight (normal or
--   bold) that should be used for all text within a diagram. Inner
--   <tt>FontWeightA</tt> attributes override outer ones.
data FontWeightA

-- | Extract the font weight from a <a>FontWeightA</a> attribute.
getFontWeight :: FontWeightA -> FontWeight

-- | Specify the weight (normal or bold) that should be used for all text
--   within a diagram. See also <a>bold</a> for a useful special case.
fontWeight :: HasStyle a => FontWeight -> a -> a

-- | Set all text using a bold font weight.
bold :: HasStyle a => a -> a
instance Typeable Font
instance Typeable FontSize
instance Typeable FontSlantA
instance Typeable FontWeightA
instance Semigroup Font
instance Eq Font
instance Semigroup FontSize
instance Eq FontSize
instance Eq FontSlant
instance Semigroup FontSlantA
instance Eq FontSlantA
instance Eq FontWeight
instance Semigroup FontWeightA
instance Eq FontWeightA
instance AttributeClass FontWeightA
instance AttributeClass FontSlantA
instance Default FontSize
instance AttributeClass FontSize
instance AttributeClass Font
instance Renderable Text NullBackend
instance HasOrigin Text
instance IsPrim Text
instance Transformable Text


-- | Tools for visualizing diagrams' internal model: local origins,
--   envelopes, <i>etc.</i>
module Diagrams.TwoD.Model

-- | Mark the origin of a diagram by placing a red dot 1/50th its size.
showOrigin :: (Renderable (Path R2) b, Backend b R2, Monoid' m) => QDiagram b R2 m -> QDiagram b R2 m

-- | Mark the origin of a diagram, with control over colour and scale of
--   marker dot.
showOrigin' :: (Renderable (Path R2) b, Backend b R2, Monoid' m) => OriginOpts -> QDiagram b R2 m -> QDiagram b R2 m
data OriginOpts
OriginOpts :: Colour Double -> Double -> Double -> OriginOpts
oColor :: OriginOpts -> Colour Double
oScale :: OriginOpts -> Double
oMinSize :: OriginOpts -> Double
showLabels :: (Renderable Text b, Backend b R2) => QDiagram b R2 m -> QDiagram b R2 Any
instance Default OriginOpts


-- | This module defines the two-dimensional vector space R^2,
--   two-dimensional transformations, and various predefined
--   two-dimensional shapes. This module re-exports useful functionality
--   from a group of more specific modules:
--   
--   <ul>
--   <li><a>Diagrams.TwoD.Types</a> defines basic types for two-dimensional
--   diagrams, including types representing the 2D Euclidean vector space
--   and various systems of angle measurement.</li>
--   <li><a>Diagrams.TwoD.Align</a> defines alignment combinators
--   specialized to two dimensions (see <a>Diagrams.Align</a> for more
--   general alignment).</li>
--   <li><a>Diagrams.TwoD.Combinators</a> defines ways of combining
--   diagrams specialized to two dimensions (see also
--   <a>Diagrams.Combinators</a> for more general combining).</li>
--   <li><a>Diagrams.TwoD.Transform</a> defines R^2-specific
--   transformations such as rotation by an angle, and scaling,
--   translation, and reflection in the X and Y directions.</li>
--   <li><a>Diagrams.TwoD.Ellipse</a> defines circles and ellipses.</li>
--   <li><a>Diagrams.TwoD.Arc</a> defines circular arcs.</li>
--   <li><a>Diagrams.TwoD.Path</a> exports various operations on
--   two-dimensional paths when viewed as regions of the plane.</li>
--   <li><a>Diagrams.TwoD.Polygons</a> defines general algorithms for
--   drawing various types of polygons.</li>
--   <li><a>Diagrams.TwoD.Shapes</a> defines other two-dimensional shapes,
--   e.g. various polygons.</li>
--   <li><a>Diagrams.TwoD.Text</a> defines primitive text diagrams.</li>
--   <li><a>Diagrams.TwoD.Image</a> allows importing external images into
--   diagrams.</li>
--   <li><a>Diagrams.TwoD.Vector</a> defines some special 2D vectors and
--   functions for converting between vectors and angles.</li>
--   <li><a>Diagrams.TwoD.Size</a> defines functions for working with the
--   size of 2D objects.</li>
--   <li><a>Diagrams.TwoD.Model</a> defines some aids for visualizing
--   diagrams' internal model (local origins, envelopes, etc.)</li>
--   </ul>
module Diagrams.TwoD

-- | The two-dimensional Euclidean vector space R^2. This type is
--   intentionally abstract.
--   
--   <ul>
--   <li>To construct a vector, use <a>r2</a>, or <a>&amp;</a> (from
--   <a>Diagrams.Coordinates</a>):</li>
--   </ul>
--   
--   <pre>
--   r2 (3,4) :: R2
--   3 &amp; 4    :: R2
--   </pre>
--   
--   Note that <a>Diagrams.Coordinates</a> is not re-exported by
--   <a>Diagrams.Prelude</a> and must be explicitly imported.
--   
--   <ul>
--   <li>To construct the vector from the origin to a point <tt>p</tt>, use
--   <tt>p <a>.-.</a> <a>origin</a></tt>.</li>
--   <li>To convert a vector <tt>v</tt> into the point obtained by
--   following <tt>v</tt> from the origin, use <tt><a>origin</a> <a>.+^</a>
--   v</tt>.</li>
--   <li>To convert a vector back into a pair of components, use
--   <tt>unv2</tt> or <a>coords</a> (from <a>Diagrams.Coordinates</a>).
--   These are typically used in conjunction with the <tt>ViewPatterns</tt>
--   extension:</li>
--   </ul>
--   
--   <pre>
--   foo (unr2 -&gt; (x,y)) = ...
--   foo (coords -&gt; x :&amp; y) = ...
--   </pre>
data R2

-- | Construct a 2D vector from a pair of components. See also
--   <a>&amp;</a>.
r2 :: (Double, Double) -> R2

-- | Convert a 2D vector back into a pair of components. See also
--   <a>coords</a>.
unr2 :: R2 -> (Double, Double)

-- | Points in R^2. This type is intentionally abstract.
--   
--   <ul>
--   <li>To construct a point, use <a>p2</a>, or <a>&amp;</a> (see
--   <a>Diagrams.Coordinates</a>):</li>
--   </ul>
--   
--   <pre>
--   p2 (3,4)  :: P2
--   3 &amp; 4     :: P2
--   </pre>
--   
--   <ul>
--   <li>To construct a point from a vector <tt>v</tt>, use
--   <tt><a>origin</a> <a>.+^</a> v</tt>.</li>
--   <li>To convert a point <tt>p</tt> into the vector from the origin to
--   <tt>p</tt>, use <tt>p <a>.-.</a> <a>origin</a></tt>.</li>
--   <li>To convert a point back into a pair of coordinates, use
--   <a>unp2</a>, or <a>coords</a> (from <a>Diagrams.Coordinates</a>). It's
--   common to use these in conjunction with the <tt>ViewPatterns</tt>
--   extension:</li>
--   </ul>
--   
--   <pre>
--   foo (unp2 -&gt; (x,y)) = ...
--   foo (coords -&gt; x :&amp; y) = ...
--   </pre>
type P2 = Point R2

-- | Construct a 2D point from a pair of coordinates. See also
--   <a>&amp;</a>.
p2 :: (Double, Double) -> P2

-- | Convert a 2D point back into a pair of coordinates. See also
--   <a>coords</a>.
unp2 :: P2 -> (Double, Double)

-- | Transformations in R^2.
type T2 = Transformation R2

-- | The unit vector in the positive X direction.
unitX :: R2

-- | The unit vector in the positive Y direction.
unitY :: R2

-- | The unit vector in the negative X direction.
unit_X :: R2

-- | The unit vector in the negative Y direction.
unit_Y :: R2

-- | Compute the direction of a vector, measured counterclockwise from the
--   positive x-axis as a fraction of a full turn. The zero vector is
--   arbitrarily assigned the direction 0.
direction :: Angle a => R2 -> a

-- | Convert an angle into a unit vector pointing in that direction.
fromDirection :: Angle a => a -> R2

-- | A convenient synonym for <a>fromDirection</a>.
e :: Angle a => a -> R2

-- | The circle constant, the ratio of a circle's circumference to its
--   <i>radius</i>. Note that <tt>pi = tau/2</tt>.
--   
--   For more information and a well-reasoned argument why we should all be
--   using tau instead of pi, see <i>The Tau Manifesto</i>,
--   <a>http://tauday.com/</a>.
--   
--   To hear what it sounds like (and to easily memorize the first 30
--   digits or so), try <a>http://youtu.be/3174T-3-59Q</a>.
tau :: Floating a => a

-- | Type class for types that measure angles.
class Num a => Angle a
toTurn :: Angle a => a -> Turn
fromTurn :: Angle a => Turn -> a

-- | Newtype wrapper used to represent angles as fractions of a circle. For
--   example, 1/3 turn = tau/3 radians = 120 degrees.
newtype Turn
Turn :: Double -> Turn
getTurn :: Turn -> Double

-- | Deprecated synonym for <a>Turn</a>, retained for backwards
--   compatibility.
type CircleFrac = Turn

-- | Newtype wrapper for representing angles in radians.
newtype Rad
Rad :: Double -> Rad
getRad :: Rad -> Double

-- | Newtype wrapper for representing angles in degrees.
newtype Deg
Deg :: Double -> Deg
getDeg :: Deg -> Double

-- | Deprecated synonym for <a>fullTurn</a>, retained for backwards
--   compatibility.
fullCircle :: Angle a => a

-- | Convert between two angle representations.
convertAngle :: (Angle a, Angle b) => a -> b

-- | Convert a path into a diagram. The resulting diagram has the names 0,
--   1, ... assigned to each of the path's vertices.
--   
--   See also <a>stroke'</a>, which takes an extra options record allowing
--   its behavior to be customized.
--   
--   Note that a bug in GHC 7.0.1 causes a context stack overflow when
--   inferring the type of <tt>stroke</tt>. The solution is to give a type
--   signature to expressions involving <tt>stroke</tt>, or (recommended)
--   upgrade GHC (the bug is fixed in 7.0.2 onwards).
stroke :: Renderable (Path R2) b => Path R2 -> Diagram b R2

-- | A variant of <a>stroke</a> that takes an extra record of options to
--   customize its behavior. In particular:
--   
--   <ul>
--   <li>Names can be assigned to the path's vertices</li>
--   </ul>
--   
--   <a>StrokeOpts</a> is an instance of <a>Default</a>, so <tt>stroke'
--   <tt>with</tt> { ... }</tt> syntax may be used.
stroke' :: (Renderable (Path R2) b, IsName a) => StrokeOpts a -> Path R2 -> Diagram b R2

-- | A composition of <a>stroke</a> and <a>pathFromTrail</a> for
--   conveniently converting a trail directly into a diagram.
--   
--   Note that a bug in GHC 7.0.1 causes a context stack overflow when
--   inferring the type of <a>stroke</a> and hence of <tt>strokeT</tt> as
--   well. The solution is to give a type signature to expressions
--   involving <tt>strokeT</tt>, or (recommended) upgrade GHC (the bug is
--   fixed in 7.0.2 onwards).
strokeT :: Renderable (Path R2) b => Trail R2 -> Diagram b R2

-- | A composition of <a>stroke'</a> and <a>pathFromTrail</a> for
--   conveniently converting a trail directly into a diagram.
strokeT' :: (Renderable (Path R2) b, IsName a) => StrokeOpts a -> Trail R2 -> Diagram b R2

-- | A composition of <a>strokeT</a> and <a>wrapLine</a> for conveniently
--   converting a line directly into a diagram.
strokeLine :: Renderable (Path R2) b => Trail' Line R2 -> Diagram b R2

-- | A composition of <a>strokeT</a> and <a>wrapLoop</a> for conveniently
--   converting a loop directly into a diagram.
strokeLoop :: Renderable (Path R2) b => Trail' Loop R2 -> Diagram b R2

-- | A convenience function for converting a <tt>Located Trail</tt>
--   directly into a diagram; <tt>strokeLocT = stroke . trailLike</tt>.
strokeLocT :: Renderable (Path R2) b => Located (Trail R2) -> Diagram b R2

-- | A convenience function for converting a <tt>Located</tt> line directly
--   into a diagram; <tt>strokeLocLine = stroke . trailLike . mapLoc
--   wrapLine</tt>.
strokeLocLine :: Renderable (Path R2) b => Located (Trail' Line R2) -> Diagram b R2

-- | A convenience function for converting a <tt>Located</tt> loop directly
--   into a diagram; <tt>strokeLocLoop = stroke . trailLike . mapLoc
--   wrapLoop</tt>.
strokeLocLoop :: Renderable (Path R2) b => Located (Trail' Loop R2) -> Diagram b R2

-- | Enumeration of algorithms or "rules" for determining which points lie
--   in the interior of a (possibly self-intersecting) closed path.
data FillRule

-- | Interior points are those with a nonzero <i>winding</i> <i>number</i>.
--   See <a>http://en.wikipedia.org/wiki/Nonzero-rule</a>.
Winding :: FillRule

-- | Interior points are those where a ray extended infinitely in a
--   particular direction crosses the path an odd number of times. See
--   <a>http://en.wikipedia.org/wiki/Even-odd_rule</a>.
EvenOdd :: FillRule

-- | Specify the fill rule that should be used for determining which points
--   are inside a path.
fillRule :: HasStyle a => FillRule -> a -> a

-- | A record of options that control how a path is stroked.
--   <tt>StrokeOpts</tt> is an instance of <a>Default</a>, so a
--   <tt>StrokeOpts</tt> records can be created using <tt><tt>with</tt> {
--   ... }</tt> notation.
data StrokeOpts a
StrokeOpts :: [[a]] -> FillRule -> StrokeOpts a

-- | Atomic names that should be assigned to the vertices of the path so
--   that they can be referenced later. If there are not enough names, the
--   extra vertices are not assigned names; if there are too many, the
--   extra names are ignored. Note that this is a <i>list of lists</i> of
--   names, since paths can consist of multiple trails. The first list of
--   names are assigned to the vertices of the first trail, the second list
--   to the second trail, and so on.
--   
--   The default value is the empty list.
vertexNames :: StrokeOpts a -> [[a]]

-- | The fill rule used for determining which points are inside the path.
--   The default is <a>Winding</a>. NOTE: for now, this only affects the
--   resulting diagram's <a>Query</a>, <i>not</i> how it will be drawn! To
--   set the fill rule determining how it is to be drawn, use the
--   <a>fillRule</a> function.
queryFillRule :: StrokeOpts a -> FillRule

-- | Clip a diagram by the given path:
--   
--   <ul>
--   <li>Only the parts of the diagram which lie in the interior of the
--   path will be drawn.</li>
--   <li>The envelope of the diagram is unaffected.</li>
--   </ul>
clipBy :: (HasStyle a, V a ~ R2) => Path R2 -> a -> a

-- | Create a centered horizontal (L-R) line of the given length.
--   
--   
--   <pre>
--   hruleEx = vcat' with {sep = 0.2} (map hrule [1..5])
--           # centerXY # pad 1.1
--   </pre>
hrule :: (TrailLike t, V t ~ R2) => Double -> t

-- | Create a centered vertical (T-B) line of the given length.
--   
--   
--   <pre>
--   vruleEx = hcat' with {sep = 0.2} (map vrule [1, 1.2 .. 2])
--           # centerXY # pad 1.1
--   </pre>
vrule :: (TrailLike t, V t ~ R2) => Double -> t

-- | A circle of radius 1, with center at the origin.
unitCircle :: (TrailLike t, V t ~ R2) => t

-- | A circle of the given radius, centered at the origin. As a path, it
--   begins at (r,0).
circle :: (TrailLike t, V t ~ R2, Transformable t) => Double -> t

-- | <tt>ellipse e</tt> constructs an ellipse with eccentricity <tt>e</tt>
--   by scaling the unit circle in the X direction. The eccentricity must
--   be within the interval [0,1).
ellipse :: (TrailLike t, V t ~ R2, Transformable t) => Double -> t

-- | <tt>ellipseXY x y</tt> creates an axis-aligned ellipse, centered at
--   the origin, with radius <tt>x</tt> along the x-axis and radius
--   <tt>y</tt> along the y-axis.
ellipseXY :: (TrailLike t, V t ~ R2, Transformable t) => Double -> Double -> t

-- | Given a start angle <tt>s</tt> and an end angle <tt>e</tt>,
--   <tt><a>arc</a> s e</tt> is the path of a radius one arc
--   counterclockwise between the two angles. The origin of the arc is its
--   center.
arc :: (Angle a, TrailLike t, V t ~ R2) => a -> a -> t

-- | Given a radus <tt>r</tt>, a start angle <tt>s</tt> and an end angle
--   <tt>e</tt>, <tt><a>arc'</a> r s e</tt> is the path of a radius
--   <tt>(abs r)</tt> arc between the two angles. If a negative radius is
--   given, the arc will be clockwise, otherwise it will be
--   counterclockwise. The origin of the arc is its center.
arc' :: (Angle a, TrailLike p, V p ~ R2) => Double -> a -> a -> p

-- | Like <a>arc</a> but clockwise.
arcCW :: (Angle a, TrailLike t, V t ~ R2) => a -> a -> t

-- | Create a circular wedge of the given radius, beginning at the first
--   angle and extending counterclockwise to the second.
wedge :: (Angle a, TrailLike p, V p ~ R2) => Double -> a -> a -> p

-- | Generate the polygon described by the given options.
polygon :: (TrailLike t, V t ~ R2) => PolygonOpts -> t

-- | Generate a polygon. See <a>PolygonOpts</a> for more information.
polyTrail :: PolygonOpts -> Located (Trail R2)

-- | Options for specifying a polygon.
data PolygonOpts
PolygonOpts :: PolyType -> PolyOrientation -> P2 -> PolygonOpts

-- | Specification for the polygon's vertices.
polyType :: PolygonOpts -> PolyType

-- | Should a rotation be applied to the polygon in order to orient it in a
--   particular way?
polyOrient :: PolygonOpts -> PolyOrientation

-- | Should a translation be applied to the polygon in order to place the
--   center at a particular location?
polyCenter :: PolygonOpts -> P2

-- | Method used to determine the vertices of a polygon.
data PolyType

-- | A "polar" polygon.
--   
--   <ul>
--   <li>The first argument is a list of <i>central</i> <i>angles</i> from
--   each vertex to the next.</li>
--   <li>The second argument is a list of <i>radii</i> from the origin to
--   each successive vertex.</li>
--   </ul>
--   
--   To construct an <i>n</i>-gon, use a list of <i>n-1</i> angles and
--   <i>n</i> radii. Extra angles or radii are ignored.
--   
--   Cyclic polygons (with all vertices lying on a circle) can be
--   constructed using a second argument of <tt>(repeat r)</tt>.
PolyPolar :: [a] -> [Double] -> PolyType

-- | A polygon determined by the distance between successive vertices and
--   the angles formed by each three successive vertices. In other words, a
--   polygon specified by "turtle graphics": go straight ahead x1 units;
--   turn by angle a1; go straght ahead x2 units; turn by angle a2; etc.
--   The polygon will be centered at the <i>centroid</i> of its vertices.
--   
--   <ul>
--   <li>The first argument is a list of <i>vertex</i> <i>angles</i>,
--   giving the angle at each vertex from the previous vertex to the next.
--   The first angle in the list is the angle at the <i>second</i> vertex;
--   the first edge always starts out heading in the positive y direction
--   from the first vertex.</li>
--   <li>The second argument is a list of distances between successive
--   vertices.</li>
--   </ul>
--   
--   To construct an <i>n</i>-gon, use a list of <i>n-2</i> angles and
--   <i>n-1</i> edge lengths. Extra angles or lengths are ignored.
PolySides :: [a] -> [Double] -> PolyType

-- | A regular polygon with the given number of sides (first argument) and
--   the given radius (second argument).
PolyRegular :: Int -> Double -> PolyType

-- | Determine how a polygon should be oriented.
data PolyOrientation

-- | No special orientation; the first vertex will be at (1,0). This is the
--   default.
NoOrient :: PolyOrientation

-- | Orient <i>horizontally</i>, so the bottommost edge is parallel to the
--   x-axis.
OrientH :: PolyOrientation

-- | Orient <i>vertically</i>, so the leftmost edge is parallel to the
--   y-axis.
OrientV :: PolyOrientation

-- | Orient so some edge is <i>facing</i> <i>in</i> <i>the</i>
--   <i>direction</i> <i>of</i>, that is, perpendicular to, the given
--   vector.
OrientTo :: R2 -> PolyOrientation

-- | Options for creating "star" polygons, where the edges connect possibly
--   non-adjacent vertices.
data StarOpts

-- | Specify the order in which the vertices should be connected by a
--   function that maps each vertex index to the index of the vertex that
--   should come next. Indexing of vertices begins at 0.
StarFun :: (Int -> Int) -> StarOpts

-- | Specify a star polygon by a "skip". A skip of 1 indicates a normal
--   polygon, where edges go between successive vertices. A skip of 2 means
--   that edges will connect every second vertex, skipping one in between.
--   Generally, a skip of <i>n</i> means that edges will connect every
--   <i>n</i>th vertex.
StarSkip :: Int -> StarOpts

-- | Create a generalized <i>star</i> <i>polygon</i>. The <a>StarOpts</a>
--   are used to determine in which order the given vertices should be
--   connected. The intention is that the second argument of type
--   <tt>[P2]</tt> could be generated by a call to <a>polygon</a>,
--   <tt>regPoly</tt>, or the like, since a list of vertices is
--   <a>TrailLike</a>. But of course the list can be generated any way you
--   like. A <tt><a>Path</a> <a>R2</a></tt> is returned (instead of any
--   <a>TrailLike</a>) because the resulting path may have more than one
--   component, for example if the vertices are to be connected in several
--   disjoint cycles.
star :: StarOpts -> [P2] -> Path R2

-- | Create a regular polygon. The first argument is the number of sides,
--   and the second is the <i>length</i> of the sides. (Compare to the
--   <a>polygon</a> function with a <a>PolyRegular</a> option, which
--   produces polygons of a given <i>radius</i>).
--   
--   The polygon will be oriented with one edge parallel to the x-axis.
regPoly :: (TrailLike t, V t ~ R2) => Int -> Double -> t

-- | An equilateral triangle, with sides of the given length and base
--   parallel to the x-axis.
--   
triangle :: (TrailLike t, V t ~ R2) => Double -> t

-- | A synonym for <a>triangle</a>, provided for backwards compatibility.
eqTriangle :: (TrailLike t, V t ~ R2) => Double -> t

-- | A square with its center at the origin and sides of the given length,
--   oriented parallel to the axes.
--   
square :: (TrailLike t, Transformable t, V t ~ R2) => Double -> t

-- | A regular pentagon, with sides of the given length and base parallel
--   to the x-axis.
--   
pentagon :: (TrailLike t, V t ~ R2) => Double -> t

-- | A regular hexagon, with sides of the given length and base parallel to
--   the x-axis.
--   
hexagon :: (TrailLike t, V t ~ R2) => Double -> t

-- | A regular septagon, with sides of the given length and base parallel
--   to the x-axis.
--   
septagon :: (TrailLike t, V t ~ R2) => Double -> t

-- | A regular octagon, with sides of the given length and base parallel to
--   the x-axis.
--   
octagon :: (TrailLike t, V t ~ R2) => Double -> t

-- | A regular nonagon, with sides of the given length and base parallel to
--   the x-axis.
--   
nonagon :: (TrailLike t, V t ~ R2) => Double -> t

-- | A regular decagon, with sides of the given length and base parallel to
--   the x-axis.
--   
decagon :: (TrailLike t, V t ~ R2) => Double -> t

-- | A regular hendecagon, with sides of the given length and base parallel
--   to the x-axis.
--   
hendecagon :: (TrailLike t, V t ~ R2) => Double -> t

-- | A regular dodecagon, with sides of the given length and base parallel
--   to the x-axis.
--   
dodecagon :: (TrailLike t, V t ~ R2) => Double -> t

-- | A square with its center at the origin and sides of length 1, oriented
--   parallel to the axes.
--   
unitSquare :: (TrailLike t, V t ~ R2) => t

-- | <tt>rect w h</tt> is an axis-aligned rectangle of width <tt>w</tt> and
--   height <tt>h</tt>, centered at the origin.
--   
rect :: (TrailLike t, Transformable t, V t ~ R2) => Double -> Double -> t

-- | <tt>roundedRect w h r</tt> generates a closed trail, or closed path
--   centered at the origin, of an axis-aligned rectangle with width
--   <tt>w</tt>, height <tt>h</tt>, and circular rounded corners of radius
--   <tt>r</tt>. If <tt>r</tt> is negative the corner will be cut out in a
--   reverse arc. If the size of <tt>r</tt> is larger than half the smaller
--   dimension of <tt>w</tt> and <tt>h</tt>, then it will be reduced to fit
--   in that range, to prevent the corners from overlapping. The trail or
--   path begins with the right edge and proceeds counterclockwise. If you
--   need to specify a different radius for each corner individually, use
--   <a>roundedRect'</a> instead.
--   
--   
--   <pre>
--   roundedRectEx = pad 1.1 . centerXY $ hcat' with { sep = 0.2 }
--     [ roundedRect  0.5 0.4 0.1
--     , roundedRect  0.5 0.4 (-0.1)
--     , roundedRect' 0.7 0.4 with { radiusTL = 0.2
--                                 , radiusTR = -0.2
--                                 , radiusBR = 0.1 }
--     ]
--   </pre>
roundedRect :: (TrailLike t, V t ~ R2) => Double -> Double -> Double -> t

-- | <tt>roundedRect'</tt> works like <tt>roundedRect</tt> but allows you
--   to set the radius of each corner indivually, using
--   <tt>RoundedRectOpts</tt>. The default corner radius is 0. Each radius
--   can also be negative, which results in the curves being reversed to be
--   inward instead of outward.
roundedRect' :: (TrailLike t, V t ~ R2) => Double -> Double -> RoundedRectOpts -> t
data RoundedRectOpts
RoundedRectOpts :: Double -> Double -> Double -> Double -> RoundedRectOpts
radiusTL :: RoundedRectOpts -> Double
radiusTR :: RoundedRectOpts -> Double
radiusBL :: RoundedRectOpts -> Double
radiusBR :: RoundedRectOpts -> Double

-- | Create a primitive text diagram from the given string, with center
--   alignment, equivalent to <tt><a>alignedText</a> 0.5 0.5</tt>.
--   
--   Note that it <i>takes up no space</i>, as text size information is not
--   available.
text :: Renderable Text b => String -> Diagram b R2

-- | Create a primitive text diagram from the given string, origin at the
--   top left corner of the text's bounding box, equivalent to
--   <tt><a>alignedText</a> 0 1</tt>.
--   
--   Note that it <i>takes up no space</i>.
topLeftText :: Renderable Text b => String -> Diagram b R2

-- | Create a primitive text diagram from the given string, with the origin
--   set to a point interpolated within the bounding box. The first
--   parameter varies from 0 (left) to 1 (right), and the second parameter
--   from 0 (bottom) to 1 (top).
--   
--   The height of this box is determined by the font's potential ascent
--   and descent, rather than the height of the particular string.
--   
--   Note that it <i>takes up no space</i>.
alignedText :: Renderable Text b => Double -> Double -> String -> Diagram b R2

-- | Create a primitive text diagram from the given string, with the origin
--   set to be on the baseline, at the beginning (although not bounding).
--   This is the reference point of showText in the Cairo graphics library.
--   
--   Note that it <i>takes up no space</i>.
baselineText :: Renderable Text b => String -> Diagram b R2

-- | Specify a font family to be used for all text within a diagram.
font :: HasStyle a => String -> a -> a

-- | Set the font size, that is, the size of the font's em-square as
--   measured within the current local vector space. The default size is
--   <tt>1</tt>.
fontSize :: HasStyle a => Double -> a -> a

-- | Set all text in italics.
italic :: HasStyle a => a -> a

-- | Set all text using an oblique slant.
oblique :: HasStyle a => a -> a

-- | Set all text using a bold font weight.
bold :: HasStyle a => a -> a

-- | Take an external image from the specified file and turn it into a
--   diagram with the specified width and height, centered at the origin.
--   Note that the image's aspect ratio will be preserved; if the specified
--   width and height have a different ratio than the image's aspect ratio,
--   there will be extra space in one dimension.
image :: Renderable Image b => FilePath -> Double -> Double -> Diagram b R2

-- | Create a transformation which performs a rotation about the local
--   origin by the given angle. See also <a>rotate</a>.
rotation :: Angle a => a -> T2

-- | Rotate about the local origin by the given angle. Positive angles
--   correspond to counterclockwise rotation, negative to clockwise. The
--   angle can be expressed using any type which is an instance of
--   <a>Angle</a>. For example, <tt>rotate (1/4 :: <a>Turn</a>)</tt>,
--   <tt>rotate (tau/4 :: <a>Rad</a>)</tt>, and <tt>rotate (90 ::
--   <a>Deg</a>)</tt> all represent the same transformation, namely, a
--   counterclockwise rotation by a right angle. To rotate about some point
--   other than the local origin, see <a>rotateAbout</a>.
--   
--   Note that writing <tt>rotate (1/4)</tt>, with no type annotation, will
--   yield an error since GHC cannot figure out which sort of angle you
--   want to use. In this common situation you can use <a>rotateBy</a>,
--   which is specialized to take a <a>Turn</a> argument.
rotate :: (Transformable t, V t ~ R2, Angle a) => a -> t -> t

-- | A synonym for <a>rotate</a>, specialized to only work with
--   <tt>Turn</tt> arguments; it can be more convenient to write
--   <tt>rotateBy (1/4)</tt> than <tt><a>rotate</a> (1/4 ::
--   <a>Turn</a>)</tt>.
rotateBy :: (Transformable t, V t ~ R2) => Turn -> t -> t

-- | <tt>rotationAbout p</tt> is a rotation about the point <tt>p</tt>
--   (instead of around the local origin).
rotationAbout :: Angle a => P2 -> a -> T2

-- | <tt>rotateAbout p</tt> is like <a>rotate</a>, except it rotates around
--   the point <tt>p</tt> instead of around the local origin.
rotateAbout :: (Transformable t, V t ~ R2, Angle a) => P2 -> a -> t -> t

-- | Construct a transformation which scales by the given factor in the x
--   (horizontal) direction.
scalingX :: Double -> T2

-- | Scale a diagram by the given factor in the x (horizontal) direction.
--   To scale uniformly, use <a>scale</a>.
scaleX :: (Transformable t, V t ~ R2) => Double -> t -> t

-- | Construct a transformation which scales by the given factor in the y
--   (vertical) direction.
scalingY :: Double -> T2

-- | Scale a diagram by the given factor in the y (vertical) direction. To
--   scale uniformly, use <a>scale</a>.
scaleY :: (Transformable t, V t ~ R2) => Double -> t -> t

-- | Create a uniform scaling transformation.
scaling :: (HasLinearMap v, Fractional (Scalar v)) => Scalar v -> Transformation v

-- | Scale uniformly in every dimension by the given scalar.
scale :: (Transformable t, Fractional (Scalar (V t)), Eq (Scalar (V t))) => Scalar (V t) -> t -> t

-- | <tt>scaleToX w</tt> scales a diagram in the x (horizontal) direction
--   by whatever factor required to make its width <tt>w</tt>.
--   <tt>scaleToX</tt> should not be applied to diagrams with a width of 0,
--   such as <tt>vrule</tt>.
scaleToX :: (Enveloped t, Transformable t, V t ~ R2) => Double -> t -> t

-- | <tt>scaleToY h</tt> scales a diagram in the y (vertical) direction by
--   whatever factor required to make its height <tt>h</tt>.
--   <tt>scaleToY</tt> should not be applied to diagrams with a height of
--   0, such as <tt>hrule</tt>.
scaleToY :: (Enveloped t, Transformable t, V t ~ R2) => Double -> t -> t

-- | <tt>scaleUToX w</tt> scales a diagram <i>uniformly</i> by whatever
--   factor required to make its width <tt>w</tt>. <tt>scaleUToX</tt>
--   should not be applied to diagrams with a width of 0, such as
--   <tt>vrule</tt>.
scaleUToX :: (Enveloped t, Transformable t, V t ~ R2) => Double -> t -> t

-- | <tt>scaleUToY h</tt> scales a diagram <i>uniformly</i> by whatever
--   factor required to make its height <tt>h</tt>. <tt>scaleUToY</tt>
--   should not be applied to diagrams with a height of 0, such as
--   <tt>hrule</tt>.
scaleUToY :: (Enveloped t, Transformable t, V t ~ R2) => Double -> t -> t

-- | Construct a transformation which translates by the given distance in
--   the x (horizontal) direction.
translationX :: Double -> T2

-- | Translate a diagram by the given distance in the x (horizontal)
--   direction.
translateX :: (Transformable t, V t ~ R2) => Double -> t -> t

-- | Construct a transformation which translates by the given distance in
--   the y (vertical) direction.
translationY :: Double -> T2

-- | Translate a diagram by the given distance in the y (vertical)
--   direction.
translateY :: (Transformable t, V t ~ R2) => Double -> t -> t

-- | Create a translation.
translation :: HasLinearMap v => v -> Transformation v

-- | Translate by a vector.
translate :: (Transformable t, HasLinearMap (V t)) => V t -> t -> t

-- | Construct a transformation which flips a diagram from left to right,
--   i.e. sends the point (x,y) to (-x,y).
reflectionX :: T2

-- | Flip a diagram from left to right, i.e. send the point (x,y) to
--   (-x,y).
reflectX :: (Transformable t, V t ~ R2) => t -> t

-- | Construct a transformation which flips a diagram from top to bottom,
--   i.e. sends the point (x,y) to (x,-y).
reflectionY :: T2

-- | Flip a diagram from top to bottom, i.e. send the point (x,y) to
--   (x,-y).
reflectY :: (Transformable t, V t ~ R2) => t -> t

-- | <tt>reflectionAbout p v</tt> is a reflection in the line determined by
--   the point <tt>p</tt> and vector <tt>v</tt>.
reflectionAbout :: P2 -> R2 -> T2

-- | <tt>reflectAbout p v</tt> reflects a diagram in the line determined by
--   the point <tt>p</tt> and the vector <tt>v</tt>.
reflectAbout :: (Transformable t, V t ~ R2) => P2 -> R2 -> t -> t

-- | <tt>shearingX d</tt> is the linear transformation which is the
--   identity on y coordinates and sends <tt>(0,1)</tt> to <tt>(d,1)</tt>.
shearingX :: Double -> T2

-- | <tt>shearX d</tt> performs a shear in the x-direction which sends
--   <tt>(0,1)</tt> to <tt>(d,1)</tt>.
shearX :: (Transformable t, V t ~ R2) => Double -> t -> t

-- | <tt>shearingY d</tt> is the linear transformation which is the
--   identity on x coordinates and sends <tt>(1,0)</tt> to <tt>(1,d)</tt>.
shearingY :: Double -> T2

-- | <tt>shearY d</tt> performs a shear in the y-direction which sends
--   <tt>(1,0)</tt> to <tt>(1,d)</tt>.
shearY :: (Transformable t, V t ~ R2) => Double -> t -> t

-- | Place two diagrams (or other objects) vertically adjacent to one
--   another, with the first diagram above the second. Since Haskell
--   ignores whitespace in expressions, one can thus write
--   
--   <pre>
--    c
--   ===
--    d
--   </pre>
--   
--   to place <tt>c</tt> above <tt>d</tt>. The local origin of the
--   resulting combined diagram is the same as the local origin of the
--   first. <tt>(===)</tt> is associative and has <a>mempty</a> as an
--   identity. See the documentation of <a>beside</a> for more information.
(===) :: (Juxtaposable a, V a ~ R2, Semigroup a) => a -> a -> a

-- | Place two diagrams (or other juxtaposable objects) horizontally
--   adjacent to one another, with the first diagram to the left of the
--   second. The local origin of the resulting combined diagram is the same
--   as the local origin of the first. <tt>(===)</tt> is associative and
--   has <a>mempty</a> as an identity. See the documentation of
--   <a>beside</a> for more information.
(|||) :: (Juxtaposable a, V a ~ R2, Semigroup a) => a -> a -> a

-- | Place two diagrams (or other juxtaposable objects) adjacent to one
--   another, with the second diagram placed along a line at angle
--   <tt>th</tt> from the first. The local origin of the resulting combined
--   diagram is the same as the local origin of the first. See the
--   documentation of <a>beside</a> for more information.
atAngle :: (Juxtaposable a, V a ~ R2, Semigroup a, Angle b) => b -> a -> a -> a

-- | Lay out a list of juxtaposable objects in a row from left to right, so
--   that their local origins lie along a single horizontal line, with
--   successive envelopes tangent to one another.
--   
--   <ul>
--   <li>For more control over the spacing, see <a>hcat'</a>.</li>
--   <li>To align the diagrams vertically (or otherwise), use alignment
--   combinators (such as <a>alignT</a> or <a>alignB</a>) from
--   <a>Diagrams.TwoD.Align</a> before applying <a>hcat</a>.</li>
--   <li>For non-axis-aligned layout, see <a>cat</a>.</li>
--   </ul>
hcat :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2) => [a] -> a

-- | A variant of <a>hcat</a> taking an extra <a>CatOpts</a> record to
--   control the spacing. See the <a>cat'</a> documentation for a
--   description of the possibilities.
hcat' :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2) => CatOpts R2 -> [a] -> a

-- | Lay out a list of juxtaposable objects in a column from top to bottom,
--   so that their local origins lie along a single vertical line, with
--   successive envelopes tangent to one another.
--   
--   <ul>
--   <li>For more control over the spacing, see <a>vcat'</a>.</li>
--   <li>To align the diagrams horizontally (or otherwise), use alignment
--   combinators (such as <a>alignL</a> or <a>alignR</a>) from
--   <a>Diagrams.TwoD.Align</a> before applying <a>vcat</a>.</li>
--   <li>For non-axis-aligned layout, see <a>cat</a>.</li>
--   </ul>
vcat :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2) => [a] -> a

-- | A variant of <a>vcat</a> taking an extra <a>CatOpts</a> record to
--   control the spacing. See the <a>cat'</a> documentation for a
--   description of the possibilities.
vcat' :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2) => CatOpts R2 -> [a] -> a

-- | <tt>strutX w</tt> is an empty diagram with width <tt>w</tt>, height 0,
--   and a centered local origin. Note that <tt>strutX (-w)</tt> behaves
--   the same as <tt>strutX w</tt>.
strutX :: (Backend b R2, Monoid' m) => Double -> QDiagram b R2 m

-- | <tt>strutY h</tt> is an empty diagram with height <tt>h</tt>, width 0,
--   and a centered local origin. Note that <tt>strutY (-h)</tt> behaves
--   the same as <tt>strutY h</tt>.
strutY :: (Backend b R2, Monoid' m) => Double -> QDiagram b R2 m

-- | <tt>padX s</tt> "pads" a diagram in the x-direction, expanding its
--   envelope horizontally by a factor of <tt>s</tt> (factors between 0 and
--   1 can be used to shrink the envelope). Note that the envelope will
--   expand with respect to the local origin, so if the origin is not
--   centered horizontally the padding may appear "uneven". If this is not
--   desired, the origin can be centered (using <a>centerX</a>) before
--   applying <tt>padX</tt>.
padX :: (Backend b R2, Monoid' m) => Double -> QDiagram b R2 m -> QDiagram b R2 m

-- | <tt>padY s</tt> "pads" a diagram in the y-direction, expanding its
--   envelope vertically by a factor of <tt>s</tt> (factors between 0 and 1
--   can be used to shrink the envelope). Note that the envelope will
--   expand with respect to the local origin, so if the origin is not
--   centered vertically the padding may appear "uneven". If this is not
--   desired, the origin can be centered (using <a>centerY</a>) before
--   applying <tt>padY</tt>.
padY :: (Backend b R2, Monoid' m) => Double -> QDiagram b R2 m -> QDiagram b R2 m

-- | <tt>extrudeLeft s</tt> "extrudes" a diagram in the negative
--   x-direction, offsetting its envelope by the provided distance. When
--   <tt> s &lt; 0 </tt>, the envelope is inset instead.
--   
--   See the documentation for <a>extrudeEnvelope</a> for more information.
extrudeLeft :: (Semigroup m, Monoid m) => Double -> QDiagram b R2 m -> QDiagram b R2 m

-- | <tt>extrudeRight s</tt> "extrudes" a diagram in the positive
--   x-direction, offsetting its envelope by the provided distance. When
--   <tt> s &lt; 0 </tt>, the envelope is inset instead.
--   
--   See the documentation for <a>extrudeEnvelope</a> for more information.
extrudeRight :: (Semigroup m, Monoid m) => Double -> QDiagram b R2 m -> QDiagram b R2 m

-- | <tt>extrudeBottom s</tt> "extrudes" a diagram in the negative
--   y-direction, offsetting its envelope by the provided distance. When
--   <tt> s &lt; 0 </tt>, the envelope is inset instead.
--   
--   See the documentation for <a>extrudeEnvelope</a> for more information.
extrudeBottom :: (Semigroup m, Monoid m) => Double -> QDiagram b R2 m -> QDiagram b R2 m

-- | <tt>extrudeTop s</tt> "extrudes" a diagram in the positive
--   y-direction, offsetting its envelope by the provided distance. When
--   <tt> s &lt; 0 </tt>, the envelope is inset instead.
--   
--   See the documentation for <a>extrudeEnvelope</a> for more information.
extrudeTop :: (Semigroup m, Monoid m) => Double -> QDiagram b R2 m -> QDiagram b R2 m

-- | <tt>view p v</tt> sets the envelope of a diagram to a rectangle whose
--   lower-left corner is at <tt>p</tt> and whose upper-right corner is at
--   <tt>p .+^ v</tt>. Useful for selecting the rectangular portion of a
--   diagram which should actually be "viewed" in the final render, if you
--   don't want to see the entire diagram.
view :: (Backend b R2, Monoid' m) => P2 -> R2 -> QDiagram b R2 m -> QDiagram b R2 m

-- | Construct a bounding rectangle for an enveloped object, that is, the
--   smallest axis-aligned rectangle which encloses the object.
boundingRect :: (Enveloped t, Transformable t, TrailLike t, Monoid t, V t ~ R2, Enveloped a, V a ~ R2) => a -> t

-- | "Set the background color" of a diagram. That is, place a diagram atop
--   a bounding rectangle of the given color.
bg :: Renderable (Path R2) b => Colour Double -> Diagram b R2 -> Diagram b R2

-- | Align along the left edge, i.e. translate the diagram in a horizontal
--   direction so that the local origin is on the left edge of the
--   envelope.
alignL :: (Alignable a, V a ~ R2) => a -> a

-- | Align along the right edge.
alignR :: (Alignable a, V a ~ R2) => a -> a

-- | Align along the top edge.
alignT :: (Alignable a, V a ~ R2) => a -> a

-- | Align along the bottom edge.
alignB :: (Alignable a, V a ~ R2) => a -> a
alignTL :: (Alignable a, V a ~ R2) => a -> a
alignTR :: (Alignable a, V a ~ R2) => a -> a
alignBL :: (Alignable a, V a ~ R2) => a -> a
alignBR :: (Alignable a, V a ~ R2) => a -> a

-- | <tt>alignX</tt> moves the local origin horizontally as follows:
--   
--   <ul>
--   <li><tt>alignX (-1)</tt> moves the local origin to the left edge of
--   the envelope;</li>
--   <li><tt>align 1</tt> moves the local origin to the right edge;</li>
--   <li>any other argument interpolates linearly between these. For
--   example, <tt>alignX 0</tt> centers, <tt>alignX 2</tt> moves the origin
--   one "radius" to the right of the right edge, and so on.</li>
--   </ul>
alignX :: (Alignable a, V a ~ R2) => Double -> a -> a

-- | Like <a>alignX</a>, but moving the local origin vertically, with an
--   argument of <tt>1</tt> corresponding to the top edge and <tt>(-1)</tt>
--   corresponding to the bottom edge.
alignY :: (Alignable a, V a ~ R2) => Double -> a -> a

-- | Center the local origin along the X-axis.
centerX :: (Alignable a, V a ~ R2) => a -> a

-- | Center the local origin along the Y-axis.
centerY :: (Alignable a, V a ~ R2) => a -> a

-- | Center along both the X- and Y-axes.
centerXY :: (Alignable a, V a ~ R2) => a -> a

-- | Compute the width of an enveloped object.
width :: (Enveloped a, V a ~ R2) => a -> Double

-- | Compute the height of an enveloped object.
height :: (Enveloped a, V a ~ R2) => a -> Double

-- | Compute the width and height of an enveloped object.
size2D :: (Enveloped a, V a ~ R2) => a -> (Double, Double)

-- | Compute the size of an enveloped object as a <a>SizeSpec2D</a> value.
sizeSpec2D :: (Enveloped a, V a ~ R2) => a -> SizeSpec2D

-- | Compute the absolute x-coordinate range of an enveloped object in R2,
--   in the form (lo,hi). Return <tt>Nothing</tt> for objects with an empty
--   envelope.
extentX :: (Enveloped a, V a ~ R2) => a -> Maybe (Double, Double)

-- | Compute the absolute y-coordinate range of an enveloped object in R2,
--   in the form (lo,hi).
extentY :: (Enveloped a, V a ~ R2) => a -> Maybe (Double, Double)

-- | Compute the point at the center (in the x- and y-directions) of a
--   enveloped object. Return the origin for objects with an empty
--   envelope.
center2D :: (Enveloped a, V a ~ R2) => a -> P2

-- | A specification of a (requested) rectangular size.
data SizeSpec2D

-- | Specify an explicit width. The height should be determined
--   automatically (so as to preserve aspect ratio).
Width :: Double -> SizeSpec2D

-- | Specify an explicit height. The width should be determined
--   automatically (so as to preserve aspect ratio).
Height :: Double -> SizeSpec2D

-- | An explicit specification of a width and height.
Dims :: Double -> Double -> SizeSpec2D

-- | Absolute size: use whatever size an object already has; do not
--   rescale.
Absolute :: SizeSpec2D

-- | Create a size specification from a possibly-specified width and
--   height.
mkSizeSpec :: Maybe Double -> Maybe Double -> SizeSpec2D

-- | Uniformly scale any enveloped object so that it fits within the given
--   size.
sized :: (Transformable a, Enveloped a, V a ~ R2) => SizeSpec2D -> a -> a

-- | Uniformly scale an enveloped object so that it "has the same size as"
--   (fits within the width and height of) some other object.
sizedAs :: (Transformable a, Enveloped a, V a ~ R2, Enveloped b, V b ~ R2) => b -> a -> a

-- | Mark the origin of a diagram by placing a red dot 1/50th its size.
showOrigin :: (Renderable (Path R2) b, Backend b R2, Monoid' m) => QDiagram b R2 m -> QDiagram b R2 m

-- | Mark the origin of a diagram, with control over colour and scale of
--   marker dot.
showOrigin' :: (Renderable (Path R2) b, Backend b R2, Monoid' m) => OriginOpts -> QDiagram b R2 m -> QDiagram b R2 m
data OriginOpts
OriginOpts :: Colour Double -> Double -> Double -> OriginOpts
oColor :: OriginOpts -> Colour Double
oScale :: OriginOpts -> Double
oMinSize :: OriginOpts -> Double
showLabels :: (Renderable Text b, Backend b R2) => QDiagram b R2 m -> QDiagram b R2 Any


-- | A default diagram-adjustment implementation for two-dimensional
--   diagrams, useful for backend implementors.
module Diagrams.TwoD.Adjust

-- | Set default attributes of a 2D diagram (in case they have not been
--   set):
--   
--   <ul>
--   <li>Line width 0.01</li>
--   <li>Line color black</li>
--   <li>Font size 1</li>
--   <li>Line cap LineCapButt</li>
--   <li>line join miter</li>
--   <li>Miter limit 10</li>
--   </ul>
setDefault2DAttributes :: Semigroup m => QDiagram b R2 m -> QDiagram b R2 m

-- | Adjust the size and position of a 2D diagram to fit within the
--   requested size. The first two arguments specify a method for
--   extracting the requested output size from the rendering options, and a
--   way of updating the rendering options with a new (more specific) size.
adjustDiaSize2D :: Monoid' m => (Options b R2 -> SizeSpec2D) -> (SizeSpec2D -> Options b R2 -> Options b R2) -> b -> Options b R2 -> QDiagram b R2 m -> (Options b R2, QDiagram b R2 m)

-- | <tt>adjustDia2D</tt> provides a useful default implementation of the
--   <a>adjustDia</a> method from the <a>Backend</a> type class.
--   
--   As its first two arguments it requires a method for extracting the
--   requested output size from the rendering options, and a way of
--   updating the rendering options with a new (more specific) size.
--   
--   It then performs the following adjustments:
--   
--   <ul>
--   <li>Set default attributes (see <a>setDefault2DAttributes</a>)</li>
--   <li>Freeze the diagram in its final form</li>
--   <li>Scale and translate the diagram to fit within the requested size
--   (see <a>adjustDiaSize2D</a>)</li>
--   <li>Also return the actual adjusted size of the diagram.</li>
--   </ul>
adjustDia2D :: Monoid' m => (Options b R2 -> SizeSpec2D) -> (SizeSpec2D -> Options b R2 -> Options b R2) -> b -> Options b R2 -> QDiagram b R2 m -> (Options b R2, QDiagram b R2 m)

-- | Re-export <a>requiredScaleT</a> with the name <a>adjustSize</a> for
--   backwards compatibility.

-- | <i>Deprecated: Use Diagrams.TwoD.Size.requiredScaleT instead. </i>
adjustSize :: SizeSpec2D -> (Double, Double) -> Transformation R2

-- | <tt>requiredScale spec sz</tt> returns a scaling factor necessary to
--   make something of size <tt>sz</tt> fit the requested size
--   <tt>spec</tt>, without changing the aspect ratio. Hence an explicit
--   specification of both dimensions may not be honored if the aspect
--   ratios do not match; in that case the scaling will be as large as
--   possible so that the object still fits within the requested size.
requiredScale :: SizeSpec2D -> (Double, Double) -> Double


-- | A module to re-export most of the functionality of the diagrams core
--   and standard library.
module Diagrams.Prelude

-- | A functor with application, providing operations to
--   
--   <ul>
--   <li>embed pure expressions (<a>pure</a>), and</li>
--   <li>sequence computations and combine their results
--   (<a>&lt;*&gt;</a>).</li>
--   </ul>
--   
--   A minimal complete definition must include implementations of these
--   functions satisfying the following laws:
--   
--   <ul>
--   <li><i><i>identity</i></i> <tt><a>pure</a> <a>id</a> <a>&lt;*&gt;</a>
--   v = v</tt></li>
--   <li><i><i>composition</i></i> <tt><a>pure</a> (.) <a>&lt;*&gt;</a> u
--   <a>&lt;*&gt;</a> v <a>&lt;*&gt;</a> w = u <a>&lt;*&gt;</a> (v
--   <a>&lt;*&gt;</a> w)</tt></li>
--   <li><i><i>homomorphism</i></i> <tt><a>pure</a> f <a>&lt;*&gt;</a>
--   <a>pure</a> x = <a>pure</a> (f x)</tt></li>
--   <li><i><i>interchange</i></i> <tt>u <a>&lt;*&gt;</a> <a>pure</a> y =
--   <a>pure</a> (<a>$</a> y) <a>&lt;*&gt;</a> u</tt></li>
--   </ul>
--   
--   The other methods have the following default definitions, which may be
--   overridden with equivalent specialized implementations:
--   
--   <pre>
--   u <a>*&gt;</a> v = <a>pure</a> (<a>const</a> <a>id</a>) <a>&lt;*&gt;</a> u <a>&lt;*&gt;</a> v
--   u <a>&lt;*</a> v = <a>pure</a> <a>const</a> <a>&lt;*&gt;</a> u <a>&lt;*&gt;</a> v
--   </pre>
--   
--   As a consequence of these laws, the <a>Functor</a> instance for
--   <tt>f</tt> will satisfy
--   
--   <pre>
--   <a>fmap</a> f x = <a>pure</a> f <a>&lt;*&gt;</a> x
--   </pre>
--   
--   If <tt>f</tt> is also a <a>Monad</a>, it should satisfy
--   <tt><a>pure</a> = <a>return</a></tt> and <tt>(<a>&lt;*&gt;</a>) =
--   <a>ap</a></tt> (which implies that <a>pure</a> and <a>&lt;*&gt;</a>
--   satisfy the applicative functor laws).
class Functor f => Applicative (f :: * -> *)
pure :: Applicative f => a -> f a
(<*>) :: Applicative f => f (a -> b) -> f a -> f b
(*>) :: Applicative f => f a -> f b -> f b
(<*) :: Applicative f => f a -> f b -> f a

-- | Sequence actions, discarding the value of the first argument.
(*>) :: Applicative f => forall a b. f a -> f b -> f b

-- | Sequence actions, discarding the value of the second argument.
(<*) :: Applicative f => forall a b. f a -> f b -> f a

-- | An infix synonym for <a>fmap</a>.
(<$>) :: Functor f => (a -> b) -> f a -> f b

-- | Replace all locations in the input with the same value. The default
--   definition is <tt><a>fmap</a> . <a>const</a></tt>, but this may be
--   overridden with a more efficient version.
(<$) :: Functor f => forall a b. a -> f b -> f a

-- | Lift a function to actions. This function may be used as a value for
--   <a>fmap</a> in a <a>Functor</a> instance.
liftA :: Applicative f => (a -> b) -> f a -> f b

-- | Lift a binary function to actions.
liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c

-- | Lift a ternary function to actions.
liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d


-- | A simple Show-based diagrams backend, for testing purposes.
module Diagrams.Backend.Show

-- | Token for identifying this backend.
data ShowBackend
ShowBackend :: ShowBackend
renderTransf :: (Num (Scalar v), HasLinearMap v, Show (Scalar v)) => Transformation v -> Doc
renderMat :: Show a => [[a]] -> Doc
instance (Show v, OrderedField (Scalar v), InnerSpace v, HasLinearMap v) => Renderable (Path v) ShowBackend
instance (Show v, OrderedField (Scalar v), InnerSpace v, HasLinearMap v) => Renderable (Trail v) ShowBackend
instance (Show v, HasLinearMap v) => Renderable (Segment o v) ShowBackend
instance Monoid (Render ShowBackend v)
instance HasLinearMap v => Backend ShowBackend v
