网格中邻居的命名约定

Naming convention for neighbors in grid

我正在为此绞尽脑汁,无法想出一个好的命名解决方案,也许有人会在这里提出一个好的建议。

我有一个单元格 (x,y) 网格,我正在努力正确命名两个方法 return 给定单元格的邻居。

一种方法是return给定单元格的上下左右相邻。 (加号一共4个邻居)

第二个是return上、下、右、左、右上、左上、右下、左下的邻居(总共8个邻居,围绕单元格)

有人对我如何命名这些方法以恰当地反映它们在做什么有什么建议吗?

您可以将它们视为北、南、东和西。

那么你可以有 GetCardinalNeighboursGetInterCardinalNeighbours

Cardinal Directions

实际上已经存在确切的名称:

  • Von Neumann Neighborhood

    In cellular automata, the von Neumann neighborhood (or 4-neighborhood) is classically defined on a two-dimensional square lattice and is composed of a central cell and its four adjacent cells.

  • Moore Neighborhood

    In cellular automata, the Moore neighborhood is defined on a two-dimensional square lattice and is composed of a central cell and the eight cells that surround it.

而且它当然也连接到

中提到的像素连接

您可以使用像素连通性的概念来描述邻域。 Pixel connectivity Wikipedia article.

中对此进行了描述

术语 8 连接和 4 连接通常用于描述以下模式:

所以我的建议是将函数命名为 Get8ConnectedNeighboursGet4ConnectedNeighbours