MCPcopy Create free account
hub / github.com/BindsNET/bindsnet / movePoint

Method movePoint

bindsnet/environment/dot_simulator.py:282–362  ·  view source on GitHub ↗

Apply clockwise directional enumeration. :param dotDir: enumerated movement as described above. :param/return r: current row => next row :param/return c: current column => next column

(self, d: Dot, dotDir: int = -1)

Source from the content-addressed store, hash-verified

280 return self.obs
281
282 def movePoint(self, d: Dot, dotDir: int = -1):
283 """
284 Apply clockwise directional enumeration.
285
286 :param dotDir: enumerated movement as described above.
287 :param/return r: current row => next row
288 :param/return c: current column => next column
289 """
290
291 # If not provided, use the known current direction.
292 targetDir = False # flag if we're using the target's direction.
293 if dotDir < 0:
294 dotDir = self.dotDir
295 targetDir = True
296
297 r, c = d.row[0], d.col[0]
298
299 """ Apply clockwise directional enumeration. """
300 # 0 means stay, though we also won't go past the edge.
301 if dotDir == 1: # up
302 r += self.speed
303 elif dotDir == 2: # right
304 c += self.speed
305 elif dotDir == 3: # down
306 r -= self.speed
307 elif dotDir == 4: # left
308 c -= self.speed
309 elif dotDir == 5: # up and right
310 r += self.speed
311 c += self.speed
312 elif dotDir == 6: # down and right
313 r -= self.speed
314 c += self.speed
315 elif dotDir == 7: # down and left
316 r -= self.speed
317 c -= self.speed
318 elif dotDir == 8: # up and left
319 r += self.speed
320 c -= self.speed
321 elif dotDir != 0: # Woops
322 assert False, "Unsupported dot direction"
323
324 """ When a dot attempts to move past an edge... """
325 # Stay put.
326 if self.b_handling == 0:
327 r = max(min(r, self.h - 1), 0)
328 c = max(min(c, self.w - 1), 0)
329 # direction stays the same.
330
331 # Bounce: reflect its coordinates back into the region.
332 elif self.b_handling == 1:
333 if r < 0 or self.h <= r:
334 r = self.h - 1 - r % self.h # reflect row
335 if targetDir:
336 self.dotDir += ROW_CROSSING[dotDir]
337
338 if c < 0 or self.w <= c:
339 c = self.w - 1 - c % self.w # reflect column

Callers 1

stepMethod · 0.95

Calls 1

moveMethod · 0.80

Tested by

no test coverage detected