-- 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 Diagrams.Prelude.
@package diagrams-lib
@version 0.7.1.1

-- | A cubic spline 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 x where A is
--   an n by n matrix with bs as the main
--   diagonal and as the diagonal below and cs the
--   diagonal above. See:
--   http://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm
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
--   http://en.wikipedia.org/wiki/Sherman-Morrison_formula. This
--   code is based on Numerical Recpies in C's cyclic
--   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 '(&)' operator from the
--   lens package, this module is not re-exported by
--   Diagrams.Prelude. 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 Coordinates class can be
--   constructed using & (for example, a three-dimensional
--   vector could be constructed by 1 & 6 & 3), and
--   deconstructed using coords. A common pattern is to use
--   coords in conjunction with the ViewPatterns extension,
--   like so:
--   
--   
--   foo :: Vector3 -> ...
--   foo (coords -> x :& y :& z) = ...
--   
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
--   PolygonOpts in Diagrams.TwoD.Shapes for an example).
--   Such record types are made instances of the Default class,
--   which provides a single record structure (def) collecting the
--   "default" arguments to the function. with is a synonym for
--   def, which provides nice-looking syntax for simulating
--   optional, named arguments in Haskell. For example,
--   
--   
--   polygon with {sides = 7, edgeSkip = 2}
--   
--   
--   calls the polygon function with a single argument (note that
--   record update binds more tightly than function application!), namely,
--   with (the record of default arguments) where the sides
--   and edgeSkip fields have been updated.
with :: Default d => d

-- | applyAll 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, applyAll [f1, f2, f3] a == f1 . f2 . f3 $ a.
applyAll :: [a -> a] -> a -> a

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

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

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

-- | A value of Proxy a carries no information; it's used only to
--   fix the type a.
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 balanced fold over a list.
--   For example,
--   
--   
--   foldB (+) z [a,b,c,d,e,f] == ((a+b) + (c+d)) + (e+f)
--   
foldB :: (a -> a -> a) -> a -> [a] -> a

