示例#1
0
 /// <summary>
 ///     初始化一个N阶八叉树根节点。
 /// </summary>
 /// <param name="n">子节点分割参数,子节点数量为 8^<paramref name="n" />。</param>
 /// <param name="position">该节点的位置。</param>
 /// <param name="size">该节点的边长。</param>
 public NOctCell(int n, Vector3 position, float size)
 {
     _node         = new NOctNode(n);
     Position      = position;
     Size          = size;
     LocalPosition = Vector3.zero;
 }
示例#2
0
        private NOctCell(NOctNode node)
        {
            _node = node;

            var p = node;

            while (p != null)
            {
                p = p.Parent;
            }
        }
示例#3
0
        public void EmptyNode()
        {
            var node = new NOctNode();

            Assert.AreEqual(0, node.N);
            Assert.AreEqual(0, node.ChildCount);
            Assert.AreEqual(0, node.ChildCapacity);
            Assert.AreEqual(0, node.DimensionalChildCapacity);

            Assert.AreEqual(NOctIndex.Invalid, node.Index);
            Assert.IsNull(node.Parent);
            Assert.IsTrue(node.IsRoot);
            Assert.AreEqual(node, node.FindRoot());

            Assert.IsTrue(node.IsLeaf);
        }
示例#4
0
        private void InitializeCells()
        {
            if (_rootCell != null)
            {
                throw new InvalidOperationException("Duplicated initialization call.");
            }
            if (GrowN < 1)
            {
                throw new InvalidOperationException("A value greater than 0 for grow exponent expected.");
            }

            var rootNode     = new NOctNode(GrowN);
            var rootCellSize = rootNode.DimensionalChildCapacity * LeafCellSize;

            _rootCell = new NOctCell(GrowN, transform.position, rootCellSize);
        }
示例#5
0
        private static void NRankNode(int n, int expectedChildCapacity, int expectedDimensionalChildCapacity)
        {
            var node = new NOctNode(n);

            Assert.AreEqual(n, node.N);
            Assert.AreEqual(0, node.ChildCount);
            Assert.AreEqual(expectedChildCapacity, node.ChildCapacity);
            Assert.AreEqual(expectedDimensionalChildCapacity, node.DimensionalChildCapacity);

            Assert.AreEqual(NOctIndex.Invalid, node.Index);

            Assert.IsNull(node.Parent);
            Assert.IsTrue(node.IsRoot);
            Assert.AreEqual(node, node.FindRoot());

            Assert.IsTrue(node.IsLeaf);
        }
示例#6
0
        public void IndexOfChild()
        {
            var n0 = new NOctNode(1);
            var n1 = new NOctNode(2);
            var n2 = new NOctNode(3);
            var n3 = new NOctNode();

            n0.SetChild(1, 1, 0, n1);
            n1.SetChild(2, 1, 1, n2);
            n2.SetChild(5, 3, 2, n3);

            Assert.AreEqual(n1.Index, n0.IndexOf(n1));
            Assert.AreEqual(new NOctIndex(6, 5, 1), n0.IndexOf(n2));
            Assert.AreEqual(new NOctIndex(53, 43, 10), n0.IndexOf(n3));
            Assert.AreEqual(n2.Index, n1.IndexOf(n2));
            Assert.AreEqual(new NOctIndex(21, 11, 10), n1.IndexOf(n3));
            Assert.AreEqual(n3.Index, n2.IndexOf(n3));
        }
示例#7
0
        public void DepthOfChild()
        {
            var n0 = new NOctNode(1);
            var n1 = new NOctNode(2);
            var n2 = new NOctNode(3);
            var n3 = new NOctNode(1);

            n0.SetChild(NOctIndex.Zero, n1);
            n1.SetChild(NOctIndex.Zero, n2);
            n2.SetChild(NOctIndex.Zero, n3);

            Assert.AreEqual(0, n0.DepthOf(n0));
            Assert.AreEqual(1, n0.DepthOf(n1));
            Assert.AreEqual(2, n0.DepthOf(n2));
            Assert.AreEqual(3, n0.DepthOf(n3));
            Assert.AreEqual(1, n1.DepthOf(n2));
            Assert.AreEqual(2, n1.DepthOf(n3));
            Assert.AreEqual(1, n2.DepthOf(n3));
        }
示例#8
0
        public void SetChild()
        {
            var parent1 = new NOctNode(2);

            var child1 = new NOctNode();

            parent1.SetChild(1, 1, 0, child1);
            Assert.AreEqual(parent1, child1.Parent);
            Assert.AreEqual(child1, parent1[1, 1, 0]);
            Assert.AreEqual(1, parent1.ChildCount);
            Assert.IsTrue(child1.IsLeaf);

            var child2 = new NOctNode();

            parent1.SetChild(1, 1, 0, child2);
            Assert.IsNull(child1.Parent);
            Assert.AreEqual(parent1, child2.Parent);
            Assert.AreEqual(child2, parent1[1, 1, 0]);
            Assert.AreEqual(1, parent1.ChildCount);
            Assert.IsTrue(child2.IsLeaf);

            parent1.SetChild(1, 1, 0, null);
            Assert.AreEqual(0, parent1.ChildCount);
            Assert.IsNull(child2.Parent);

            var parent2 = new NOctNode(1);

            parent2.SetChild(0, 0, 0, child1);
            Assert.AreEqual(parent2, child1.Parent);
            Assert.AreEqual(child1, parent2[0, 0, 0]);
            Assert.AreEqual(1, parent2.ChildCount);

            parent2.SetChild(0, 0, 1, child2);
            Assert.AreEqual(parent2, child2.Parent);
            Assert.AreEqual(child2, parent2[0, 0, 0]);
            Assert.AreEqual(2, parent2.ChildCount);

            parent2.SetChild(0, 1, 1, child2);
            Assert.AreEqual(parent2, child2.Parent);
            Assert.AreEqual(child2, parent2[0, 1, 1]);
            Assert.AreEqual(2, parent2.ChildCount);
        }
示例#9
0
        public void RankOfChild()
        {
            var root   = new NOctNode(1);
            var child1 = new NOctNode(2);

            root.SetChild(NOctIndex.Zero, child1);
            Assert.AreEqual(1, root.RankOf(child1));

            var child2 = new NOctNode(3);

            child1.SetChild(NOctIndex.Zero, child2);
            Assert.AreEqual(2, child1.RankOf(child2));
            Assert.AreEqual(3, root.RankOf(child2));

            var child3 = new NOctNode(1);

            child2.SetChild(NOctIndex.Zero, child3);
            Assert.AreEqual(3, child2.RankOf(child3));
            Assert.AreEqual(5, child1.RankOf(child3));
            Assert.AreEqual(6, root.RankOf(child3));
        }