build method
Builds the tape of characters to interpolate to and from.
Implementation
@override
String build(String a, String b) {
final tape = super.build(a, b);
final maxDistance = this.distance;
final int length = tape.characters.length;
final int maxIndex = length - 1;
if (a == b) {
if (repeatCharacters) {
return a * (maxDistance + 2);
} else {
return a;
}
}
if (length <= 2) {
final int halfDist = maxDistance ~/ 2;
return a * (halfDist + 1) + b * (halfDist + 1);
}
final StringBuffer newKit = StringBuffer();
int distance = maxDistance;
bool fromStart = true;
while (distance > 0) {
final progress = maxDistance - distance;
if (fromStart) {
final int start = min(progress, maxIndex - 1);
newKit.write(tape.characters.elementAt(start + 1));
// if (newKit.length >= maxDistance + 2) break;
} else {
final int end = max(maxIndex - progress, 1);
newKit.write(tape.characters.elementAt(end - 1));
// if (newKit.length >= maxDistance + 2) break;
}
distance--;
fromStart = !fromStart;
}
return a + newKit.toString() + b;
}