3d-adjacency 中文文档教程

发布于 8年前 浏览 32 更新于 3年前

3d-adjacency

cdaringe/3d-adjacency 的代码状态覆盖状态

从 3d 数组中查找相邻单元格的“集群”。 该阵列不需要必须是立方体,但它确实需要是直角棱柱。

example

假设你有一个三维数组,里面全是 0 和 1。 0 是白色,1 是绿色。 ,它可能看起来像:

从图形上看

你想要的是一组相连的绿色单元格。 它可能看起来像:

从图形上看

, 这正是这个模块提供的! 雅虎!

const adj3d = require('3d-adjacency')
const exampleCube = [ // as shown above
    [
      [1, 0, 1], [0, 0, 0], [1, 0, 1],
    ],
    [
      [1, 0, 1], [0, 0, 0], [1, 0, 1],
    ],
    [
      [1, 0, 1], [0, 0, 0], [1, 0, 2],
    ],
]
const groups = adj3d.find(exampleCube)
// ==>
/*
[ // four groups of green blocks
  [
    { x: 0, y: 0, z: 0, value: 1 },
    { x: 1, y: 0, z: 0, value: 1 },
    { x: 2, y: 0, z: 0, value: 1 }
  ],
  [
    { x: 0, y: 0, z: 2, value: 1 },
    { x: 1, y: 0, z: 2, value: 1 },
    { x: 2, y: 0, z: 2, value: 1 }
  ],
  [
    { x: 0, y: 2, z: 0, value: 1 },
    { x: 1, y: 2, z: 0, value: 1 },
    { x: 2, y: 2, z: 0, value: 1 }
  ],
  [
    { x: 0, y: 2, z: 2, value: 1 },
    { x: 1, y: 2, z: 2, value: 1 },
    { x: 2, y: 2, z: 2, value: 2 }
  ]
]
*/

“嘿,为什么输出与输入不匹配相同的形式?”

有效的问题。 具体来说,输出是一组坐标+值的对象。 输入是实际数据。 尽管人们可能希望输出类似于 [ [0, 1, 2] ],其中 0, 1, 2 是坐标,但输入不是坐标集首先。

install

npm install --save 3d-adjacency

usage

请参阅上面的示例和官方 API 文档

changelog

  • 0.0.3 handle much larger arrays. remove recursive calls to keep stack down

3d-adjacency

Codeship Status for cdaringe/3d-adjacencyCoverage Status

find "clusters" of adjacent cells from a 3d array. the array does not need to be cubic, but it does need to be a rectangular prism.

example

suppose you had a three dimensional array, full of 0s and 1s. 0s are white, and 1s are green. graphically, it may look like:

what you desire is the sets of connected green cells. graphically, it may look like:

well, that's exactly what this module provides! yahoo!

const adj3d = require('3d-adjacency')
const exampleCube = [ // as shown above
    [
      [1, 0, 1], [0, 0, 0], [1, 0, 1],
    ],
    [
      [1, 0, 1], [0, 0, 0], [1, 0, 1],
    ],
    [
      [1, 0, 1], [0, 0, 0], [1, 0, 2],
    ],
]
const groups = adj3d.find(exampleCube)
// ==>
/*
[ // four groups of green blocks
  [
    { x: 0, y: 0, z: 0, value: 1 },
    { x: 1, y: 0, z: 0, value: 1 },
    { x: 2, y: 0, z: 0, value: 1 }
  ],
  [
    { x: 0, y: 0, z: 2, value: 1 },
    { x: 1, y: 0, z: 2, value: 1 },
    { x: 2, y: 0, z: 2, value: 1 }
  ],
  [
    { x: 0, y: 2, z: 0, value: 1 },
    { x: 1, y: 2, z: 0, value: 1 },
    { x: 2, y: 2, z: 0, value: 1 }
  ],
  [
    { x: 0, y: 2, z: 2, value: 1 },
    { x: 1, y: 2, z: 2, value: 1 },
    { x: 2, y: 2, z: 2, value: 2 }
  ]
]
*/

"Hey, why is output not matching the same form as the input?"

Valid question. Specifically, the output is a set of objects that are coordinates+values. the input is the actual data. Although one might expect the output to be something like [ [0, 1, 2] ], where 0, 1, 2 are coordinates, the input was not coordinate sets to begin with.

install

npm install --save 3d-adjacency

usage

See example above and the offcial API docs

changelog

  • 0.0.3 handle much larger arrays. remove recursive calls to keep stack down
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文