问题:给定单元格索引(红色)计算单元格索引周围的数组索引(黑色)。
bool CalculateCellVerticesFromIndex(size_t index, size_t* vertices)
{
size_t gridSize[2] = {6, 5};
return true; // if the index was valid
return false; // if the index was invalid
}
计算已知大小的N维网格中单元格周围的顶点(m X n X ...)。
示例图:
说int vertices[4] = {0, 0, 0, 0}
在上图中,CalculateCellVerticesFromIndex(12,vertices);应该用{14,15,20,21}填充顶点;
答案 0 :(得分:1)
Width = 6
Row = Index div (Width - 1)
if Row > 5 - 2 then OutOfGrid
Column = Index mod (Width - 1)
LeftBottom = Row * Width + Column
LeftTop = LeftBottom + Width
RightBottom and RightTop - elaborate