CatmullRomSpline constructor

CatmullRomSpline(
  1. List<Offset> controlPoints, {
  2. double tension = 0.0,
  3. Offset? startHandle,
  4. Offset? endHandle,
})

Constructs a centripetal Catmull-Rom spline curve.

The controlPoints argument is a list of four or more points that describe the points that the curve must pass through.

The optional tension argument controls how tightly the curve approaches the given controlPoints. It must be in the range 0.0 to 1.0, inclusive. It defaults to 0.0, which provides the smoothest curve. A value of 1.0 produces a linear interpolation between points.

The optional endHandle and startHandle points are the beginning and ending handle positions. If not specified, they are created automatically by extending the line formed by the first and/or last line segment in the controlPoints, respectively. The spline will not go through these handle points, but they will affect the slope of the line at the beginning and end of the spline. The spline will attempt to match the slope of the line formed by the start or end handle and the neighboring first or last control point. The default is chosen so that the slope of the line at the ends matches that of the first or last line segment in the control points.

The controlPoints list must contain at least four control points to interpolate.

The internal curve data structures are lazily computed the first time transform is called. If you would rather pre-compute the structures, use CatmullRomSpline.precompute instead.

Implementation

CatmullRomSpline(
    List<Offset> controlPoints, {
      double tension = 0.0,
      Offset? startHandle,
      Offset? endHandle,
    }) : assert(tension <= 1.0, 'tension $tension must not be greater than 1.0.'),
         assert(tension >= 0.0, 'tension $tension must not be negative.'),
         assert(controlPoints.length > 3, 'There must be at least four control points to create a CatmullRomSpline.'),
         _controlPoints = controlPoints,
         _startHandle = startHandle,
         _endHandle = endHandle,
         _tension = tension,
         _cubicSegments = <List<Offset>>[];