Skip to content

Coordinates on grid are used inconsistently throughout the code #194

@ReblochonMasque

Description

@ReblochonMasque

I am opening this issue as a general case of this earlier one: #191 that identifies a specific mix up in the height/width of the canvas. A related question was asked in the mailing list by Victor Norman on Dec 25th 2015.

  • I noticed that the coordinates for row, _row, height, y, _y and col, _col, width, x, _x are used in the order (a, b) and (b, a) indiscriminately throughout the code.
  • As shown above, the naming of these indices varies.

This leads to confusion and must be fixed. This is not an easy task.

My suggestion is to proceed in two steps:

  • First, we need to rename the variables to _row and _col throughout the code, which may or may not break the examples, depending on how class attributes are accessed. This is a deep undertaking as, as far as I can tell, every single class is affected; I doubt we can do this one class at a time.
  • Second, (that will break the examples, and should be in the milestone "The Rebirth"), is to rewrite the classes using consistent signatures for all methods. My suggestion here would be to use a class Position to encapsulate the indices; maybe we could use a named Tuple, or an extension of named Tuples?

Depending on the timeline of "The Rebirth", we might be able to skip the first step and concentrate our energies on the second step

Here are two examples extracted from #191:
From Grid() in mesa.space.py:

for row in range(self.height):
    for col in range(self.width):
        yield self.grid[row][col], col, row  # agent, x, y
 ---------------->>     Y    X     X    Y

From test_grid.py :

for agent in self.agents:
    x, y = agent.pos
    assert self.grid[y][x] == agent          # X, Y  <==>  Y, X

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions