mhwombat / grid

Tools for working with regular grids/graphs/lattices.
Other
106 stars 12 forks source link

center #1

Closed neapel closed 11 years ago

neapel commented 12 years ago

It would be helpful to have a method in the interface that returns the center of a grid, such that

center grid = snd $ minimum $ map (\x ->
  (sum $ map snd $ viewpoint x grid, x)) $
  indices grid

A grid implementation would of course know in O(1) where its center is, but code that is supposed to work with HexHexGrid as well as RectSquareGrid can't just use (0,0), for example.

mhwombat commented 12 years ago

That's a good idea. I'll have to think about how the centre should be defined for grids that don't have a boundary (like the torus), or to grids that would have multiple tiles tied for "centre", like a RectSquareGrid with sides that are even (e.g., 4x6). One option might be to modify the numbering scheme so that the centre of the grid (or at least one of the centres) is at (0,0).

mhwombat commented 11 years ago

Version 3.0 adds a centre function, a boundary function, and more. Note that this version changed the order of parameters for many functions. This makes it easier for the user to write mapping and folding operations.