writePath method

void writePath(
  1. Path path,
  2. double progress, {
  3. double scaleX = 1,
  4. double scaleY = 1,
  5. double dx = 0,
  6. double dy = 0,
})

Writes the shape at progress into path, reset first: the same curves as asCubics (the last one closing exactly on the first anchor), each point scaled by (scaleX, scaleY) then offset by (dx, dy). Allocates nothing: it reads the matched cubics' own arrays and writes straight into the caller's reused path, so a morph animates without garbage per frame (Expressive's addition).

Implementation

void writePath(
  Path path,
  double progress, {
  double scaleX = 1,
  double scaleY = 1,
  double dx = 0,
  double dy = 0,
}) {
  path.reset();
  final count = _morphMatch.length;
  if (count == 0) return;
  final first0 = _morphMatch[0].$1._points;
  final first1 = _morphMatch[0].$2._points;
  final startX = _lerp(first0[0], first1[0], progress);
  final startY = _lerp(first0[1], first1[1], progress);
  path.moveTo(startX * scaleX + dx, startY * scaleY + dy);
  for (var i = 0; i < count; i++) {
    final a = _morphMatch[i].$1._points;
    final b = _morphMatch[i].$2._points;
    final last = i == count - 1;
    path.cubicTo(
      _lerp(a[2], b[2], progress) * scaleX + dx,
      _lerp(a[3], b[3], progress) * scaleY + dy,
      _lerp(a[4], b[4], progress) * scaleX + dx,
      _lerp(a[5], b[5], progress) * scaleY + dy,
      (last ? startX : _lerp(a[6], b[6], progress)) * scaleX + dx,
      (last ? startY : _lerp(a[7], b[7], progress)) * scaleY + dy,
    );
  }
  path.close();
}