const limbSeq = [ [1, 2], [2, 3], [3, 4], // 右腕 [1, 5], [5, 6], [6, 7], // 左腕 [1, 8], [8, 9], [9, 10], // 右胴→右脚 [1, 11], [11, 12], [12, 13], // 左胴→左脚 [1, 0], // 首 [0, 14], [14, 16], // 右目 [0, 15], [15, 17] // 左目 ]; let parentNodeIndices = Array(18).fill(-1); let childNodeIndices = Array(18).fill(-1); let outEdgeIndices = Array(18).fill(-1); let inEdgeIndices = Array(18).fill(-1); function initializeLimb() { limbSeq.forEach((limb, i) => { parentNodeIndices[limb[1]] = limb[0]; childNodeIndices[limb[0]] = limb[1]; outEdgeIndices[limb[0]] = i; inEdgeIndices[limb[1]] = i; }); } function findParentNodeIndex(nodeIndex) { return parentNodeIndices[nodeIndex]; } function findChildNodeIndex(nodeIndex) { return childNodeIndices[nodeIndex]; } function findOutEdgeIndex(nodeIndex) { return outEdgeIndices[nodeIndex]; } function findInEdgeIndex(nodeIndex) { return inEdgeIndices[nodeIndex]; } function findNextEdgeIndex(edgeIndex) { return findOutEdgeIndex(limbSeq[edgeIndex][1]); } function findPrevEdgeIndex(edgeIndex) { return findInEdgeIndex(limbSeq[edgeIndex][0]); } initializeLimb();