code: def addJunctionPos(shape, fromPos, toPos):
      
      result = list(shape)
      if fromPos != shape[0]:
          result = [fromPos] + result
      if toPos != shape[-1]:
          result.append(toPos)
      return result
docs: Extends shape with the given positions in case they differ from the
      existing endpoints. assumes that shape and positions have the same dimensionality