@@ -598,10 +598,10 @@ class HexGrid(Grid):
598
598
def torus_adj_2d (self , pos : Coordinate ) -> Coordinate :
599
599
return pos [0 ] % self .width , pos [1 ] % self .height
600
600
601
- def iter_neighborhood (
601
+ def get_neighborhood (
602
602
self , pos : Coordinate , include_center : bool = False , radius : int = 1
603
- ) -> Iterator [Coordinate ]:
604
- """Return an iterator over cell coordinates that are in the
603
+ ) -> list [Coordinate ]:
604
+ """Return a list of coordinates that are in the
605
605
neighborhood of a certain point. To calculate the neighborhood
606
606
for a HexGrid the parity of the x coordinate of the point is
607
607
important, the neighborhood can be sketched as:
@@ -617,7 +617,7 @@ def iter_neighborhood(
617
617
radius: radius, in cells, of neighborhood to get.
618
618
619
619
Returns:
620
- An iterator of coordinate tuples representing the neighborhood. For
620
+ A list of coordinate tuples representing the neighborhood. For
621
621
example with radius 1, it will return list with number of elements
622
622
equals at most 9 (8) if Moore, 5 (4) if Von Neumann (if not
623
623
including the center).
@@ -626,8 +626,7 @@ def iter_neighborhood(
626
626
neighborhood = self ._neighborhood_cache .get (cache_key , None )
627
627
628
628
if neighborhood is not None :
629
- yield from neighborhood
630
- return
629
+ return neighborhood
631
630
632
631
queue = collections .deque ()
633
632
queue .append (pos )
@@ -687,7 +686,7 @@ def iter_neighborhood(
687
686
neighborhood = sorted (coordinates )
688
687
self ._neighborhood_cache [cache_key ] = neighborhood
689
688
690
- yield from neighborhood
689
+ return neighborhood
691
690
692
691
def neighbor_iter (self , pos : Coordinate ) -> Iterator [Agent ]:
693
692
"""Iterate over position neighbors.
@@ -702,11 +701,11 @@ def neighbor_iter(self, pos: Coordinate) -> Iterator[Agent]:
702
701
)
703
702
return self .iter_neighbors (pos )
704
703
705
- def get_neighborhood (
704
+ def iter_neighborhood (
706
705
self , pos : Coordinate , include_center : bool = False , radius : int = 1
707
- ) -> list [Coordinate ]:
708
- """Return a list of cells that are in the neighborhood of a
709
- certain point.
706
+ ) -> Iterator [Coordinate ]:
707
+ """Return an iterator over cell coordinates that are in the
708
+ neighborhood of a certain point.
710
709
711
710
Args:
712
711
pos: Coordinate tuple for the neighborhood to get.
@@ -715,10 +714,9 @@ def get_neighborhood(
715
714
radius: radius, in cells, of neighborhood to get.
716
715
717
716
Returns:
718
- A list of coordinate tuples representing the neighborhood;
719
- With radius 1
717
+ An iterator of coordinate tuples representing the neighborhood.
720
718
"""
721
- return list ( self .iter_neighborhood (pos , include_center , radius ) )
719
+ yield from self .get_neighborhood (pos , include_center , radius )
722
720
723
721
def iter_neighbors (
724
722
self , pos : Coordinate , include_center : bool = False , radius : int = 1
0 commit comments