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

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

Diagrams.Segment

Contents

Description

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.

Synopsis

Open/closed tags

data Open Source

Type tag for open segments.

data Closed Source

Type tag for closed segments.

Instances

(Additive v, Num n) => EndValues (Tangent (Segment Closed v n)) Source 
(Additive v, Num n) => Parametric (Tangent (Segment Closed v n)) Source 
ToPath (Located [Segment Closed v n]) Source 
ToPath (Located (Segment Closed v n)) Source 
(Metric v, OrderedField n, Metric u, OrderedField n') => Cons (SegTree v n) (SegTree u n') (Segment Closed v n) (Segment Closed u n') 
(Metric v, OrderedField n, Metric u, OrderedField n') => Snoc (SegTree v n) (SegTree u n') (Segment Closed v n) (Segment Closed u n') 
(OrderedField n, Metric v) => Measured (SegMeasure v n) (Segment Closed v n) Source 
(Metric v, OrderedField n) => Enveloped (Segment Closed v n) Source

The envelope for a segment is based at the segment's start.

(Additive v, Num n) => Reversing (Segment Closed v n) Source

Reverse the direction of a segment.

(Metric v, OrderedField n) => HasArcLength (Segment Closed v n) Source 
(Additive v, Fractional n) => Sectionable (Segment Closed v n) Source 
(Additive v, Num n) => EndValues (Segment Closed v n) Source 
Num n => DomainBounds (Segment Closed v n) Source 
(Additive v, Num n) => Parametric (Segment Closed v n) Source

atParam yields a parametrized view of segments as continuous functions [0,1] -> v, which give the offset from the start of the segment for each value of the parameter between 0 and 1. It is designed to be used infix, like seg `atParam` 0.5.

(Metric v, OrderedField n, Metric u, OrderedField n') => Cons (Trail' Line v n) (Trail' Line u n') (Segment Closed v n) (Segment Closed u n') 
(Metric v, OrderedField n, Metric u, OrderedField n') => Snoc (Trail' Line v n) (Trail' Line u n') (Segment Closed v n) (Segment Closed u n') 
type Codomain (Segment Closed v n) = v Source 

Segment offsets

data Offset c v n where Source

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.

Constructors

OffsetOpen :: Offset Open v n 
OffsetClosed :: v n -> Offset Closed v n 

Instances

Functor v => Functor (Offset c v) Source 
Eq (v n) => Eq (Offset c v n) Source 
Ord (v n) => Ord (Offset c v n) Source 
Show (v n) => Show (Offset c v n) Source 
Transformable (Offset c v n) Source 
(Additive v, Num n) => Reversing (Offset c v n) Source

Reverses the direction of closed offsets.

(~) * r (Offset c u n) => AffineMappable (Offset c v n) r Source 
(~) * r (Offset c u m) => LinearMappable (Offset c v n) r Source 
Each (Offset c v n) (Offset c v' n') (v n) (v' n') Source 
type V (Offset c v n) = v Source 
type N (Offset c v n) = n Source 

segOffset :: Segment Closed v n -> v n Source

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.

Constructing and modifying segments

data Segment c v n Source

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.

Constructors

Linear !(Offset c v n)

A linear segment with given offset.

Cubic !(v n) !(v n) !(Offset c v n)

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.

Instances

(Additive v, Num n) => EndValues (Tangent (Segment Closed v n)) Source 
(Additive v, Num n) => Parametric (Tangent (Segment Closed v n)) Source 
ToPath (Located [Segment Closed v n]) Source 
ToPath (Located (Segment Closed v n)) Source 
Functor v => Functor (Segment c v) Source 
(Metric v, OrderedField n, Metric u, OrderedField n') => Cons (SegTree v n) (SegTree u n') (Segment Closed v n) (Segment Closed u n') 
(Metric v, OrderedField n, Metric u, OrderedField n') => Snoc (SegTree v n) (SegTree u n') (Segment Closed v n) (Segment Closed u n') 
(OrderedField n, Metric v) => Measured (SegMeasure v n) (Segment Closed v n) Source 
Eq (v n) => Eq (Segment c v n) Source 
Ord (v n) => Ord (Segment c v n) Source 
Show (v n) => Show (Segment c v n) Source 
(Metric v, OrderedField n) => Enveloped (Segment Closed v n) Source

The envelope for a segment is based at the segment's start.

Transformable (Segment c v n) Source 
(Additive v, Num n) => Reversing (Segment Closed v n) Source

Reverse the direction of a segment.

(Metric v, OrderedField n) => HasArcLength (Segment Closed v n) Source 
(Additive v, Fractional n) => Sectionable (Segment Closed v n) Source 
(Additive v, Num n) => EndValues (Segment Closed v n) Source 
Num n => DomainBounds (Segment Closed v n) Source 
(Additive v, Num n) => Parametric (Segment Closed v n) Source

atParam yields a parametrized view of segments as continuous functions [0,1] -> v, which give the offset from the start of the segment for each value of the parameter between 0 and 1. It is designed to be used infix, like seg `atParam` 0.5.

Renderable (Segment c v n) NullBackend Source 
(~) * r (Segment c u n) => AffineMappable (Segment c v n) r Source 
(~) * r (Segment c u m) => LinearMappable (Segment c v n) r Source 
Each (Segment c v n) (Segment c v' n') (v n) (v' n') Source 
(Metric v, OrderedField n, Metric u, OrderedField n') => Cons (Trail' Line v n) (Trail' Line u n') (Segment Closed v n) (Segment Closed u n') 
(Metric v, OrderedField n, Metric u, OrderedField n') => Snoc (Trail' Line v n) (Trail' Line u n') (Segment Closed v n) (Segment Closed u n') 
type V (Segment c v n) = v Source 
type N (Segment c v n) = n Source 
type Codomain (Segment Closed v n) = v Source 

straight :: v n -> Segment Closed v n Source

straight v constructs a translationally invariant linear segment with direction and length given by the vector v.

bezier3 :: v n -> v n -> v n -> Segment Closed v n Source

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.

bézier3 :: v n -> v n -> v n -> Segment Closed v n Source

bézier3 is the same as bezier3, but with more snobbery.

reverseSegment :: (Num n, Additive v) => Segment Closed v n -> Segment Closed v n Source

Reverse the direction of a segment.

mapSegmentVectors :: (v n -> v' n') -> Segment c v n -> Segment c v' n' Source

Map over the vectors of each segment.

openLinear :: Segment Open v n Source

An open linear segment. This means the trail makes a straight line from the last segment the beginning to form a loop.

openCubic :: v n -> v n -> Segment Open v n Source

An open cubic segment. This means the trail makes a cubic bézier with control vectors v1 and v2 to form a loop.

Fixed (absolutely located) segments

data FixedSegment v n Source

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.

Constructors

FLinear (Point v n) (Point v n) 
FCubic (Point v n) (Point v n) (Point v n) (Point v n) 

mkFixedSeg :: (Num n, Additive v) => Located (Segment Closed v n) -> FixedSegment v n Source

Create a FixedSegment from a located Segment.

fromFixedSeg :: (Num n, Additive v) => FixedSegment v n -> Located (Segment Closed v n) Source

Convert a FixedSegment back into a located Segment.

fixedSegIso :: (Num n, Additive v) => Iso' (FixedSegment v n) (Located (Segment Closed v n)) Source

Use a FixedSegment to make an Iso between an a fixed segment and a located segment.

Segment measures

Trails store a sequence of segments in a fingertree, which can automatically track various monoidal "measures" on segments.

newtype SegCount Source

A type to track the count of segments in a Trail.

Constructors

SegCount (Sum Int) 

newtype ArcLength n Source

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.

Constructors

ArcLength (Sum (Interval n), n -> Sum (Interval n)) 

getArcLengthCached :: ArcLength n -> Interval n Source

Project out the cached arc length, stored together with error bounds.

getArcLengthFun :: ArcLength n -> n -> Interval n Source

Project out the generic arc length function taking the tolerance as an argument.

getArcLengthBounded :: (Num n, Ord n) => n -> ArcLength n -> Interval n Source

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.

newtype TotalOffset v n Source

A type to represent the total cumulative offset of a chain of segments.

Constructors

TotalOffset (v n) 

data OffsetEnvelope v n Source

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 first into account.

Constructors

OffsetEnvelope 

Fields

_oeOffset :: !(TotalOffset v n)
 
_oeEnvelope :: Envelope v n
 

oeOffset :: forall v n. Lens' (OffsetEnvelope v n) (TotalOffset v n) Source

oeEnvelope :: forall v n. Lens' (OffsetEnvelope v n) (Envelope v n) Source

type SegMeasure v n = SegCount ::: (ArcLength n ::: (OffsetEnvelope v n ::: ())) Source

SegMeasure collects up all the measurements over a chain of segments.