recenterRover method

void recenterRover()

Determines the new offset based on the current roverPosition.

The autonomy grid is inherently unbounded, meaning we have to choose somewhere to bound the grid. We chose to draw a grid of size gridSize with the rover in the center. This means we need to add an offset to every other coordinates to draw it relative to the rover on-screen.

For example, say the rover is at (2, 3), and there is an obstacle at (1, 2), with a grid size of 11. The rover should be at the center, (5, 5), so we need to add an offset of (3, 2) to get it there. That means we should also add (3, 2) to the obstacle's position so it remains (-1, -1) away from the rover's new position, yielding (4, 4).

Implementation

void recenterRover() {
    // final position = isPlayingBadApple ? GpsCoordinates() : roverPosition;
    final position = isPlayingBadApple ? GpsCoordinates(latitude: (gridSize ~/ 2).toDouble(), longitude: (gridSize ~/ 2).toDouble()) : roverPosition;
	final midpoint = ((gridSize - 1) / 2).floor();
	final offsetX = midpoint - -1 * gpsToBlock(position.longitude);
	final offsetY = midpoint - gpsToBlock(position.latitude);
	offset = GridOffset(offsetX, offsetY);
	notifyListeners();
}