folkertdev/one-true-path-experiment/2.0.0

NOTE: this package is not compatible with Elm 0.19.1

Segment

An alternative interpretation of paths that is convenient for mathematical operations.

Here, a path is viewed as a list of segments with a start and end point.

type Segment
= LineSegment (Vec2 Float) (Vec2 Float)
| Quadratic (Vec2 Float) (Vec2 Float) (Vec2 Float)
| Cubic (Vec2 Float) (Vec2 Float) (Vec2 Float) (Vec2 Float)
| Arc
{ start : Vec2 Float
, end : Vec2 Float
, radii : ( Float, Float )
, xAxisRotate : Float
, arcFlag : ArcFlag
, direction : Direction
}

The four types of segments.

For segments, the xAxisRotate field is in radians.

Operations

at : Float -> Segment -> ( Float, Float )

Get the location at a point on the curve, only defined in the range [0, 1].

length : Segment -> Float

The approximate length of a segment

{ minDepth : Int
, error : Float
}
-> Segment
-> Float

Supply the options for the approximation

  • minDepth: Minimum recursion depth for calculating the length of arc segments. Default is 10.
  • error: Minimal amount of progress that an recursive step must make. Default is 1.0e-12.
derivativeAtFirst : Segment -> Float2

The derivative at the starting point of the segment

derivativeAtFinal : Segment -> Float2

The derivative at the ending point of the segment

angle : Segment -> Segment -> Float

The angle between the end of segment1 and the start of segment2

startingPoint : Segment -> Vec2 Float

Extract the starting point from a segment

Conversion

toDrawTo : Segment -> DrawTo

Convert a segment to a drawto instruction.

toSegment : Segment -> DrawTo -> List Segment

Convert a drawto into a segment

This function needs the previous segment to the starting point and (for bezier curves) the control points