getParentCell method

VectorDefinition getParentCell(
  1. VectorDefinition position
)

Implementation

VectorDefinition getParentCell(VectorDefinition position) {
  var current = position;
  for (var depth = 0; depth < maxMergeSpan; depth++) {
    final cell = cells[current];
    final strategy = cell?.merge;
    if (strategy is MergedCellStrategy) {
      current = strategy.direction == CellMergeDirection.horizontal
          ? VectorDefinition(current.x - 1, current.y)
          : VectorDefinition(current.x, current.y - 1);
    } else {
      return current;
    }
  }
  return current;
}