void MakeConnectedVertical(QuadTreeConnectedNode downNode, QuadTreeConnectedNode upNode) { // 如果Pn裡的2個node都沒有child node,就為該2個node建立連結 if (!downNode.HasChild() && !upNode.HasChild()) { // https://plus.google.com/u/0/+XiangweiChiou/posts/EET3zRE8Awz if (!downNode.isOuter || !upNode.isOuter) { return; } downNode.upLink = new QuadTreeConnectedNode[1]; downNode.upLink[0] = upNode; upNode.downLink = new QuadTreeConnectedNode[1]; upNode.downLink[0] = downNode; verticalLinks.Add(new LinkInfo(downNode, upNode)); } else // 否則,向下遞迴找出邊界上子node,並相連 { var upSideNodes = new List <QuadTreeConnectedNode>(); if (!upNode.HasChild()) { upSideNodes.Add(upNode); } else { GetBorderNodes(upNode, new int[] { 0, 1 }, upSideNodes); } var downSideNodes = new List <QuadTreeConnectedNode>(); if (!downNode.HasChild()) { downSideNodes.Add(downNode); } else { GetBorderNodes(downNode, new int[] { 3, 2 }, downSideNodes); } connectTwoSide(false, downSideNodes, upSideNodes); } }
void MakeConnectedHorizontal(QuadTreeConnectedNode leftNode, QuadTreeConnectedNode rightNode) { // 如果Pn裡的2個node都沒有child node,就為該2個node建立連結 if (!leftNode.HasChild() && !rightNode.HasChild()) { // https://plus.google.com/u/0/+XiangweiChiou/posts/EET3zRE8Awz if (!leftNode.isOuter || !rightNode.isOuter) { return; } leftNode.rightLink = new QuadTreeConnectedNode[1]; leftNode.rightLink[0] = rightNode; rightNode.leftLink = new QuadTreeConnectedNode[1]; rightNode.leftLink[0] = leftNode; horizontalLinks.Add(new LinkInfo(leftNode, rightNode)); } else // 否則,向下遞迴找出邊界上子node,並相連 { var leftSideNodes = new List <QuadTreeConnectedNode>(); if (!leftNode.HasChild()) { leftSideNodes.Add(leftNode); } else { GetBorderNodes(leftNode, new int[] { 1, 2 }, leftSideNodes); } var rightSideNodes = new List <QuadTreeConnectedNode>(); if (!rightNode.HasChild()) { rightSideNodes.Add(rightNode); } else { GetBorderNodes(rightNode, new int[] { 0, 3 }, rightSideNodes); } connectTwoSide(true, leftSideNodes, rightSideNodes); } }
static void GetBorderNodes(QuadTreeConnectedNode targetNode, int[] borderIndex, List <QuadTreeConnectedNode> list) { if (!targetNode.HasChild()) { return; } foreach (var index in borderIndex) { var nowChildNode = targetNode.childs[index]; if (nowChildNode.HasChild()) { GetBorderNodes(nowChildNode, borderIndex, list); } else { list.Add(nowChildNode); } } }