alignPoints method

  1. @override
void alignPoints(
  1. Mobject mob
)
override

Implementation

@override
void alignPoints(Mobject mob) {
  assert(mob is VMobject);
  var vmob = mob as VMobject;

  alignColors(vmob);

  if (getNumPoints() == vmob.getNumPoints()) {
    return;
  }

  for (var mob in [this, vmob]) {
    if (mob.hasNoPoints()) {
      mob.startNewPath(mob.getCenter());
    }

    if (mob.hasNewPathStarted()) {
      mob.addLineTo(mob.getLastPoint());
    }
  }

  var subpaths1 = getSubpaths();
  var subpaths2 = vmob.getSubpaths();
  var numSubpaths = max(subpaths1.length, subpaths2.length);

  var newPath1 = <Vector3>[];
  var newPath2 = <Vector3>[];
  var nppc = nPointsPerCurve;

  SubPath getNthSubpath(List<SubPath> pathlist, n) {
    if (n >= pathlist.length) {
      return [for (var _ in range(end: nppc)) pathlist.last.last];
    }

    return pathlist[n];
  }

  for (var n in range(end: numSubpaths)) {
    var sp1 = getNthSubpath(subpaths1, n);
    var sp2 = getNthSubpath(subpaths2, n);

    var diff1 = max(0, (sp2.length - sp1.length) ~/ nppc);
    var diff2 = max(0, (sp1.length - sp2.length) ~/ nppc);

    sp1 = insertNCurvesToPointList(diff1, sp1);
    sp2 = insertNCurvesToPointList(diff2, sp2);

    newPath1.addAll(sp1);
    newPath2.addAll(sp2);
  }

  setPoints(newPath1);
  vmob.setPoints(newPath2);
}