add method

void add(
  1. Offset point, {
  2. double? pressure,
})

Adds a new point to the active path. This method calculates new cubic line segments and updates the path.

point The new Offset to add to the path. pressure The pressure at the new point.

Implementation

void add(Offset point, {double? pressure}) {
  assert(_origin != null);

  final nextPoint = point is OffsetPoint
      ? point
      : OffsetPoint.from(point, pressure: pressure);

  if (_lastPoint == null ||
      _lastPoint!.distanceTo(nextPoint) < setup.threshold) {
    return;
  }

  _points.add(nextPoint);
  int count = _points.length;

  if (count < 3) {
    return;
  }

  int i = count - 3;

  final prev = i > 0 ? _points[i - 1] : _points[i];
  final start = _points[i];
  final end = _points[i + 1];
  final next = _points[i + 2];

  final cpStart = CubicLine.softCP(
    start,
    previous: prev,
    next: end,
    smoothing: setup.smoothRatio,
  );

  final cpEnd = CubicLine.softCP(
    end,
    previous: start,
    next: next,
    smoothing: setup.smoothRatio,
    reverse: true,
  );

  final line = CubicLine(
    start: start,
    cpStart: cpStart,
    cpEnd: cpEnd,
    end: end,
  );

  _addLine(line);
}