diagrams-lib-1.1.0.7: Embedded domain-specific language for declarative graphics

Copyright(c) 2011 diagrams-lib team (see LICENSE)
LicenseBSD-style (see LICENSE)
Maintainerdiagrams-discuss@googlegroups.com
Safe HaskellNone
LanguageHaskell2010

Diagrams.TwoD.Path

Contents

Description

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.

Synopsis

Constructing path-based diagrams

stroke :: Renderable (Path R2) b => Path R2 -> Diagram b R2 Source

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, IsName a) => StrokeOpts a -> Path R2 -> Diagram b R2 Source

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.

strokeTrail :: Renderable (Path R2) b => Trail R2 -> Diagram b R2 Source

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 strokeTrail as well. The solution is to give a type signature to expressions involving strokeTrail, or (recommended) upgrade GHC (the bug is fixed in 7.0.2 onwards).

strokeT :: Renderable (Path R2) b => Trail R2 -> Diagram b R2 Source

Deprecated synonym for strokeTrail.

strokeTrail' :: (Renderable (Path R2) b, IsName a) => StrokeOpts a -> Trail R2 -> Diagram b R2 Source

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 Source

Deprecated synonym for strokeTrail'.

strokeLine :: Renderable (Path R2) b => Trail' Line R2 -> Diagram b R2 Source

A composition of strokeT and wrapLine for conveniently converting a line directly into a diagram.

strokeLoop :: Renderable (Path R2) b => Trail' Loop R2 -> Diagram b R2 Source

A composition of strokeT and wrapLoop for conveniently converting a loop directly into a diagram.

strokeLocTrail :: Renderable (Path R2) b => Located (Trail R2) -> Diagram b R2 Source

A convenience function for converting a Located Trail directly into a diagram; strokeLocTrail = stroke . trailLike.

strokeLocT :: Renderable (Path R2) b => Located (Trail R2) -> Diagram b R2 Source

Deprecated synonym for strokeLocTrail.

strokeLocLine :: Renderable (Path R2) b => Located (Trail' Line R2) -> Diagram b R2 Source

A convenience function for converting a Located line directly into a diagram; strokeLocLine = stroke . trailLike . mapLoc wrapLine.

strokeLocLoop :: Renderable (Path R2) b => Located (Trail' Loop R2) -> Diagram b R2 Source

A convenience function for converting a Located loop directly into a diagram; strokeLocLoop = stroke . trailLike . mapLoc wrapLoop.

Stroke options

data FillRule Source

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

Constructors

Winding

Interior points are those with a nonzero winding number. See http://en.wikipedia.org/wiki/Nonzero-rule.

EvenOdd

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.

getFillRule :: FillRuleA -> FillRule Source

Extract the fill rule from a FillRuleA attribute.

fillRule :: HasStyle a => FillRule -> a -> a Source

Specify the fill rule that should be used for determining which points are inside a path.

data StrokeOpts a Source

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.

Constructors

StrokeOpts 

Fields

_vertexNames :: [[a]]
 
_queryFillRule :: FillRule
 

Instances

vertexNames :: forall a a'. Lens (StrokeOpts a) (StrokeOpts a') [[a]] [[a']] Source

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.

queryFillRule :: forall a. Lens' (StrokeOpts a) FillRule Source

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.

Inside/outside testing

isInsideWinding :: P2 -> Path R2 -> Bool Source

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.

isInsideEvenOdd :: P2 -> Path R2 -> Bool Source

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.

Clipping

newtype Clip Source

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.

Constructors

Clip [Path R2] 

clipBy :: (HasStyle a, V a ~ R2) => Path R2 -> a -> a Source

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.

clipTo :: Renderable (Path R2) b => Path R2 -> Diagram b R2 -> Diagram b R2 Source

Clip a diagram to the given path setting its envelope to the pointwise minimum of the envelopes of the diagram and path. The trace consists of those parts of the original diagram's trace which fall within the clipping path, or parts of the path's trace within the original diagram.

clipped :: Renderable (Path R2) b => Path R2 -> Diagram b R2 -> Diagram b R2 Source

Clip a diagram to the clip path taking the envelope and trace of the clip path.