File size: 1,243 Bytes
b82e8b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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();