-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneighbourhoods.lisp
35 lines (30 loc) · 1.18 KB
/
neighbourhoods.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
;;;; -*-lisp-*-
;;;;
;;;; neighbourhoods.lisp
(in-package #:ca)
(defun neighbourhood-variable (nb-name)
"Returns the neighbourhood's variable *<nb-name>-NB*."
(eval (find-symbol (concatenate 'string
"*"
(symbol-name nb-name)
"-NB*")
'ca)))
(defun cell-neighbourhoods (neighbourhoods bounds)
"Returns all cells' neighbourhoods in a cellular automaton
of dimensions specified by BOUNDS."
(mapcar (lambda (cell)
(mapcar (lambda (neighbourhood)
(point-to-index
(fix-bounds bounds (mapcar #'+ cell neighbourhood))
bounds))
neighbourhoods))
(get-all-cells bounds)))
(defun cell-neighbourhood (cells neighbourhood)
"Returns the values of the cells in NEIGHBOURHOOD."
(mapcar #'(lambda (index) (elt cells index))
neighbourhood))
(defvar *neumann-nb* '((0 0) (1 0) (0 1) (-1 0) (0 -1)))
(defvar *elementary-nb* '((-1) (0) (1)))
(defvar *moore-nb* '((0 0) (1 0) (0 1)
(-1 0) (0 -1) (1 1)
(-1 1) (-1 -1) (1 -1)))