Copyright | (c) 2013 diagrams-lib team (see LICENSE) |
---|---|

License | BSD-style (see LICENSE) |

Maintainer | diagrams-discuss@googlegroups.com |

Safe Haskell | None |

Language | Haskell2010 |

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.

- offsetSegment :: Double -> Double -> Segment Closed R2 -> Located (Trail R2)
- data OffsetOpts = OffsetOpts {}
- offsetJoin :: Lens' OffsetOpts LineJoin
- offsetMiterLimit :: Lens' OffsetOpts Double
- offsetEpsilon :: Lens' OffsetOpts Double
- offsetTrail :: Double -> Located (Trail R2) -> Located (Trail R2)
- offsetTrail' :: OffsetOpts -> Double -> Located (Trail R2) -> Located (Trail R2)
- offsetPath :: Double -> Path R2 -> Path R2
- offsetPath' :: OffsetOpts -> Double -> Path R2 -> Path R2
- data ExpandOpts = ExpandOpts {}
- expandJoin :: Lens' ExpandOpts LineJoin
- expandMiterLimit :: Lens' ExpandOpts Double
- expandCap :: Lens' ExpandOpts LineCap
- expandEpsilon :: Lens' ExpandOpts Double
- expandTrail :: Double -> Located (Trail R2) -> Path R2
- expandTrail' :: ExpandOpts -> Double -> Located (Trail R2) -> Path R2
- expandPath :: Double -> Path R2 -> Path R2
- expandPath' :: ExpandOpts -> Double -> Path R2 -> Path R2

# Offsets

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

Eq OffsetOpts | |

Show OffsetOpts | |

Default OffsetOpts | The default offset options use the default |

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.

offsetEpsilon :: Lens' OffsetOpts Double Source

Epsilon perimeter for `offsetSegment`

.

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

Offset a `Trail`

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

.

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

Eq ExpandOpts | |

Show ExpandOpts | |

Default ExpandOpts | The default |

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.

expandEpsilon :: Lens' ExpandOpts Double Source

Epsilon perimeter for `offsetSegment`

.

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

Expand a `Trail`

with the given radius and default options. See `expandTrail'`

.

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