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

Safe HaskellNone



Compute offsets to segments in two dimensions.





:: Double

Epsilon 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 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

-> (Point R2, Trail R2)

Resulting offset point and trail.

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