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

Copyright | (c) 2011 diagrams-lib team (see LICENSE)
License | BSD-style (see LICENSE)
Maintainer | diagrams-discuss@googlegroups.com
Safe Haskell | None
Language | Haskell2010

Diagrams.TwoD.Path

Contents

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

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 :: (InSpace V2 n t, ToPath t, TypeableFloat n, Renderable (Path V2 n) b) => t -> QDiagram b V2 n Any
- stroke' :: (InSpace V2 n t, ToPath t, TypeableFloat n, Renderable (Path V2 n) b, IsName a) => StrokeOpts a -> t -> QDiagram b V2 n Any
- strokePath :: (TypeableFloat n, Renderable (Path V2 n) b) => Path V2 n -> QDiagram b V2 n Any
- strokeP :: (TypeableFloat n, Renderable (Path V2 n) b) => Path V2 n -> QDiagram b V2 n Any
- strokePath' :: (TypeableFloat n, Renderable (Path V2 n) b, IsName a) => StrokeOpts a -> Path V2 n -> QDiagram b V2 n Any
- strokeP' :: (TypeableFloat n, Renderable (Path V2 n) b, IsName a) => StrokeOpts a -> Path V2 n -> QDiagram b V2 n Any
- strokeTrail :: (TypeableFloat n, Renderable (Path V2 n) b) => Trail V2 n -> QDiagram b V2 n Any
- strokeT :: (TypeableFloat n, Renderable (Path V2 n) b) => Trail V2 n -> QDiagram b V2 n Any
- strokeTrail' :: (TypeableFloat n, Renderable (Path V2 n) b, IsName a) => StrokeOpts a -> Trail V2 n -> QDiagram b V2 n Any
- strokeT' :: (TypeableFloat n, Renderable (Path V2 n) b, IsName a) => StrokeOpts a -> Trail V2 n -> QDiagram b V2 n Any
- strokeLine :: (TypeableFloat n, Renderable (Path V2 n) b) => Trail' Line V2 n -> QDiagram b V2 n Any
- strokeLoop :: (TypeableFloat n, Renderable (Path V2 n) b) => Trail' Loop V2 n -> QDiagram b V2 n Any
- strokeLocTrail :: (TypeableFloat n, Renderable (Path V2 n) b) => Located (Trail V2 n) -> QDiagram b V2 n Any
- strokeLocT :: (TypeableFloat n, Renderable (Path V2 n) b) => Located (Trail V2 n) -> QDiagram b V2 n Any
- strokeLocLine :: (TypeableFloat n, Renderable (Path V2 n) b) => Located (Trail' Line V2 n) -> QDiagram b V2 n Any
- strokeLocLoop :: (TypeableFloat n, Renderable (Path V2 n) b) => Located (Trail' Loop V2 n) -> QDiagram b V2 n Any
- data FillRule
  - = Winding
  - | EvenOdd
- getFillRule :: FillRule -> FillRule
- fillRule :: HasStyle a => FillRule -> a -> a
- _fillRule :: Lens' (Style V2 n) FillRule
- data StrokeOpts a = StrokeOpts {
  - _vertexNames :: [[a]]
  - _queryFillRule :: FillRule
  }
- vertexNames :: forall a a'. Lens (StrokeOpts a) (StrokeOpts a') [[a]] [[a']]
- queryFillRule :: forall a. Lens' (StrokeOpts a) FillRule
- isInsideWinding :: RealFloat n => Point V2 n -> Path V2 n -> Bool
- isInsideEvenOdd :: RealFloat n => Point V2 n -> Path V2 n -> Bool
- newtype Clip n = Clip [Path V2 n]
- _Clip :: Iso (Clip n) (Clip n') [Path V2 n] [Path V2 n']
- _clip :: (Typeable n, OrderedField n) => Lens' (Style V2 n) [Path V2 n]
- clipBy :: (HasStyle a, V a ~ V2, N a ~ n, TypeableFloat n) => Path V2 n -> a -> a
- clipTo :: (TypeableFloat n, Renderable (Path V2 n) b) => Path V2 n -> QDiagram b V2 n Any -> QDiagram b V2 n Any
- clipped :: (TypeableFloat n, Renderable (Path V2 n) b) => Path V2 n -> QDiagram b V2 n Any -> QDiagram b V2 n Any
- intersectPoints :: (InSpace V2 n t, SameSpace t s, ToPath t, ToPath s, OrderedField n) => t -> s -> [P2 n]
- intersectPoints' :: (InSpace V2 n t, SameSpace t s, ToPath t, ToPath s, OrderedField n) => n -> t -> s -> [P2 n]
- intersectPointsP :: OrderedField n => Path V2 n -> Path V2 n -> [P2 n]
- intersectPointsP' :: OrderedField n => n -> Path V2 n -> Path V2 n -> [P2 n]
- intersectPointsT :: OrderedField n => Located (Trail V2 n) -> Located (Trail V2 n) -> [P2 n]
- intersectPointsT' :: OrderedField n => n -> Located (Trail V2 n) -> Located (Trail V2 n) -> [P2 n]

# 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' :: (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.

Instances

Eq FillRule Source |
Ord FillRule Source |
Show FillRule Source |
Semigroup FillRule Source |
Default FillRule Source |
AttributeClass FillRule Source |

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

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

Instances

Default (StrokeOpts a) Source |

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 :: RealFloat n => Point V2 n -> Path V2 n -> 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.

isInsideEvenOdd :: RealFloat n => Point V2 n -> Path V2 n -> 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.

# 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 |
Typeable * n => AttributeClass (Clip n) Source |
OrderedField n => Transformable (Clip n) Source |
AsEmpty (Clip n) Source |
Wrapped (Clip n) Source |
(~) * (Clip n1) t0 => Rewrapped (Clip n) t Source |
type V (Clip n) = V2 Source |
type N (Clip n) = n Source |
type Unwrapped (Clip n0) = [Path V2 n0] Source |

_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, Renderable (Path V2 n) b) => 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, Renderable (Path V2 n) b) => 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.