appendPattern static method

int appendPattern(
  1. List<bool> target,
  2. int pos,
  3. List<int> pattern,
  4. bool startColor,
)

@param target encode black/white pattern into this array @param pos position to start encoding at in target @param pattern lengths of black/white runs to encode @param startColor starting color - false for white, true for black @return the number of elements added to target.

Implementation

static int appendPattern(
  List<bool> target,
  int pos,
  List<int> pattern,
  bool startColor,
) {
  bool color = startColor;
  int numAdded = 0;
  for (int len in pattern) {
    for (int j = 0; j < len; j++) {
      target[pos++] = color;
    }
    numAdded += len;
    color = !color; // flip color after each segment
  }
  return numAdded;
}