markCell method

void markCell(
  1. AutonomyGrid grid,
  2. GpsCoordinates gps,
  3. AutonomyCell value
)

Calculates a new position for gps based on centerPosition and adds it to the grid.

This function filters out any coordinates that shouldn't be shown based on gridSize.

Implementation

void markCell(AutonomyGrid grid, GpsCoordinates gps, AutonomyCell value) {
  // Latitude is y-axis, longitude is x-axis
  // The rover will occupy the center of the grid, so
  // - rover.longitude => (gridSize - 1) / 2
  // - rover.latitude => (gridSize - 1) / 2
  // Then, everything else should be offset by that
  final gridPosition = gps.toGridBlock(centerPosition);
  final x = gridPosition.dx.round();
  final y = gridPosition.dy.round();

  if (x < 0 || x >= gridSize) return;
  if (y < 0 || y >= gridSize) return;
  grid[y][x] = (coordinates: grid[y][x].coordinates, cellType: value);
}