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

Maintainer | diagrams-discuss@googlegroups.com
Safe Haskell | None

Diagrams.TwoD.Path

Contents

- Constructing path-based diagrams
  - Stroke options
  - Inside/outside testing
- Clipping

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

- stroke :: Renderable (Path R2) b => Path R2 -> Diagram b R2
- stroke' :: (Renderable (Path R2) b, IsName a) => StrokeOpts a -> Path R2 -> Diagram b R2
- strokeT :: Renderable (Path R2) b => Trail R2 -> Diagram b R2
- strokeT' :: (Renderable (Path R2) b, IsName a) => StrokeOpts a -> Trail R2 -> Diagram b R2
- strokeLine :: Renderable (Path R2) b => Trail' Line R2 -> Diagram b R2
- strokeLoop :: Renderable (Path R2) b => Trail' Loop R2 -> Diagram b R2
- strokeLocT :: Renderable (Path R2) b => Located (Trail R2) -> Diagram b R2
- strokeLocLine :: Renderable (Path R2) b => Located (Trail' Line R2) -> Diagram b R2
- strokeLocLoop :: Renderable (Path R2) b => Located (Trail' Loop R2) -> Diagram b R2
- data FillRule
  - = Winding
  - | EvenOdd
- newtype FillRuleA = FillRuleA (Last FillRule)
- getFillRule :: FillRuleA -> FillRule
- fillRule :: HasStyle a => FillRule -> a -> a
- data StrokeOpts a = StrokeOpts {
  - vertexNames :: [[a]]
  - queryFillRule :: FillRule
  }
- isInsideWinding :: P2 -> Path R2 -> Bool
- isInsideEvenOdd :: P2 -> Path R2 -> Bool
- newtype Clip = Clip {
  - getClip :: [Path R2]
  }
- clipBy :: (HasStyle a, V a ~ R2) => Path R2 -> a -> a

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

strokeT :: 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 `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, 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.

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.

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

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

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.

Instances

Eq FillRule |

newtype FillRuleA Source

Constructors

FillRuleA (Last FillRule) |

Instances

Typeable FillRuleA |
Semigroup FillRuleA |
AttributeClass FillRuleA |

getFillRule :: FillRuleA -> FillRule Source

Extract the fill rule from a `FillRuleA` attribute.

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

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

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

  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.

Instances

Default (StrokeOpts a) |

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

Fields

getClip :: [Path R2]

Instances

Typeable Clip |
Semigroup Clip |
AttributeClass Clip |
Transformable Clip |

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

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.