Module forma.neighbourhood

Cell neighbourhood definitions.

The neighbourhood of a cell in a pattern defines which other cells are considered its neighbours. This is an important definition for many functions in forma. For example, when finding all cells that border a pattern in subpattern.edge a definition of border in terms of a neighbourhood is required. Cellular automata rules are also defined in terms of neighbourhoods.

This module provides a class to represent a neighbourhood, along with examples of typical neighbourhoods such as the Moore or von Neumann neighbourhoods.

Usage:

    -- Load some neighbourhoods to use with other functions
    local moore = neighbourhood.moore()
    local vn    = neighbourhood.von_neumann()
    
    -- Define a new neighbourhood from a table of forma.cells
    local cell_list = {cell.new(-1,1), cell.new(1,-1)}
    local new_neighbourhood = neighbourhood.new(cell_list)
    

Neighbourhoods

moore () The Moore neighbourhood.
von_neumann () The von Neumann neighbourhood.
diagonal () The diagonal neighbourhood.
diagonal_2 () The twice diagonal neighbourhood.

Functions

new (neighbour_cells) Generate a new neighbourhood from a set of cells.
categorise (nbh, ip, icell) Identify which category a cell in a pattern fits into.
category_label (nbh) Returns the category labelling (if it exists) for a neighbourhood.
get_ncategories (nbh) Returns the number of categories for a neighbourhood


Neighbourhoods

moore ()
The Moore neighbourhood. Wikipedia entry.

Contains all cells with Chebyshev distance 1 from origin. Used in Conway's Game of Life.

von_neumann ()
The von Neumann neighbourhood. Wikipedia entry.

Contains all cells with Manhattan distance 1 from origin.

diagonal ()
The diagonal neighbourhood.

Contains all cells diagonally bordering the origin. i.e the Moore neighbourhood with the von Neumann subtracted.

diagonal_2 ()
The twice diagonal neighbourhood.

Contains all cells two cells away from the origin along the diagonal axes.

Functions

new (neighbour_cells)
Generate a new neighbourhood from a set of cells.

Parameters:

  • neighbour_cells a list of neighbouring cell vectors

Returns:

    a forma.neighbourhood comprised of neighbour_cells
categorise (nbh, ip, icell)
Identify which category a cell in a pattern fits into. Categorises cells in a pattern according to their neighbourhood configuration. For each cell in a forma.pattern, there are a finite number of possible configurations of neighbouring cells. Specifically, each cell has 2^n possible neighbourhood configurations where n is the number of cells in the neighbourhood. This method categorises cells according to which type of neighbourhood they are in.

Parameters:

  • nbh the forma.neighbourhood to categorise the cell in
  • ip the input pattern
  • icell the cell in ip of interest

Returns:

    the category index of nbh that 'cell' belongs to
category_label (nbh)
Returns the category labelling (if it exists) for a neighbourhood.

Parameters:

  • nbh the neighbourhood to fetch the category labelling for.

Returns:

    a table of labels, one for each neighbourhood category.
get_ncategories (nbh)
Returns the number of categories for a neighbourhood

Parameters:

  • nbh the neighbourhood` in question

Returns:

    the number of categories for neighbourhood nbh
generated by LDoc 1.4.6 Last updated 2019-01-07 21:10:29