changeAnchorMode method

void changeAnchorMode(
  1. String mode
)

Implementation

void changeAnchorMode(String mode) {
  assert(mode == 'jagged' || mode == 'smooth');
  var nppc = nPointsPerCurve;

  for (var submob in getVectorizedFamily()) {
    var subpaths = submob.getSubpaths();
    submob.clearPoints();

    for (var subpath in subpaths) {
      var anchors = [
        ...subpath.whereIndexed((index, element) => index % nppc == 0),
        subpath.last
      ];

      List<Vector3> h1, h2;

      if (mode == 'smooth') {
        var handles = getSmoothHandlePoints(anchors);
        h1 = handles.item1;
        h2 = handles.item2;
      } else {
        // mode == 'jagged'

        var a1 = withoutLast(anchors);
        var a2 = withoutFirst(anchors);

        h1 = [
          for (var v in IterableZip([a1, a2]))
            interpolateValue(v[0], v[1], 1.0 / 3.0)
        ];

        h2 = [
          for (var v in IterableZip([a1, a2]))
            interpolateValue(v[0], v[1], 2.0 / 3.0)
        ];
      }

      var newSubpath = [
        for (var iPt in enumerate(subpath))
          if (iPt.item1 % nppc == 1)
            h1[iPt.item1]
          else if (iPt.item1 % nppc == 2)
            h2[iPt.item1]
          else
            iPt.item2
      ];

      appendPoints(newSubpath);
    }
  }
}