#793 Addition of inner_radius parameter in vision for get_neighbor[...] functions

Open hildobby hildobby
Showing 1 of 1 files from the diff.

@@ -133,7 +133,7 @@
Loading
133 133
        return self.iter_cell_list_contents(neighborhood)
134 134
135 135
    def iter_neighborhood(self, pos: Coordinate, moore: bool,
136 -
                          include_center: bool = False, radius: int = 1) -> Iterator[Coordinate]:
136 +
                          include_center: bool = False, radius: int = 1, inner_radius: int = 0) -> Iterator[Coordinate]:
137 137
        """ Return an iterator over cell coordinates that are in the
138 138
        neighborhood of a certain point.
139 139
@@ -146,6 +146,10 @@
Loading
146 146
            include_center: If True, return the (x, y) cell as well.
147 147
                            Otherwise, return surrounding cells only.
148 148
            radius: radius, in cells, of neighborhood to get.
149 +
            inner_radius: If defined, the inner radius will be
150 +
                          substracted from the radius of neighborhood
151 +
                          to get (also in number of cells).
152 +
                          Otherwise, the full radius is considered.
149 153
150 154
        Returns:
151 155
            A list of coordinate tuples representing the neighborhood. For
@@ -163,6 +167,8 @@
Loading
163 167
                # Skip coordinates that are outside manhattan distance
164 168
                if not moore and abs(dx) + abs(dy) > radius:
165 169
                    continue
170 +
                if abs(dx) < inner_radius and abs(dy) < inner_radius:
171 +
                    continue
166 172
                # Skip if not a torus and new coords out of bounds.
167 173
                if not self.torus and (not (0 <= dx + x < self.width) or not (0 <= dy + y < self.height)):
168 174
                    continue
@@ -179,7 +185,7 @@
Loading
179 185
                    yield coords
180 186
181 187
    def get_neighborhood(self, pos: Coordinate, moore: bool,
182 -
                         include_center: bool = False, radius: int = 1) -> List[Coordinate]:
188 +
                         include_center: bool = False, radius: int = 1, inner_radius: int = 0) -> List[Coordinate]:
183 189
        """ Return a list of cells that are in the neighborhood of a
184 190
        certain point.
185 191
@@ -192,17 +198,21 @@
Loading
192 198
            include_center: If True, return the (x, y) cell as well.
193 199
                            Otherwise, return surrounding cells only.
194 200
            radius: radius, in cells, of neighborhood to get.
201 +
            inner_radius: If defined, the inner radius will be
202 +
                          substracted from the radius of neighborhood
203 +
                          to get (also in number of cells).
204 +
                          Otherwise, the full radius is considered.
195 205
196 206
        Returns:
197 207
            A list of coordinate tuples representing the neighborhood;
198 208
            With radius 1, at most 9 if Moore, 5 if Von Neumann (8 and 4
199 209
            if not including the center).
200 210
201 211
        """
202 -
        return list(self.iter_neighborhood(pos, moore, include_center, radius))
212 +
        return list(self.iter_neighborhood(pos, moore, include_center, radius, inner_radius=0))
203 213
204 214
    def iter_neighbors(self, pos: Coordinate, moore: bool,
205 -
                       include_center: bool = False, radius: int = 1) -> Iterator[GridContent]:
215 +
                       include_center: bool = False, radius: int = 1, innner_radius: int = 0) -> Iterator[GridContent]:
206 216
        """ Return an iterator over neighbors to a certain point.
207 217
208 218
        Args:
@@ -215,6 +225,10 @@
Loading
215 225
                            Otherwise,
216 226
                            return surrounding cells only.
217 227
            radius: radius, in cells, of neighborhood to get.
228 +
            inner_radius: If defined, the inner radius will be
229 +
                          substracted from the radius of neighborhood
230 +
                          to get (also in number of cells).
231 +
                          Otherwise, the full radius is considered.
218 232
219 233
        Returns:
220 234
            An iterator of non-None objects in the given neighborhood;
@@ -227,7 +241,7 @@
Loading
227 241
        return self.iter_cell_list_contents(neighborhood)
228 242
229 243
    def get_neighbors(self, pos: Coordinate, moore: bool,
230 -
                      include_center: bool = False, radius: int = 1) -> List[Coordinate]:
244 +
                      include_center: bool = False, radius: int = 1, inner_radius: int = 0) -> List[Coordinate]:
231 245
        """ Return a list of neighbors to a certain point.
232 246
233 247
        Args:
@@ -240,6 +254,10 @@
Loading
240 254
                            Otherwise,
241 255
                            return surrounding cells only.
242 256
            radius: radius, in cells, of neighborhood to get.
257 +
            inner_radius: If defined, the inner radius will be
258 +
                          substracted from the radius of neighborhood
259 +
                          to get (also in number of cells).
260 +
                          Otherwise, the full radius is considered.
243 261
244 262
        Returns:
245 263
            A list of non-None objects in the given neighborhood;

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Coverage
mesa -0.16% 84.48%
Project Totals (17 files) 84.48%
Loading