transformPath function

Path transformPath(
  1. Path preInsertPath,
  2. Path b, [
  3. int delta = 1
])

Implementation

Path transformPath(Path preInsertPath, Path b, [int delta = 1]) {
  if (preInsertPath.length > b.length || preInsertPath.isEmpty || b.isEmpty) {
    return b;
  }

  // check the prefix
  for (int i = 0; i < preInsertPath.length - 1; i++) {
    if (preInsertPath[i] != b[i]) {
      return b;
    }
  }

  final prefix = preInsertPath.sublist(0, preInsertPath.length - 1);
  final suffix = b.sublist(preInsertPath.length);
  final preInsertLast = preInsertPath.last;
  final bAtIndex = b[preInsertPath.length - 1];

  prefix.add(preInsertLast <= bAtIndex ? bAtIndex + delta : bAtIndex);
  prefix.addAll(suffix);

  return prefix;
}