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

Copyright(c) 2011-2015 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 :: (InSpace V2 n t, ToPath t, TypeableFloat n, Renderable (Path V2 n) b) => t -> QDiagram b V2 n Any Source #

Convert a ToPath object 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 behaviour to be customized.

stroke :: Path V2 Double                  -> Diagram b
stroke :: Located (Trail V2 Double)       -> Diagram b
stroke :: Located (Trail' Loop V2 Double) -> Diagram b
stroke :: Located (Trail' Line V2 Double) -> Diagram b

stroke' :: (InSpace V2 n t, ToPath t, TypeableFloat n, Renderable (Path V2 n) b, IsName a) => StrokeOpts a -> t -> QDiagram b V2 n Any Source #

A variant of stroke that takes an extra record of options to customize its behaviour. In particular:

  • Names can be assigned to the path's vertices

StrokeOpts is an instance of Default, so stroke' (with & ... ) syntax may be used.

strokePath :: (TypeableFloat n, Renderable (Path V2 n) b) => Path V2 n -> QDiagram b V2 n Any Source #

stroke specialised to Path.

strokeP :: (TypeableFloat n, Renderable (Path V2 n) b) => Path V2 n -> QDiagram b V2 n Any Source #

stroke specialised to Path.

strokePath' :: (TypeableFloat n, Renderable (Path V2 n) b, IsName a) => StrokeOpts a -> Path V2 n -> QDiagram b V2 n Any Source #

stroke' specialised to Path.

strokeP' :: (TypeableFloat n, Renderable (Path V2 n) b, IsName a) => StrokeOpts a -> Path V2 n -> QDiagram b V2 n Any Source #

stroke' specialised to Path.

strokeTrail :: (TypeableFloat n, Renderable (Path V2 n) b) => Trail V2 n -> QDiagram b V2 n Any Source #

stroke specialised to Trail.

strokeT :: (TypeableFloat n, Renderable (Path V2 n) b) => Trail V2 n -> QDiagram b V2 n Any Source #

stroke specialised to Trail.

strokeTrail' :: (TypeableFloat n, Renderable (Path V2 n) b, IsName a) => StrokeOpts a -> Trail V2 n -> QDiagram b V2 n Any Source #

A composition of stroke' and pathFromTrail for conveniently converting a trail directly into a diagram.

strokeT' :: (TypeableFloat n, Renderable (Path V2 n) b, IsName a) => StrokeOpts a -> Trail V2 n -> QDiagram b V2 n Any Source #

Deprecated synonym for strokeTrail'.

strokeLine :: (TypeableFloat n, Renderable (Path V2 n) b) => Trail' Line V2 n -> QDiagram b V2 n Any Source #

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

strokeLoop :: (TypeableFloat n, Renderable (Path V2 n) b) => Trail' Loop V2 n -> QDiagram b V2 n Any Source #

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

strokeLocTrail :: (TypeableFloat n, Renderable (Path V2 n) b) => Located (Trail V2 n) -> QDiagram b V2 n Any Source #

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

strokeLocT :: (TypeableFloat n, Renderable (Path V2 n) b) => Located (Trail V2 n) -> QDiagram b V2 n Any Source #

Deprecated synonym for strokeLocTrail.

strokeLocLine :: (TypeableFloat n, Renderable (Path V2 n) b) => Located (Trail' Line V2 n) -> QDiagram b V2 n Any Source #

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

strokeLocLoop :: (TypeableFloat n, Renderable (Path V2 n) b) => Located (Trail' Loop V2 n) -> QDiagram b V2 n Any 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) 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 :: FillRule -> 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.

_fillRule :: Lens' (Style V2 n) FillRule Source #

Lens onto the fill rule of a style.

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

Instances

vertexNames :: 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 :: 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

newtype Crossings Source #

The sum of signed crossings of a path as we travel in the positive x direction from a given point.

This is the HasQuery result for Paths, Located Trails and Located Loops.

sample :: Path V2 Double                  -> Point V2 Double -> Crossings
sample :: Located (Trail V2 Double)       -> Point V2 Double -> Crossings
sample :: Located (Trail' Loop V2 Double) -> Point V2 Double -> Crossings

Note that Lines have no inside or outside, so don't contribute crossings

Constructors

Crossings Int 

Instances

Enum Crossings Source # 
Eq Crossings Source # 
Integral Crossings Source # 
Num Crossings Source # 
Ord Crossings Source # 
Real Crossings Source # 
Show Crossings Source # 
Semigroup Crossings Source # 
Monoid Crossings Source # 

isInsideWinding :: HasQuery t Crossings => t -> Point (V t) (N t) -> Bool Source #

Test whether the given point is inside the given path, by testing whether the point's winding number is nonzero. Note that False is always returned for paths consisting of lines (as opposed to loops), regardless of the winding number.

isInsideWinding :: Path V2 Double                  -> Point V2 Double -> Bool
isInsideWinding :: Located (Trail V2 Double)       -> Point V2 Double -> Bool
isInsideWinding :: Located (Trail' Loop V2 Double) -> Point V2 Double -> Bool

isInsideEvenOdd :: HasQuery t Crossings => t -> Point (V t) (N t) -> Bool Source #

Test whether the given point is inside the given 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 paths consisting of lines (as opposed to loops), regardless of the number of crossings.

isInsideEvenOdd :: Path V2 Double                  -> Point V2 Double -> Bool
isInsideEvenOdd :: Located (Trail V2 Double)       -> Point V2 Double -> Bool
isInsideEvenOdd :: Located (Trail' Loop V2 Double) -> Point V2 Double -> Bool

Clipping

newtype Clip n 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 V2 n] 

Instances

Semigroup (Clip n) Source # 

Methods

(<>) :: Clip n -> Clip n -> Clip n #

sconcat :: NonEmpty (Clip n) -> Clip n #

stimes :: Integral b => b -> Clip n -> Clip n #

Typeable * n => AttributeClass (Clip n) Source # 
OrderedField n => Transformable (Clip n) Source # 

Methods

transform :: Transformation (V (Clip n)) (N (Clip n)) -> Clip n -> Clip n #

AsEmpty (Clip n) Source # 

Methods

_Empty :: Prism' (Clip n) () #

Wrapped (Clip n0) Source # 

Associated Types

type Unwrapped (Clip n0) :: * #

Methods

_Wrapped' :: Iso' (Clip n0) (Unwrapped (Clip n0)) #

(~) * (Clip n0) t0 => Rewrapped (Clip n1) t0 Source # 
RealFloat n => HasQuery (Clip n) All Source #

A point inside a clip if the point is in All invididual clipping paths.

Methods

getQuery :: Clip n -> Query (V (Clip n)) (N (Clip n)) All Source #

type V (Clip n) Source # 
type V (Clip n) = V2
type N (Clip n) Source # 
type N (Clip n) = n
type Unwrapped (Clip n0) Source # 
type Unwrapped (Clip n0) = [Path V2 n0]

_Clip :: Iso (Clip n) (Clip n') [Path V2 n] [Path V2 n'] Source #

_clip :: (Typeable n, OrderedField n) => Lens' (Style V2 n) [Path V2 n] Source #

Lens onto the Clip in a style. An empty list means no clipping.

clipBy :: (HasStyle a, V a ~ V2, N a ~ n, TypeableFloat n) => Path V2 n -> 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 :: TypeableFloat n => Path V2 n -> QDiagram b V2 n Any -> QDiagram b V2 n Any 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 :: TypeableFloat n => Path V2 n -> QDiagram b V2 n Any -> QDiagram b V2 n Any Source #

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

Intersections

intersectPoints :: (InSpace V2 n t, SameSpace t s, ToPath t, ToPath s, OrderedField n) => t -> s -> [P2 n] Source #

Find the intersect points of two objects that can be converted to a path.

intersectPoints' :: (InSpace V2 n t, SameSpace t s, ToPath t, ToPath s, OrderedField n) => n -> t -> s -> [P2 n] Source #

Find the intersect points of two objects that can be converted to a path within the given tolerance.

intersectPointsP :: OrderedField n => Path V2 n -> Path V2 n -> [P2 n] Source #

Compute the intersect points between two paths.

intersectPointsP' :: OrderedField n => n -> Path V2 n -> Path V2 n -> [P2 n] Source #

Compute the intersect points between two paths within given tolerance.

intersectPointsT :: OrderedField n => Located (Trail V2 n) -> Located (Trail V2 n) -> [P2 n] Source #

Compute the intersect points between two located trails.

intersectPointsT' :: OrderedField n => n -> Located (Trail V2 n) -> Located (Trail V2 n) -> [P2 n] Source #

Compute the intersect points between two located trails within the given tolerance.

Orphan instances

RealFloat n => HasQuery (Located (Trail V2 n)) Crossings Source # 
RealFloat n => HasQuery (Located (Trail' l V2 n)) Crossings Source # 

Methods

getQuery :: Located (Trail' l V2 n) -> Query (V (Located (Trail' l V2 n))) (N (Located (Trail' l V2 n))) Crossings Source #

RealFloat n => Traced (Trail V2 n) Source # 

Methods

getTrace :: Trail V2 n -> Trace (V (Trail V2 n)) (N (Trail V2 n)) #

RealFloat n => Traced (Path V2 n) Source # 

Methods

getTrace :: Path V2 n -> Trace (V (Path V2 n)) (N (Path V2 n)) #

RealFloat n => HasQuery (Path V2 n) Crossings Source # 

Methods

getQuery :: Path V2 n -> Query (V (Path V2 n)) (N (Path V2 n)) Crossings Source #

(TypeableFloat n, Renderable (Path V2 n) b) => TrailLike (QDiagram b V2 n Any) Source # 

Methods

trailLike :: Located (Trail (V (QDiagram b V2 n Any)) (N (QDiagram b V2 n Any))) -> QDiagram b V2 n Any Source #