-- | Exact solving of low-degree (n <= 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.
--   
--   
--   
- To construct a vector, use r2, or & (from
--   Diagrams.Coordinates):
--   
--   
--   
--   r2 (3,4) :: R2
--   3 & 4    :: R2
--   
--   
--   Note that Diagrams.Coordinates is not re-exported by
--   Diagrams.Prelude and must be explicitly imported.
--   
--   
--   
- To construct the vector from the origin to a point p, use
--   p .-. origin.
--   
- To convert a vector v into the point obtained by
--   following v from the origin, use origin .+^
--   v.
--   
- To convert a vector back into a pair of components, use
--   unv2 or coords (from Diagrams.Coordinates).
--   These are typically used in conjunction with the ViewPatterns
--   extension:
--   
--   
--   
--   foo (unr2 -> (x,y)) = ...
--   foo (coords -> x :& y) = ...
--   
data R2

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

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

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

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

-- | Convert a 2D point back into a pair of coordinates. See also
--   coords.
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 Turn, 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 fullTurn, 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 fromDirection.
e :: Angle a => a -> R2

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

-- | leftTurn v1 v2 tests whether the direction of v2 is
--   a left turn from v1 (that is, if the direction of v2
--   can be obtained from that of v1 by adding an angle 0 <=
--   theta <= 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 SizeSpec2D 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 Nothing 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

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

-- | requiredScale spec sz returns a scaling factor necessary to
--   make something of size sz fit the requested size
--   spec, 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 Data.AffineSpace and Diagrams.Coordinates.
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 n points is their sum divided by
--   n.
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,
--   http://hackage.haskell.org/package/graphics-drawingcombinators.
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 True points in a diagram (i.e.
--   points "inside" the diagram); False points will be set to
--   mempty.
value :: Monoid m => m -> QDiagram b v Any -> QDiagram b v m

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

-- | Set all the query values of a diagram to False.
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. AName is just an existential wrapper around
--   things which are Typeable, Ord and Show.
data AName :: *

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

-- | Class for those types which can be used as names. They must support
--   Typeable (to facilitate extracting them from existential
--   wrappers), Ord (for comparison and efficient storage) and
--   Show.
class (Typeable a, Ord a, Show a) => IsName a
toName :: IsName a => a -> Name

-- | Convenient operator for writing qualified names with atomic components
--   of different types. Instead of writing toName a1 <> toName
--   a2 <> toName a3 you can just write a1 .> a2 .>
--   a3.
(.>) :: (IsName a1, IsName a2) => a1 -> a2 -> Name

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

-- | A Subdiagram represents a diagram embedded within the context
--   of a larger diagram. Essentially, it consists of a diagram paired with
--   any accumulated information from the larger context (transformations,
--   attributes, etc.).
data Subdiagram b v 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 pointDiagram (with no
--   content and a point envelope) treated as a subdiagram with local
--   origin at the given point. Note this is not the same as
--   mkSubdiagram . pointDiagram, which would result in a
--   subdiagram with local origin at the parent origin, rather than at the
--   given point.
subPoint :: (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.
--   getSub 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 with respect to 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 SubMap is a map associating names to subdiagrams. There can
--   be multiple associations for any given name.
data SubMap b v m :: * -> * -> * -> *

-- | Construct a SubMap 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 (e.g. 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 Maybe.
data BoundingBox v

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

-- | Create a bounding box from a point that is component-wise
--   (<=) than the other. If this is not the case, then
--   mempty 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 BoundingBox. If
--   it's empty, then the result is also mempty.
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 strictly 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 strictly 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 strictly 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 mappend.
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 Nothing 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 e.g.
--   Diagrams.TwoD.Transform.
module Diagrams.Transform

-- | General (affine) transformations, represented by an invertible linear
--   map, its transpose, and a vector representing a translation
--   component.
--   
--   By the transpose of a linear map we mean simply the linear map
--   corresponding to the transpose of the map's matrix representation. For
--   example, any scale is its own transpose, since scales are represented
--   by matrices with zeros everywhere except the diagonal. The transpose
--   of a rotation is the same as its inverse.
--   
--   The reason we need to keep track of transposes is because it turns out
--   that when transforming a shape according to some linear map L, the
--   shape's normal vectors transform according to L's inverse
--   transpose. This is exactly what we need when transforming bounding
--   functions, which are defined in terms of perpendicular (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 t 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 moveOriginTo, i.e. we
--   should have
--   
--   
--   moveTo (origin .^+ v) === moveOriginTo (origin .^- v)
--   
--   
--   For types which are also Transformable, this is essentially
--   the same as translate, i.e.
--   
--   
--   moveTo (origin .^+ v) === translate v
--   
moveTo :: HasOrigin t => Point (V t) -> t -> t

-- | A flipped variant of moveTo, provided for convenience. Useful
--   when writing a function which takes a point as an argument, such as
--   when using withName and friends.
place :: 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. conjugate t1 t2 is
--   the transformation which performs first t1, then t2,
--   then the inverse of t1.
conjugate :: HasLinearMap v => Transformation v -> Transformation v -> Transformation v

-- | Carry out some transformation "under" another one: f
--   `<a>under</a>` t first applies t, then f, then
--   the inverse of t. For example, scaleX 2
--   `<a>under</a>` rotationBy (-1/8 :: Turn) is the
--   transformation which scales by a factor of 2 along the diagonal line y
--   = x.
--   
--   Note that
--   
--   
--   (transform t2) under t1 == transform (conjugate t1 t2)
--   
--   
--   for all transformations t1 and t2.
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 Transformable instead of
--   having a separate class for HasOrigin; indeed, for types which
--   are instances of both we should have the identity
--   
--   
--   moveOriginTo (origin .^+ v) === translate (negateV v)
--   
--   
--   The reason is that some things (e.g. vectors, Trails) 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 rotate.
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
--   Angle. For example, rotate (1/4 :: Turn),
--   rotate (tau/4 :: Rad), and rotate (90 ::
--   Deg) all represent the same transformation, namely, a
--   counterclockwise rotation by a right angle. To rotate about some point
--   other than the local origin, see rotateAbout.
--   
--   Note that writing rotate (1/4), 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 rotateBy,
--   which is specialized to take a Turn argument.
rotate :: (Transformable t, V t ~ R2, Angle a) => a -> t -> t

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

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

-- | rotateAbout p is like rotate, except it rotates around
--   the point p 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 scale.
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 scale.
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

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

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

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

-- | scaleUToY h scales a diagram uniformly by whatever
--   factor required to make its height h. scaleUToY
--   should not be applied to diagrams with a height of 0, such as
--   hrule.
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

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

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

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

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

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

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

-- | The ScaleInv wrapper creates two-dimensional
--   scale-invariant 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 non-uniform
--   scales (e.g. scaleX 2 . scaleY 3) 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.e. the local origin) and a unit vector (indicating the
--   direction) along with a scale-invariant object. A
--   transformation to be applied is decomposed into rotational and
--   translational components as follows:
--   
--   
--   
- 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.
--   
- The vector from the location to the image of the location under
--   the transformation determines the translational component.
--   
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 empty 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" (e.g. 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,
--   e.g. segments and trails.
module Diagrams.Parametric

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

-- | Codomain of parametric classes. This is usually either (V p),
--   for relative vector results, or (Point (V p)), 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 [0,1].
--   
--   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 splitAtParam or section.
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 AdjustOpts.
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.e. things with a concrete location:
--   intuitively, Located a ~ (a, Point). Wrapping a
--   translationally invariant thing (e.g. a Segment or
--   Trail) in Located pins it down to a particular
--   location and makes it no longer translationally invariant.
module Diagrams.Located

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

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

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

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

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

-- | Located is not a Functor, 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.
--   mapLoc has an extra constraint specifying that the vector space
--   must stay the same.
--   
--   (Technically, one can say that for every vector space v,
--   Located is a little-f (endo)functor on the category of types
--   with associated vector space v; but that is not covered by
--   the standard Functor 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 segment is a translation-invariant, atomic path. Currently,
--   there are two types: linear (i.e. just a straight line to the
--   endpoint) and cubic Bézier curves (i.e. 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
--   Diagrams.Trail, Diagrams.TrailLike, and
--   Diagrams.Path 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 offset of a segment is the vector from its starting point
--   to its end. The offset for an open segment is determined by the
--   context, i.e. its endpoint is not fixed. The offset for a
--   closed segment is stored explicitly, i.e. 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 not the same as the
--   length of the curve itself; for that, see arcLength.
segOffset :: Segment Closed v -> v

-- | The atomic constituents of the concrete representation currently used
--   for trails are segments, currently limited to single straight
--   lines or cubic Bézier curves. Segments are translationally
--   invariant, 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

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

-- | bezier3 c1 c2 x 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
--   c1, c2, and x.
bezier3 :: v -> v -> v -> Segment Closed v

-- | bézier3 is the same as bezier3, 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

-- | FixedSegments are like Segments except that they have
--   absolute locations. FixedSegment v is isomorphic to
--   Located (Segment Closed v), as witnessed by mkFixedSeg
--   and fromFixedSeg, but FixedSegment 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 FixedSegment from a located Segment.
mkFixedSeg :: AdditiveGroup v => Located (Segment Closed v) -> FixedSegment v

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

-- | A type to track the count of segments in a Trail.
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 10e-6. 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

-- | SegMeasure 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
--   
--   
--   
--   {-# LANGUAGE GADTs #-}
--   
--   import Diagrams.TwoD.Curvature
--   import Data.Monoid.Inf
--   import Diagrams.Coordinates
--   
--   segmentA = Cubic (12 & 0) (8 & 10) (OffsetClosed (20 & 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
--           <> 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) & 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
--                    <> stroke (origin ~~ (origin .+^ vpr)))
--                     # moveTo (origin .+^ atParam bez t)
--         where
--           vpr = r2 (normalized vp ^* r)
--   
curvature :: Segment Closed R2 -> Double -> PosInf Double

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

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

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

-- | This module defines trails, 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:
--   
--   
--   
- The TrailLike class (Diagrams.TrailLike) exposes a
--   generic API for building a wide range of things out of trails.
--   
- Paths (Diagrams.Path) are collections of
--   Located (Diagrams.Located) trails.
--   
- Trails are composed of Segments (see
--   Diagrams.Segment), though most users should not need to work
--   with segments directly.
--   
module Diagrams.Trail

-- | Intuitively, a trail is a single, continuous path through space.
--   However, a trail has no fixed starting point; it merely specifies
--   how to move through space, not where. 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 translation-invariant; applying a translation to a
--   trail has no effect.
--   
--   A Located Trail, 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
--   Diagrams.Located module for help working with Located
--   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 Located trail is
--   a continuous function from [0,1] to points in some
--   affine space.)
--   
--   There are two types of trails:
--   
--   
--   
- 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 drawn 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 Monoid instance where
--   mappend corresponds to concatenation, i.e. chaining
--   one line after the other.
--   
- 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 Monoid instance.
--   
--   
--   To convert between lines and loops, see glueLine,
--   closeLine, and cutLoop.
--   
--   To construct trails, see emptyTrail, trailFromSegments,
--   trailFromVertices, trailFromOffsets, and friends. You
--   can also get any type of trail from any function which returns a
--   TrailLike (e.g. functions in
--   Diagrams.TwoD.Shapes, and many others; see
--   Diagrams.TrailLike).
--   
--   To extract information from trails, see withLine,
--   isLoop, trailSegments, trailOffsets,
--   trailVertices, 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 glueLine to turn it into a loop.
--   
--   
--   
--   import Diagrams.Coordinates
--   glueLineEx = pad 1.1 . hcat' with {sep = 1}
--     $ [almostClosed # strokeLine, almostClosed # glueLine # strokeLoop]
--   
--   almostClosed :: Trail' Line R2
--   almostClosed = fromOffsets [2 & (-1), (-3) & (-0.5), (-2) & 1, 1 & 0.5]
--   
--   
--   glueLine is left inverse to cutLoop, that is,
--   
--   
--   glueLine . cutLoop === id
--   
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.
--   
--   closeLine does not have any particularly nice theoretical
--   properties, but can be useful e.g. 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 glueLine, one would first have to
--   duplicate the initial vertex, like
--   
--   
--   glueLine . lineFromVertices $ ps ++ [head ps]
--   
--   
--   Using closeLine, however, one can simply
--   
--   
--   closeLine . lineFromVertices $ ps
--   
--   
--   
--   
--   closeLineEx = pad 1.1 . centerXY . hcat' with {sep = 1}
--     $ [almostClosed # strokeLine, almostClosed # closeLine # strokeLoop]
--   
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.
--   
--   cutLoop is right inverse to glueLine, that is,
--   
--   
--   glueLine . cutLoop === id
--   
cutLoop :: (InnerSpace v, OrderedField (Scalar v)) => Trail' Loop v -> Trail' Line v

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

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

-- | Convert a line into a Trail. This is the same as
--   wrapTrail, 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 Trail. This is the same as
--   wrapTrail, 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 Trail, 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 Trail 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 cutLoop, the
--   transformation applied, and then glued back into a loop with
--   glueLine. That is,
--   
--   
--   onLine f === onTrail f (glueLine . f . cutLoop)
--   
--   
--   Note that there is no corresponding onLoop 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

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

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

-- | cutTrail is a variant of cutLoop for Trail; it
--   is the is the identity on lines and performs cutLoop 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 emptyLine.
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 v,
--   
--   
--   lineFromVertices === lineFromVertices . translate v
--   
--   
--   If you want to retain the position information, you should instead use
--   the more general fromVertices function to construct, say, a
--   Located (Trail' Line v) or a
--   Located (Trail v).
--   
--   
--   
--   import Diagrams.Coordinates
--   lineFromVerticesEx = pad 1.1 . centerXY . strokeLine
--     $ lineFromVertices [origin, 0 & 1, 1 & 2, 5 & 1]
--   
lineFromVertices :: (InnerSpace v, OrderedField (Scalar v)) => [Point v] -> Trail' Line v

-- | trailFromVertices === wrapTrail .
--   lineFromVertices, for conveniently constructing a
--   Trail instead of a Trail' Line.
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 fromOffsets.
--   
--   
--   
--   import Diagrams.Coordinates
--   lineFromOffsetsEx = strokeLine $ lineFromOffsets [ 2 & 1, 2 & (-1), 2 & 0.5 ]
--   
lineFromOffsets :: (InnerSpace v, OrderedField (Scalar v)) => [v] -> Trail' Line v

-- | trailFromOffsets === wrapTrail .
--   lineFromOffsets, for conveniently constructing a
--   Trail instead of a Trail' Line.
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

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

-- | A generic eliminator for Trail', 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 Trail, 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 Trail 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 cutLoop. That is,
--   
--   
--   withLine f === withTrail f (f . cutLoop)
--   
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 cutLoop 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
--   
--   
--   trailOffset === sumV . trailOffsets
--   
--   
--   but is more efficient.
--   
--   
--   
--   trailOffsetEx = (strokeLine almostClosed <> showOffset) # centerXY # pad 1.1
--     where showOffset = fromOffsets [trailOffset (wrapLine almostClosed)]
--                      # stroke # lc red # lw 0.05
--   
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 loopOffset 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 not be repeated at the end. If
--   you want this behavior, you can use cutTrail to make the loop
--   into a line first, which happens to repeat the same vertex at the
--   start and end, e.g. with trailVertices . mapLoc
--   cutTrail.
--   
--   Note that it does not make sense to ask for the vertices of a
--   Trail by itself; if you want the vertices of a trail with the
--   first vertex at, say, the origin, you can use trailVertices .
--   (at origin).
trailVertices :: (InnerSpace v, OrderedField (Scalar v)) => Located (Trail v) -> [Point v]

-- | Extract the vertices of a concretely located line. See
--   trailVertices 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 trailVertices
--   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).
--   reverseTrail is an involution, that is,
--   
--   
--   reverseTrail . reverseTrail === id
--   
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.
--   reverseLocTrail is an involution, i.e.
--   
--   
--   reverseLocTrail . reverseLocTrail === id
--   
reverseLocTrail :: (InnerSpace v, OrderedField (Scalar v)) => Located (Trail v) -> Located (Trail v)

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

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

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

-- | Reverse a concretely located loop. See reverseLocTrail. 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 SegTree 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 (e.g., 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
--   SegMeasure (e.g. SegMeasure itself,
--   Segment, SegTree, Trails...)
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 SegMeasure.
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 TrailLike class abstracts over anything which can be
--   constructed from a concretely located Trail, including lines,
--   loops, trails, paths, vertex lists, and diagrams.
module Diagrams.TrailLike

-- | A type class for trail-like things, i.e. things which can be
--   constructed from a concretely located Trail. Instances include
--   lines, loops, trails, paths, lists of vertices, two-dimensional
--   Diagrams, and Located variants of all the above.
--   
--   Usually, type variables with TrailLike constraints are used as
--   the output types of functions, like
--   
--   
--   foo :: (TrailLike t) => ... -> t
--   
--   
--   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 trailLike directly; more typically, one would use one of
--   the provided functions like fromOffsets, fromVertices,
--   fromSegments, or ~~.
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 alignment of an object refers to the position of its local
--   origin with respect to its envelope. This module defines the
--   Alignable class for things which can be aligned, as well as a
--   default implementation in terms of HasOrigin and
--   Enveloped, 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 alignBy for types with
--   HasOrigin and Enveloped instances.
alignByDefault :: (HasOrigin a, Enveloped a, Num (Scalar (V a))) => V a -> Scalar (V a) -> a -> a

-- | align v aligns an enveloped object along the edge in the
--   direction of v. That is, it moves the local origin in the
--   direction of v 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

-- | center v centers an enveloped object along the direction of
--   v.
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 paths, which are collections of concretely
--   located Trails. Many drawing systems (cairo, svg, ...) have a
--   similar notion of "path". Note that paths with multiple trails are
--   necessary for being able to draw e.g. filled objects with holes
--   in them.
module Diagrams.Path

-- | A path is a (possibly empty) list of Located
--   Trails. Hence, unlike trails, paths are not translationally
--   invariant, and they form a monoid under superposition (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
--   trailLike, 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 trailVertices).
pathVertices :: (InnerSpace v, OrderedField (Scalar v)) => Path v -> [[Point v]]

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

-- | Compute the centroid of a path (i.e. 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 FixedSegments.
fixPath :: (InnerSpace v, OrderedField (Scalar v)) => Path v -> [[FixedSegment v]]

-- | Scale a path using its centroid (see pathCentroid) 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
--   explodeTrail).
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
--   True, 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

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

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

-- | pad s "pads" a diagram, expanding its envelope by a factor of
--   s (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., centerXY for 2D diagrams) before applying pad.
pad :: (Backend b v, InnerSpace v, OrderedField (Scalar v), Monoid' m) => Scalar v -> QDiagram b v m -> QDiagram b v m

-- | extrudeEnvelope v d 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

-- | intrudeEnvelope v d 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 
--   diameter v d < 0 .
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 mappend on diagrams, designed to be
--   used infix (to help remember which diagram goes on top of which when
--   combining them, namely, the first on top of the second).
atop :: (HasLinearMap v, OrderedField (Scalar v), InnerSpace v, Semigroup m) => QDiagram b v m -> QDiagram b v m -> QDiagram b v m

-- | beneath is just a convenient synonym for flip
--   atop; that is, d1 `beneath` d2 is the diagram
--   with d2 superimposed on top of d1.
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.e. 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).
--   
--   
--   
--   besideEx = beside (r2 (20,30))
--                     (circle 1 # fc orange)
--                     (circle 1.5 # fc purple)
--              # showOrigin
--              # centerXY # pad 1.1
--   
--   
--   Note that beside v is associative, so objects under
--   beside v form a semigroup for any given vector v. In
--   fact, they also form a monoid: mempty is clearly a right
--   identity (beside v d1 mempty === d1), and there should also
--   be a special case to make it a left identity, as described above.
--   
--   In older versions of diagrams, beside 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 beside' denotes the
--   old semantics,
--   
--   
--   beside' v x1 x2 = beside v (x1 # align v) x2
--   
--   
--   To get something like beside v x1 x2 whose local origin is
--   identified with that of x2 instead of x1, use
--   beside (negateV v) x2 x1.
beside :: (Juxtaposable a, Semigroup a) => V a -> a -> a -> a

-- | appends x ys appends each of the objects in ys to
--   the object x in the corresponding direction. Note that each
--   object in ys is positioned beside x without
--   reference to the other objects in ys, so this is not the same
--   as iterating beside.
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

-- | cat v positions a list of objects so that their local origins
--   lie along a line in the direction of v. 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 cat', 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 cat, but taking an extra CatOpts arguments allowing
--   the user to specify
--   
--   
--   
- The spacing method: catenation (uniform spacing between envelopes)
--   or distribution (uniform spacing between local origins). The default
--   is catenation.
--   
- The amount of separation between successive diagram
--   envelopes/origins (depending on the spacing method). The default is
--   0.
--   
--   
--   CatOpts is an instance of Default, so with may be
--   used for the second argument, as in cat' (1,2) with {sep =
--   2}.
--   
--   Note that cat' v with {catMethod = Distrib} === mconcat
--   (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 cat'.
data CatOpts v
CatOpts :: CatMethod -> Scalar v -> Proxy v -> CatOpts v

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

-- | How much separation should be used between successive diagrams
--   (default: 0)? When catMethod = Cat, this is the distance
--   between envelopes; when catMethod = Distrib, this is
--   the distance between origins.
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 envelopes will be consistent; the distance
--   between origins 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
--   origins 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
--   Diagrams.Core.Envelope for internal implementation details.
module Diagrams.Envelope

-- | Every diagram comes equipped with an envelope. What is an
--   envelope?
--   
--   Consider first the idea of a bounding box. A bounding box
--   expresses the distance to a bounding plane in every direction parallel
--   to an axis. That is, a bounding box can be thought of as the
--   intersection of a collection of half-planes, two perpendicular to each
--   axis.
--   
--   More generally, the intersection of half-planes in every
--   direction would give a tight "bounding region", or convex hull.
--   However, representing such a thing intensionally would be impossible;
--   hence bounding boxes are often used as an approximation.
--   
--   An envelope is an extensional representation of such a
--   "bounding region". Instead of storing some sort of direct
--   representation, we store a function which takes a direction as
--   input and gives a distance to a bounding half-plane as output. The
--   important point is that envelopes can be composed, and transformed by
--   any affine transformation.
--   
--   Formally, given a vector v, the envelope computes a scalar
--   s such that
--   
--   
--   
- for every point u inside the diagram, if the projection
--   of (u - origin) onto v is s' *^ v, then
--   s' <= s.
--   
- s is the smallest such scalar.
--   
--   
--   There is also a special "empty envelope".
--   
--   The idea for envelopes came from Sebastian Setzer; see
--   http://byorgey.wordpress.com/2009/10/28/collecting-attributes/#comment-2030.
--   See also Brent Yorgey, Monoids: Theme and Variations, published
--   in the 2012 Haskell Symposium:
--   http://www.cis.upenn.edu/~byorgey/pub/monoid-pearl.pdf; video:
--   http://www.youtube.com/watch?v=X-8NCkD2vOw.
data Envelope v :: * -> *

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

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

-- | pad s "pads" a diagram, expanding its envelope by a factor of
--   s (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., centerXY for 2D diagrams) before applying pad.
pad :: (Backend b v, InnerSpace v, OrderedField (Scalar v), Monoid' m) => Scalar v -> QDiagram b v m -> QDiagram b v m

-- | extrudeEnvelope v d 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

-- | intrudeEnvelope v d 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 
--   diameter v d < 0 .
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 Nothing 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 Nothing 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 Diagrams.Core.Trace for internal implementation
--   details.
module Diagrams.Trace

-- | Every diagram comes equipped with a trace. Intuitively, the
--   trace for a diagram is like a raytracer: given a line (represented as
--   a base point and a direction), 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
--   furthest intersection instead of the closest, 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 v and the returned scalar is
--   s, the distance from the base point to the intersection is
--   given by s * magnitude v.
data Trace v :: * -> *

-- | Traced 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 Nothing 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 Nothing if there is no
--   intersection in the given direction.
traceP :: Traced a => Point (V a) -> V a -> a -> Maybe (Point (V a))

-- | Like traceV, 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 traceP, 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 boundaryFromMay.
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 Nothing if there is no such
--   point.
boundaryFromMay :: (HasLinearMap v, Ord (Scalar v)) => Subdiagram b v m -> v -> Maybe (Point v)

-- | A cubic spline is a smooth, connected sequence of cubic curves
--   passing through a given sequence of points. This module provides the
--   cubicSpline 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
--   Diagrams.CubicSpline.Internal.
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.
--   
--   
--   
--   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))
--                <> cubicSpline closed pts # lw 0.05
--   cubicSplineEx = (mkPath False ||| strutX 2 ||| mkPath True)
--                 # centerXY # pad 1.1
--   
--   
--   For more information, see
--   http://mathworld.wolfram.com/CubicSpline.html.
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 s and an end angle e,
--   arc s e 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 r, a start angle s and an end angle
--   e, arc' r s e is the path of a radius
--   (abs r) 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 arc but clockwise.
arcCW :: (Angle a, TrailLike t, V t ~ R2) => a -> a -> t

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

-- | bezierFromSweep s constructs a series of Cubic
--   segments that start in the positive y direction and sweep counter
--   clockwise through s radians. If s is negative, it
--   will start in the negative y direction and sweep clockwise. When
--   s 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

-- | ellipse e constructs an ellipse with eccentricity e
--   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

-- | ellipseXY x y creates an axis-aligned ellipse, centered at
--   the origin, with radius x along the x-axis and radius
--   y 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 stroke', 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 stroke. The solution is to give a type
--   signature to expressions involving stroke, 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 stroke that takes an extra record of options to
--   customize its behavior. In particular:
--   
--   
--   
- Names can be assigned to the path's vertices
--   
--   
--   StrokeOpts is an instance of Default, so stroke'
--   with { ... } syntax may be used.
stroke' :: (Renderable (Path R2) b, IsName a) => StrokeOpts a -> Path R2 -> Diagram b R2

-- | A composition of stroke and pathFromTrail 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 stroke and hence of strokeT as
--   well. The solution is to give a type signature to expressions
--   involving strokeT, 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 stroke' and pathFromTrail 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 strokeT and wrapLine for conveniently
--   converting a line directly into a diagram.
strokeLine :: Renderable (Path R2) b => Trail' Line R2 -> Diagram b R2

-- | A composition of strokeT and wrapLoop 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 Located Trail
--   directly into a diagram; strokeLocT = stroke . trailLike.
strokeLocT :: Renderable (Path R2) b => Located (Trail R2) -> Diagram b R2

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

-- | A convenience function for converting a Located loop directly
--   into a diagram; strokeLocLoop = stroke . trailLike . mapLoc
--   wrapLoop.
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 winding number.
--   See http://en.wikipedia.org/wiki/Nonzero-rule.
Winding :: FillRule

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

-- | Extract the fill rule from a FillRuleA 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.
--   StrokeOpts is an instance of Default, so a
--   StrokeOpts records can be created using with {
--   ... } 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 list of lists 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 Winding. NOTE: for now, this only affects the
--   resulting diagram's Query, not how it will be drawn! To
--   set the fill rule determining how it is to be drawn, use the
--   fillRule function.
queryFillRule :: StrokeOpts a -> FillRule

-- | Test whether the given point is inside the given (closed) path, by
--   testing whether the point's winding number is nonzero. Note
--   that False is always returned for open 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 False is always returned for
--   open paths, regardless of the number of crossings.
isInsideEvenOdd :: P2 -> Path R2 -> Bool

-- | Clip tracks the accumulated clipping paths applied to a
--   diagram. Note that the semigroup structure on Clip 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:
--   
--   
--   
- Only the parts of the diagram which lie in the interior of the
--   path will be drawn.
--   
- The envelope of the diagram is unaffected.
--   
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.
--   
--   
--   
- The first argument is a list of central angles from
--   each vertex to the next.
--   
- The second argument is a list of radii from the origin to
--   each successive vertex.
--   
--   
--   To construct an n-gon, use a list of n-1 angles and
--   n radii. Extra angles or radii are ignored.
--   
--   Cyclic polygons (with all vertices lying on a circle) can be
--   constructed using a second argument of (repeat r).
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 centroid of its vertices.
--   
--   
--   
- The first argument is a list of vertex angles,
--   giving the angle at each vertex from the previous vertex to the next.
--   The first angle in the list is the angle at the second vertex;
--   the first edge always starts out heading in the positive y direction
--   from the first vertex.
--   
- The second argument is a list of distances between successive
--   vertices.
--   
--   
--   To construct an n-gon, use a list of n-2 angles and
--   n-1 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 horizontally, so the bottommost edge is parallel to the
--   x-axis.
OrientH :: PolyOrientation

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

-- | Orient so some edge is facing in the
--   direction of, 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 PolygonOpts for more information.
polyTrail :: PolygonOpts -> Located (Trail R2)

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

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

-- | Generate a transformation to orient a trail. orient v t
--   generates the smallest rotation such that one of the segments adjacent
--   to the vertex furthest in the direction of v is perpendicular
--   to v.
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 n means that edges will connect every
--   nth vertex.
StarSkip :: Int -> StarOpts

-- | Create a generalized star polygon. The StarOpts
--   are used to determine in which order the given vertices should be
--   connected. The intention is that the second argument of type
--   [P2] could be generated by a call to polygon,
--   regPoly, or the like, since a list of vertices is
--   TrailLike. But of course the list can be generated any way you
--   like. A Path R2 is returned (instead of any
--   TrailLike) 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

-- | orbits f n computes the graph of f on the integers
--   mod n.
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.
--   
--   
--   
--   hruleEx = vcat' with {sep = 0.2} (map hrule [1..5])
--           # centerXY # pad 1.1
--   
hrule :: (TrailLike t, V t ~ R2) => Double -> t

-- | Create a centered vertical (T-B) line of the given length.
--   
--   
--   
--   vruleEx = hcat' with {sep = 0.2} (map vrule [1, 1.2 .. 2])
--           # centerXY # pad 1.1
--   
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 length of the sides. (Compare to the
--   polygon function with a PolyRegular option, which
--   produces polygons of a given radius).
--   
--   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 triangle, 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

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

-- | roundedRect w h r generates a closed trail, or closed path
--   centered at the origin, of an axis-aligned rectangle with width
--   w, height h, and circular rounded corners of radius
--   r. If r is negative the corner will be cut out in a
--   reverse arc. If the size of r is larger than half the smaller
--   dimension of w and h, 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
--   roundedRect' instead.
--   
--   
--   
--   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 }
--     ]
--   
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

-- | roundedRect' works like roundedRect but allows you
--   to set the radius of each corner indivually, using
--   RoundedRectOpts. 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
--   Diagrams.Align 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. map
--   alignTop), and then put them together with their local
--   origins along a horizontal line (using e.g. hcat from
--   Diagrams.TwoD.Combinators).
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

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

-- | Like alignX, but moving the local origin vertically, with an
--   argument of 1 corresponding to the top edge and (-1)
--   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 Active (from the
--   active package). In particular, this module defines
--   
--   
--   
- An instance of V for Active: V
--   (Active a) = V a
--   
- HasOrigin, Transformable, and HasStyle
--   instances for Active which all work pointwise.
--   
- A TrailLike instance for Active p where
--   p is also TrailLike, which simply lifts a pathlike
--   thing to a constant active value.
--   
- A Juxtaposable instance for Active a where
--   a is also Juxtaposable. An active value can be
--   juxtaposed against another by doing the juxtaposition pointwise over
--   time. The era of juxtapose v a1 a2 will be the same as the
--   era of a2, unless a2 is constant, in which case it
--   will be the era of a1. (Note that juxtapose v a1 a2
--   and liftA2 (juxtapose v) a1 a2 therefore have different
--   semantics: the second is an active value whose era is the
--   combination of the eras of a1 and a2).
--   
- An Alignable instance for Active a where
--   a is also Alignable; the active value is aligned
--   pointwise over time.
--   
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 active package, which defines the Active
--   type.
--   
--   XXX more documentation and examples should go here
module Diagrams.Animation

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

-- | A value of type Animation b v is an animation (a time-varying
--   diagram with start and end times) in vector space v that can
--   be rendered by backspace b.
--   
--   Note that Animation is actually a synonym for
--   QAnimation where the type of the monoidal annotations has
--   been fixed to Any (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, e.g. 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
--   |||.
--   
--   By default, 30 samples per time unit are used; to adjust this number
--   see animEnvelope'.
--   
--   See also animRect 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 animEnvelope, 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

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

-- | Like animRect, 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 attributes 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 semigroup structure, that is,
--   an associative binary operation for combining two attributes into one.
--   Unless otherwise noted, all the attributes defined here use the
--   Last 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 Color type class encompasses color representations which
--   can be used by the Diagrams library. Instances are provided for both
--   the Colour and AlphaColour types from the
--   Data.Colour library.
class Color c
toAlphaColour :: Color c => c -> AlphaColour Double

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

-- | The color with which lines (strokes) are drawn. Note that child colors
--   always override parent colors; that is, lineColor c1 .
--   lineColor c2 $ d is equivalent to lineColor c2
--   $ d. More precisely, the semigroup structure on line color
--   attributes is that of Last.
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 Colour or
--   AlphaColour), but this can sometimes create problems for type
--   inference, so the lc and lcA variants are provided with
--   more concrete types.
lineColor :: (Color c, HasStyle a) => c -> a -> a

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

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

-- | A synonym for lineColor, specialized to AlphaColour
--   Double (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, fillColor c1 .
--   fillColor c2 $ d is equivalent to lineColor c2
--   $ d. More precisely, the semigroup structure on fill color
--   attributes is that of Last.
data FillColor
getFillColor :: FillColor -> SomeColor

-- | Set a "recommended" fill color, to be used only if no explicit calls
--   to fillColor (or fc, or fcA) 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 Colour or AlphaColour), but
--   this can sometimes create problems for type inference, so the
--   fc and fcA variants are provided with more concrete
--   types.
fillColor :: (Color c, HasStyle a) => c -> a -> a

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

-- | A synonym for fillColor, specialized to AlphaColour
--   Double (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
--   Opacity attribute. The opacity is a value between 1
--   (completely opaque, the default) and 0 (completely transparent).
--   Opacity is multiplicative, that is, opacity o1 .
--   opacity o2 === opacity (o1 * o2). In other words,
--   for example, opacity 0.8 means "decrease this diagram's
--   opacity to 80% of its previous opacity".
data Opacity
getOpacity :: Opacity -> Double

-- | Multiply the opacity (see Opacity) by the given value. For
--   example, opacity 0.8 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.

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

-- | The width of lines. By default, the line width is measured with
--   respect to the final 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 freeze
--   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 LineWidth attribute.
lineWidthA :: HasStyle a => LineWidth -> a -> a

-- | A convenient synonym for lineWidth.
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 LineJoinMiter 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 LineJoinMiter.
lineMiterLimit :: HasStyle a => Double -> a -> a

-- | Apply a LineMiterLimit 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 Diagrams.Combinators.
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
--   
--   
--    c
--   ===
--    d
--   
--   
--   to place c above d. The local origin of the
--   resulting combined diagram is the same as the local origin of the
--   first. (===) is associative and has mempty as an
--   identity. See the documentation of beside 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. (===) is associative and
--   has mempty as an identity. See the documentation of
--   beside 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
--   th 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 beside 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.
--   
--   
--   
- For more control over the spacing, see hcat'.
--   
- To align the diagrams vertically (or otherwise), use alignment
--   combinators (such as alignT or alignB) from
--   Diagrams.TwoD.Align before applying hcat.
--   
- For non-axis-aligned layout, see cat.
--   
hcat :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2) => [a] -> a

-- | A variant of hcat taking an extra CatOpts record to
--   control the spacing. See the cat' 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.
--   
--   
--   
- For more control over the spacing, see vcat'.
--   
- To align the diagrams horizontally (or otherwise), use alignment
--   combinators (such as alignL or alignR) from
--   Diagrams.TwoD.Align before applying vcat.
--   
- For non-axis-aligned layout, see cat.
--   
vcat :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2) => [a] -> a

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

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

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

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

-- | padX s "pads" a diagram in the x-direction, expanding its
--   envelope horizontally by a factor of s (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 centerX) before
--   applying padX.
padX :: (Backend b R2, Monoid' m) => Double -> QDiagram b R2 m -> QDiagram b R2 m

-- | padY s "pads" a diagram in the y-direction, expanding its
--   envelope vertically by a factor of s (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 centerY) before
--   applying padY.
padY :: (Backend b R2, Monoid' m) => Double -> QDiagram b R2 m -> QDiagram b R2 m

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

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

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

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

-- | view p v sets the envelope of a diagram to a rectangle whose
--   lower-left corner is at p and whose upper-right corner is at
--   p .+^ v. 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

-- | TextAlignment 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 alignedText 0.5 0.5.
--   
--   Note that it takes up no space, 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
--   alignedText 0 1.
--   
--   Note that it takes up no space.
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 takes up no space.
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 takes up no space.
baselineText :: Renderable Text b => String -> Diagram b R2

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

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

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

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

-- | Extract the size from a FontSize 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
--   1.
fontSize :: HasStyle a => Double -> a -> a

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

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

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

-- | Specify the slant (normal, italic, or oblique) that should be used for
--   all text within a diagram. See also italic and oblique
--   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 FontWeightA attribute specifies the weight (normal or
--   bold) that should be used for all text within a diagram. Inner
--   FontWeightA attributes override outer ones.
data FontWeightA

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

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

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

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

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

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

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

-- | Convert a 2D point back into a pair of coordinates. See also
--   coords.
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 fromDirection.
e :: Angle a => a -> R2

-- | The circle constant, the ratio of a circle's circumference to its
--   radius. Note that pi = tau/2.
--   
--   For more information and a well-reasoned argument why we should all be
--   using tau instead of pi, see The Tau Manifesto,
--   http://tauday.com/.
--   
--   To hear what it sounds like (and to easily memorize the first 30
--   digits or so), try http://youtu.be/3174T-3-59Q.
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 Turn, 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 fullTurn, 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 stroke', 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 stroke. The solution is to give a type
--   signature to expressions involving stroke, 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 stroke that takes an extra record of options to
--   customize its behavior. In particular:
--   
--   
--   
- Names can be assigned to the path's vertices
--   
--   
--   StrokeOpts is an instance of Default, so stroke'
--   with { ... } syntax may be used.
stroke' :: (Renderable (Path R2) b, IsName a) => StrokeOpts a -> Path R2 -> Diagram b R2

-- | A composition of stroke and pathFromTrail 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 stroke and hence of strokeT as
--   well. The solution is to give a type signature to expressions
--   involving strokeT, 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 stroke' and pathFromTrail 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 strokeT and wrapLine for conveniently
--   converting a line directly into a diagram.
strokeLine :: Renderable (Path R2) b => Trail' Line R2 -> Diagram b R2

-- | A composition of strokeT and wrapLoop 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 Located Trail
--   directly into a diagram; strokeLocT = stroke . trailLike.
strokeLocT :: Renderable (Path R2) b => Located (Trail R2) -> Diagram b R2

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

-- | A convenience function for converting a Located loop directly
--   into a diagram; strokeLocLoop = stroke . trailLike . mapLoc
--   wrapLoop.
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 winding number.
--   See http://en.wikipedia.org/wiki/Nonzero-rule.
Winding :: FillRule

-- | Interior points are those where a ray extended infinitely in a
--   particular direction crosses the path an odd number of times. See
--   http://en.wikipedia.org/wiki/Even-odd_rule.
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.
--   StrokeOpts is an instance of Default, so a
--   StrokeOpts records can be created using with {
--   ... } 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 list of lists 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 Winding. NOTE: for now, this only affects the
--   resulting diagram's Query, not how it will be drawn! To
--   set the fill rule determining how it is to be drawn, use the
--   fillRule function.
queryFillRule :: StrokeOpts a -> FillRule

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

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

-- | Create a centered vertical (T-B) line of the given length.
--   
--   
--   
--   vruleEx = hcat' with {sep = 0.2} (map vrule [1, 1.2 .. 2])
--           # centerXY # pad 1.1
--   
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

-- | ellipse e constructs an ellipse with eccentricity e
--   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

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

-- | Given a start angle s and an end angle e,
--   arc s e 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 r, a start angle s and an end angle
--   e, arc' r s e is the path of a radius
--   (abs r) 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 arc 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 PolygonOpts 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.
--   
--   
--   
- The first argument is a list of central angles from
--   each vertex to the next.
--   
- The second argument is a list of radii from the origin to
--   each successive vertex.
--   
--   
--   To construct an n-gon, use a list of n-1 angles and
--   n radii. Extra angles or radii are ignored.
--   
--   Cyclic polygons (with all vertices lying on a circle) can be
--   constructed using a second argument of (repeat r).
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 centroid of its vertices.
--   
--   
--   
- The first argument is a list of vertex angles,
--   giving the angle at each vertex from the previous vertex to the next.
--   The first angle in the list is the angle at the second vertex;
--   the first edge always starts out heading in the positive y direction
--   from the first vertex.
--   
- The second argument is a list of distances between successive
--   vertices.
--   
--   
--   To construct an n-gon, use a list of n-2 angles and
--   n-1 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 horizontally, so the bottommost edge is parallel to the
--   x-axis.
OrientH :: PolyOrientation

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

-- | Orient so some edge is facing in the
--   direction of, 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 n means that edges will connect every
--   nth vertex.
StarSkip :: Int -> StarOpts

-- | Create a generalized star polygon. The StarOpts
--   are used to determine in which order the given vertices should be
--   connected. The intention is that the second argument of type
--   [P2] could be generated by a call to polygon,
--   regPoly, or the like, since a list of vertices is
--   TrailLike. But of course the list can be generated any way you
--   like. A Path R2 is returned (instead of any
--   TrailLike) 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 length of the sides. (Compare to the
--   polygon function with a PolyRegular option, which
--   produces polygons of a given radius).
--   
--   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 triangle, 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

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

-- | roundedRect w h r generates a closed trail, or closed path
--   centered at the origin, of an axis-aligned rectangle with width
--   w, height h, and circular rounded corners of radius
--   r. If r is negative the corner will be cut out in a
--   reverse arc. If the size of r is larger than half the smaller
--   dimension of w and h, 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
--   roundedRect' instead.
--   
--   
--   
--   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 }
--     ]
--   
roundedRect :: (TrailLike t, V t ~ R2) => Double -> Double -> Double -> t

-- | roundedRect' works like roundedRect but allows you
--   to set the radius of each corner indivually, using
--   RoundedRectOpts. 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 alignedText 0.5 0.5.
--   
--   Note that it takes up no space, 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
--   alignedText 0 1.
--   
--   Note that it takes up no space.
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 takes up no space.
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 takes up no space.
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
--   1.
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 rotate.
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
--   Angle. For example, rotate (1/4 :: Turn),
--   rotate (tau/4 :: Rad), and rotate (90 ::
--   Deg) all represent the same transformation, namely, a
--   counterclockwise rotation by a right angle. To rotate about some point
--   other than the local origin, see rotateAbout.
--   
--   Note that writing rotate (1/4), 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 rotateBy,
--   which is specialized to take a Turn argument.
rotate :: (Transformable t, V t ~ R2, Angle a) => a -> t -> t

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

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

-- | rotateAbout p is like rotate, except it rotates around
--   the point p 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 scale.
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 scale.
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

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

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

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

-- | scaleUToY h scales a diagram uniformly by whatever
--   factor required to make its height h. scaleUToY
--   should not be applied to diagrams with a height of 0, such as
--   hrule.
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

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

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

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

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

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

-- | shearY d performs a shear in the y-direction which sends
--   (1,0) to (1,d).
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
--   
--   
--    c
--   ===
--    d
--   
--   
--   to place c above d. The local origin of the
--   resulting combined diagram is the same as the local origin of the
--   first. (===) is associative and has mempty as an
--   identity. See the documentation of beside 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. (===) is associative and
--   has mempty as an identity. See the documentation of
--   beside 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
--   th 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 beside 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.
--   
--   
--   
- For more control over the spacing, see hcat'.
--   
- To align the diagrams vertically (or otherwise), use alignment
--   combinators (such as alignT or alignB) from
--   Diagrams.TwoD.Align before applying hcat.
--   
- For non-axis-aligned layout, see cat.
--   
hcat :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2) => [a] -> a

-- | A variant of hcat taking an extra CatOpts record to
--   control the spacing. See the cat' 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.
--   
--   
--   
- For more control over the spacing, see vcat'.
--   
- To align the diagrams horizontally (or otherwise), use alignment
--   combinators (such as alignL or alignR) from
--   Diagrams.TwoD.Align before applying vcat.
--   
- For non-axis-aligned layout, see cat.
--   
vcat :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2) => [a] -> a

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

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

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

-- | padX s "pads" a diagram in the x-direction, expanding its
--   envelope horizontally by a factor of s (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 centerX) before
--   applying padX.
padX :: (Backend b R2, Monoid' m) => Double -> QDiagram b R2 m -> QDiagram b R2 m

-- | padY s "pads" a diagram in the y-direction, expanding its
--   envelope vertically by a factor of s (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 centerY) before
--   applying padY.
padY :: (Backend b R2, Monoid' m) => Double -> QDiagram b R2 m -> QDiagram b R2 m

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

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

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

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

-- | view p v sets the envelope of a diagram to a rectangle whose
--   lower-left corner is at p and whose upper-right corner is at
--   p .+^ v. 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

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

-- | Like alignX, but moving the local origin vertically, with an
--   argument of 1 corresponding to the top edge and (-1)
--   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 SizeSpec2D 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 Nothing 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):
--   
--   
--   
- Line width 0.01
--   
- Line color black
--   
- Font size 1
--   
- Line cap LineCapButt
--   
- line join miter
--   
- Miter limit 10
--   
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)

-- | adjustDia2D provides a useful default implementation of the
--   adjustDia method from the Backend 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:
--   
--   
--   
- Set default attributes (see setDefault2DAttributes)
--   
- Freeze the diagram in its final form
--   
- Scale and translate the diagram to fit within the requested size
--   (see adjustDiaSize2D)
--   
- Also return the actual adjusted size of the diagram.
--   
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 requiredScaleT with the name adjustSize for
--   backwards compatibility.

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

-- | requiredScale spec sz returns a scaling factor necessary to
--   make something of size sz fit the requested size
--   spec, 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
--   
--   
--   
- embed pure expressions (pure), and
--   
- sequence computations and combine their results
--   (<*>).
--   
--   
--   A minimal complete definition must include implementations of these
--   functions satisfying the following laws:
--   
--   
--   
- identity pure id <*>
--   v = v
--   
- composition pure (.) <*> u
--   <*> v <*> w = u <*> (v
--   <*> w)
--   
- homomorphism pure f <*>
--   pure x = pure (f x)
--   
- interchange u <*> pure y =
--   pure ($ y) <*> u
--   
--   
--   The other methods have the following default definitions, which may be
--   overridden with equivalent specialized implementations:
--   
--   
--   u *> v = pure (const id) <*> u <*> v
--   u <* v = pure const <*> u <*> v
--   
--   
--   As a consequence of these laws, the Functor instance for
--   f will satisfy
--   
--   
--   fmap f x = pure f <*> x
--   
--   
--   If f is also a Monad, it should satisfy
--   pure = return and (<*>) =
--   ap (which implies that pure and <*>
--   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 fmap.
(<$>) :: Functor f => (a -> b) -> f a -> f b

-- | Replace all locations in the input with the same value. The default
--   definition is fmap . const, 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
--   fmap in a Functor 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
