top method Null safety

int top(
  1. Box cube,
  2. Direction direction,
  3. int position,
  4. List<int> moment
)

Implementation

static int top(
    Box cube, Direction direction, int position, List<int> moment) {
  switch (direction) {
    case Direction.red:
      return (moment[getIndex(position, cube.g1, cube.b1)] -
          moment[getIndex(position, cube.g1, cube.b0)] -
          moment[getIndex(position, cube.g0, cube.b1)] +
          moment[getIndex(position, cube.g0, cube.b0)]);
    case Direction.green:
      return (moment[getIndex(cube.r1, position, cube.b1)] -
          moment[getIndex(cube.r1, position, cube.b0)] -
          moment[getIndex(cube.r0, position, cube.b1)] +
          moment[getIndex(cube.r0, position, cube.b0)]);
    case Direction.blue:
      return (moment[getIndex(cube.r1, cube.g1, position)] -
          moment[getIndex(cube.r1, cube.g0, position)] -
          moment[getIndex(cube.r0, cube.g1, position)] +
          moment[getIndex(cube.r0, cube.g0, position)]);
    default:
      throw 'unexpected direction $direction';
  }
}