gzone.py 653 B

1234567891011121314151617181920212223
  1. '''
  2. Created on 19 nov. 2016
  3. @author: olinox
  4. '''
  5. from core.geometry import gneighbours
  6. def zone(grid_shape, x0, y0, radius):
  7. """ returns the list of the coordinates of the cells in the zone around (x0, y0)
  8. """
  9. if not all(isinstance(c, int) for c in [x0, y0, radius]):
  10. raise TypeError("x0, y0, radius have to be integers")
  11. if not radius >= 0:
  12. raise ValueError("radius has to be positive")
  13. buffer = frozenset( [ (x0, y0) ] )
  14. for _ in range(0, radius):
  15. current = buffer
  16. for x, y in current:
  17. buffer |= frozenset( gneighbours.neighbours_of( grid_shape, x, y ) )
  18. return list(buffer)