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

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

Diagrams.TwoD.Offset

Contents

Description

Compute offsets to segments in two dimensions. More details can be found in the manual at http://projects.haskell.org/diagrams/doc/manual.html#offsets-of-segments-trails-and-paths.

Synopsis

Offsets

offsetSegment Source

Arguments

:: Double

Epsilon factor that when multiplied to the absolute value of the radius gives a value that represents the maximum allowed deviation from the true offset. In the current implementation each result segment should be bounded by arcs that are plus or minus epsilon factor from the radius of curvature of the offset.

-> Double

Offset from the original segment, positive is on the right of the curve, negative is on the left.

-> Segment Closed R2

Original segment

-> Located (Trail R2)

Resulting located (at the offset) trail.

data OffsetOpts Source

Compute the offset of a segment. Given a segment compute the offset curve that is a fixed distance from the original curve. For linear segments nothing special happens, the same linear segment is returned with a point that is offset by a perpendicular vector of the given offset length.

Cubic segments require a search for a subdivision of cubic segments that gives an approximation of the offset within the given epsilon factor (the given epsilon factor is applied to the radius giving a concrete epsilon value). We must do this because the offset of a cubic is not a cubic itself (the degree of the curve increases). Cubics do, however, approach constant curvature as we subdivide. In light of this we scale the handles of the offset cubic segment in proportion to the radius of curvature difference between the original subsegment and the offset which will have a radius increased by the offset parameter.

In the following example the blue lines are the original segments and the alternating green and red lines are the resulting offset trail segments.

Note that when the original curve has a cusp, the offset curve forms a radius around the cusp, and when there is a loop in the original curve, there can be two cusps in the offset curve.

Options for specifying line join and segment epsilon for an offset involving multiple segments.

Instances

Eq OffsetOpts 
Show OffsetOpts 
Default OffsetOpts

The default offset options use the default LineJoin (LineJoinMiter), a miter limit of 10, and epsilon factor of 0.01.

offsetJoin :: Lens' OffsetOpts LineJoin Source

Specifies the style of join for between adjacent offset segments.

offsetMiterLimit :: Lens' OffsetOpts Double Source

Specifies the miter limit for the join.

offsetTrail :: Double -> Located (Trail R2) -> Located (Trail R2) Source

Offset a Trail with the default options and a given radius. See offsetTrail'.

offsetTrail' Source

Arguments

:: OffsetOpts 
-> Double

Radius of offset. A negative value gives an offset on the left for a line and on the inside for a counter-clockwise loop.

-> Located (Trail R2) 
-> Located (Trail R2) 

Offset a Trail with options and by a given radius. This generates a new trail that is always radius r away from the given Trail (depending on the line join option) on the right.

The styles applied to an outside corner can be seen here (with the original trail in blue and the result of offsetTrail' in green):

When a negative radius is given, the offset trail will be on the left:

When offseting a counter-clockwise loop a positive radius gives an outer loop while a negative radius gives an inner loop (both counter-clockwise).

offsetPath :: Double -> Path R2 -> Path R2 Source

Offset a Path with the default options and given radius. See offsetPath'.

offsetPath' :: OffsetOpts -> Double -> Path R2 -> Path R2 Source

Offset a Path by applying offsetTrail' to each trail in the path.

Expansions

data ExpandOpts Source

Options for specifying how a Trail should be expanded.

Instances

Eq ExpandOpts 
Show ExpandOpts 
Default ExpandOpts

The default ExpandOpts is the default LineJoin (LineJoinMiter), miter limit of 10, default LineCap (LineCapButt), and epsilon factor of 0.01.

expandJoin :: Lens' ExpandOpts LineJoin Source

Specifies the style of join for between adjacent offset segments.

expandMiterLimit :: Lens' ExpandOpts Double Source

Specifies the miter limit for the join.

expandCap :: Lens' ExpandOpts LineCap Source

Specifies how the ends are handled.

expandTrail :: Double -> Located (Trail R2) -> Path R2 Source

Expand a Trail with the given radius and default options. See expandTrail'.

expandTrail' Source

Arguments

:: ExpandOpts 
-> Double

Radius of offset. Only non-negative values allowed. For a line this gives a loop of the offset. For a loop this gives two loops, the outer counter-clockwise and the inner clockwise.

-> Located (Trail R2) 
-> Path R2 

Expand a Trail with the given options and radius r around a given Trail. Expanding can be thought of as generating the loop that, when filled, represents stroking the trail with a radius r brush.

The cap styles applied to an outside corner can be seen here (with the original trail in white and the result of expandTrail' filled in green):

Loops result in a path with an inner and outer loop:

expandPath :: Double -> Path R2 -> Path R2 Source

Expand a Path with the given radius and default options. See expandPath'.

expandPath' :: ExpandOpts -> Double -> Path R2 -> Path R2 Source

Expand a Path using expandTrail' on each trail in the path.