Position constructor

Position({
  1. int row = -1,
  2. int column = -1,
  3. int index = -1,
})

Construct a cell position, using either a row/column pair, or index

Implementation

Position({int row = -1, int column = -1, int index = -1}) {
  /// If index is supplied
  if (index != -1) {
    grid = new Point((index / 9).floor(), index % 9);
    segment = _segmentFromGridPos(grid!.x as int, grid!.y as int);
    this.index = index;

    /// If row/column is supplied
  } else if (row != -1 && column != -1) {
    grid = new Point(row, column);
    segment = _segmentFromGridPos(row, column);
    this.index = (row * 9) + column;

    /// If nothing is supplied (hey, that's illegal)
  } else {
    throw new InvalidPositionException("Cannot generate Position without "
        "row/column, or cell index");
  }
}