0

问题:给定一个单元格索引(红色)计算围绕单元格索引的数组索引(黑色)。

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
}

计算在已知大小 (m X n X ... ) 的 N 维网格中围绕单元格的顶点。

示例图:

6 x 5 网格错字已修复

int vertices[4] = {0, 0, 0, 0}

上图中,CalculateCellVerticesFromIndex(12, vertices); 应该用 {14, 15, 20, 21} 填充顶点;

4

1 回答 1

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
于 2012-04-07T16:37:05.140 回答