All problems

Negative Map Coordinates Are Assigned to the Wrong Grid Cell

Level 2 · node · Correctness · Truncation toward zero for negative spatial indices

Scenario

A fictional indoor delivery robot service uses a grid map that extends to the left and below the origin. Each cell is two meters wide, and a coordinate's cell index is defined as the mathematical floor of the coordinate divided by the cell size. The location service works for positive positions but assigns negative positions to the wrong cells.

Requirements

Calculate the column and row independently using floor(x / cellSize) and floor(y / cellSize). Handle positive coordinates, zero, negative positions, and exact negative cell boundaries. Coordinates are finite numbers and cellSize is a positive finite number.

Acceptance criteria

  • Positive coordinates map to their correct grid indices.
  • The origin belongs to grid cell (0, 0).
  • Positions between zero and the first negative cell boundary have negative indices.
  • More distant negative positions map to the correct cell on each axis.