Copyright | (c) 2011-2013 diagrams-lib team (see LICENSE) |
---|---|
License | BSD-style (see LICENSE) |
Maintainer | diagrams-discuss@googlegroups.com |
Safe Haskell | None |
Language | Haskell2010 |
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.
- data Open
- data Closed
- data Offset c v n where
- OffsetOpen :: Offset Open v n
- OffsetClosed :: v n -> Offset Closed v n
- segOffset :: Segment Closed v n -> v n
- data Segment c v n
- straight :: v n -> Segment Closed v n
- bezier3 :: v n -> v n -> v n -> Segment Closed v n
- bézier3 :: v n -> v n -> v n -> Segment Closed v n
- reverseSegment :: (Num n, Additive v) => Segment Closed v n -> Segment Closed v n
- mapSegmentVectors :: (v n -> v' n') -> Segment c v n -> Segment c v' n'
- openLinear :: Segment Open v n
- openCubic :: v n -> v n -> Segment Open v n
- data FixedSegment v n
- mkFixedSeg :: (Num n, Additive v) => Located (Segment Closed v n) -> FixedSegment v n
- fromFixedSeg :: (Num n, Additive v) => FixedSegment v n -> Located (Segment Closed v n)
- fixedSegIso :: (Num n, Additive v) => Iso' (FixedSegment v n) (Located (Segment Closed v n))
- newtype SegCount = SegCount (Sum Int)
- newtype ArcLength n = ArcLength (Sum (Interval n), n -> Sum (Interval n))
- getArcLengthCached :: ArcLength n -> Interval n
- getArcLengthFun :: ArcLength n -> n -> Interval n
- getArcLengthBounded :: (Num n, Ord n) => n -> ArcLength n -> Interval n
- newtype TotalOffset v n = TotalOffset (v n)
- data OffsetEnvelope v n = OffsetEnvelope {
- _oeOffset :: !(TotalOffset v n)
- _oeEnvelope :: Envelope v n
- oeOffset :: forall v n. Lens' (OffsetEnvelope v n) (TotalOffset v n)
- oeEnvelope :: forall v n. Lens' (OffsetEnvelope v n) (Envelope v n)
- type SegMeasure v n = SegCount ::: (ArcLength n ::: (OffsetEnvelope v n ::: ()))
Open/closed tags
Type tag for closed segments.
Segment offsets
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.
OffsetOpen :: Offset Open v n | |
OffsetClosed :: v n -> Offset Closed v n |
Functor v => Functor (Offset c v) # | |
Eq (v n) => Eq (Offset c v n) # | |
Ord (v n) => Ord (Offset c v n) # | |
Show (v n) => Show (Offset c v n) # | |
Transformable (Offset c v n) # | |
(Additive v, Num n) => Reversing (Offset c v n) # | Reverses the direction of closed offsets. |
(~) * r (Offset c u n) => AffineMappable (Offset c v n) r # | |
(~) * r (Offset c u m) => LinearMappable (Offset c v n) r # | |
Each (Offset c v n) (Offset c v' n') (v n) (v' n') # | |
type V (Offset c v n) # | |
type N (Offset c v n) # | |
segOffset :: Segment Closed v n -> v n #
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
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.
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. |
straight :: v n -> Segment Closed v n #
constructs a translationally invariant linear
segment with direction and length given by the vector straight
vv
.
bezier3 :: v n -> v n -> v n -> Segment Closed v n #
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 #
bézier3
is the same as bezier3
, but with more snobbery.
reverseSegment :: (Num n, Additive v) => Segment Closed v n -> Segment Closed v n #
Reverse the direction of a segment.
mapSegmentVectors :: (v n -> v' n') -> Segment c v n -> Segment c v' n' #
Map over the vectors of each segment.
openLinear :: Segment Open v n #
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 #
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 #
FixedSegment
s are like Segment
s 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.
mkFixedSeg :: (Num n, Additive v) => Located (Segment Closed v n) -> FixedSegment v n #
Create a FixedSegment
from a located Segment
.
fromFixedSeg :: (Num n, Additive v) => FixedSegment v n -> Located (Segment Closed v n) #
Convert a FixedSegment
back into a located Segment
.
fixedSegIso :: (Num n, Additive v) => Iso' (FixedSegment v n) (Located (Segment Closed v n)) #
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.
A type to track the count of segments in a Trail
.
Semigroup SegCount # | |
Monoid SegCount # | |
Wrapped SegCount # | |
Rewrapped SegCount SegCount # | |
(Metric v, OrderedField n) => Measured (SegMeasure v n) (SegMeasure v n) # | |
(Metric v, Ord n, Floating n) => Measured (SegMeasure v n) (SegTree v n) # | |
(OrderedField n, Metric v) => Measured (SegMeasure v n) (Segment Closed v n) # | |
type Unwrapped SegCount # | |
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.
(Num n, Ord n) => Semigroup (ArcLength n) # | |
(Num n, Ord n) => Monoid (ArcLength n) # | |
Wrapped (ArcLength n) # | |
Rewrapped (ArcLength n) (ArcLength n') # | |
(Metric v, OrderedField n) => Measured (SegMeasure v n) (SegMeasure v n) # | |
(Metric v, Ord n, Floating n) => Measured (SegMeasure v n) (SegTree v n) # | |
(OrderedField n, Metric v) => Measured (SegMeasure v n) (Segment Closed v n) # | |
type Unwrapped (ArcLength n) # | |
getArcLengthCached :: ArcLength n -> Interval n #
Project out the cached arc length, stored together with error bounds.
getArcLengthFun :: ArcLength n -> n -> Interval n #
Project out the generic arc length function taking the tolerance as an argument.
getArcLengthBounded :: (Num n, Ord n) => n -> ArcLength n -> Interval n #
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 #
A type to represent the total cumulative offset of a chain of segments.
TotalOffset (v n) |
(Num n, Additive v) => Semigroup (TotalOffset v n) # | |
(Num n, Additive v) => Monoid (TotalOffset v n) # | |
Wrapped (TotalOffset v n) # | |
Rewrapped (TotalOffset v n) (TotalOffset v' n') # | |
type Unwrapped (TotalOffset v n) # | |
data OffsetEnvelope v n #
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.
OffsetEnvelope | |
|
(Metric v, OrderedField n) => Semigroup (OffsetEnvelope v n) # | |
(Metric v, OrderedField n) => Measured (SegMeasure v n) (SegMeasure v n) # | |
(Metric v, Ord n, Floating n) => Measured (SegMeasure v n) (SegTree v n) # | |
(OrderedField n, Metric v) => Measured (SegMeasure v n) (Segment Closed v n) # | |
oeOffset :: forall v n. Lens' (OffsetEnvelope v n) (TotalOffset v n) #
oeEnvelope :: forall v n. Lens' (OffsetEnvelope v n) (Envelope v n) #
type SegMeasure v n = SegCount ::: (ArcLength n ::: (OffsetEnvelope v n ::: ())) #
SegMeasure
collects up all the measurements over a chain of
segments.