コード例 #1
0
ファイル: AABBTree.cs プロジェクト: sta1216/AABBTree
        public void add(AABBExternalNode externalNode, AABBBox extents)
        {
            var endNode = this.getNodeCount();

            externalNode.spatialIndex = endNode - 1;

            var node = new AABBTreeNode(new AABBBox(), 1, null);

            node.escapeNodeOffset = 1;
            node.externalNode     = externalNode;
            var copyExtents = node.extents;

            copyExtents[0] = extents[0];
            copyExtents[1] = extents[1];
            copyExtents[2] = extents[2];
            copyExtents[3] = extents[3];
            copyExtents[4] = extents[4];
            copyExtents[5] = extents[5];

            this.nodes.Add(node);
            this.needsRebuild      = true;
            this.numAdds          += 1;
            this.numExternalNodes += 1;
        }
コード例 #2
0
        double getkeyXfn(AABBTreeNode node)
        {
            var extents = node.extents;

            return(extents[0] + extents[3]);
        }
コード例 #3
0
        double getreversekeyZfn(AABBTreeNode node)
        {
            var extents = node.extents;

            return(-(extents[2] + extents[5]));
        }
コード例 #4
0
        double getreversekeyXfn(AABBTreeNode node)
        {
            var extents = node.extents;

            return(-(extents[0] + extents[3]));
        }
コード例 #5
0
        double getkeyZfn(AABBTreeNode node)
        {
            var extents = node.extents;

            return(extents[2] + extents[5]);
        }
コード例 #6
0
        double getreversekeyYfn(AABBTreeNode node)
        {
            var extents = node.extents;

            return(-(extents[1] + extents[4]));
        }
コード例 #7
0
        double getkeyYfn(AABBTreeNode node)
        {
            var extents = node.extents;

            return(extents[1] + extents[4]);
        }
コード例 #8
0
ファイル: AABBTree.cs プロジェクト: sta1216/AABBTree
 private void _replaceNode(List <AABBTreeNode> nodes, int nodeIndex, AABBTreeNode newNode)
 {
     nodes[nodeIndex] = newNode;
 }
コード例 #9
0
ファイル: AABBTree.cs プロジェクト: sta1216/AABBTree
        private void _recursiveBuild(List <AABBTreeNode> buildNodes, int startIndex, int endIndex, int lastNodeIndex)
        {
            var nodes     = this.nodes;
            var nodeIndex = lastNodeIndex;

            lastNodeIndex += 1;

            double       minX, minY, minZ, maxX, maxY, maxZ;
            AABBBox      extents;
            AABBTreeNode buildNode, lastNode;

            if ((startIndex + this.numNodesLeaf) >= endIndex)
            {
                buildNode = buildNodes[startIndex];
                extents   = buildNode.extents;
                minX      = extents[0];
                minY      = extents[1];
                minZ      = extents[2];
                maxX      = extents[3];
                maxY      = extents[4];
                maxZ      = extents[5];

                buildNode.externalNode.spatialIndex = lastNodeIndex;
                this._replaceNode(nodes, lastNodeIndex, buildNode);

                for (var n = (startIndex + 1); n < endIndex; n += 1)
                {
                    buildNode = buildNodes[n];
                    extents   = buildNode.extents;
                    /*jshint white: false*/
                    if (minX > extents[0])
                    {
                        minX = extents[0];
                    }
                    if (minY > extents[1])
                    {
                        minY = extents[1];
                    }
                    if (minZ > extents[2])
                    {
                        minZ = extents[2];
                    }
                    if (maxX < extents[3])
                    {
                        maxX = extents[3];
                    }
                    if (maxY < extents[4])
                    {
                        maxY = extents[4];
                    }
                    if (maxZ < extents[5])
                    {
                        maxZ = extents[5];
                    }
                    /*jshint white: true*/
                    lastNodeIndex += 1;
                    buildNode.externalNode.spatialIndex = lastNodeIndex;
                    this._replaceNode(nodes, lastNodeIndex, buildNode);
                }

                lastNode = nodes[lastNodeIndex];
            }
            else
            {
                /* tslint:disable:no-bitwise */
                var splitPosIndex = ((startIndex + endIndex) >> 1);
                /* tslint:enable:no-bitwise */

                if ((startIndex + 1) >= splitPosIndex)
                {
                    buildNode = buildNodes[startIndex];
                    buildNode.externalNode.spatialIndex = lastNodeIndex;
                    this._replaceNode(nodes, lastNodeIndex, buildNode);
                }
                else
                {
                    this._recursiveBuild(buildNodes, startIndex, splitPosIndex, lastNodeIndex);
                }

                lastNode = nodes[lastNodeIndex];
                extents  = lastNode.extents;
                minX     = extents[0];
                minY     = extents[1];
                minZ     = extents[2];
                maxX     = extents[3];
                maxY     = extents[4];
                maxZ     = extents[5];

                lastNodeIndex = (lastNodeIndex + lastNode.escapeNodeOffset);

                if ((splitPosIndex + 1) >= endIndex)
                {
                    buildNode = buildNodes[splitPosIndex];
                    buildNode.externalNode.spatialIndex = lastNodeIndex;
                    this._replaceNode(nodes, lastNodeIndex, buildNode);
                }
                else
                {
                    this._recursiveBuild(buildNodes, splitPosIndex, endIndex, lastNodeIndex);
                }

                lastNode = nodes[lastNodeIndex];
                extents  = lastNode.extents;
                /*jshint white: false*/
                if (minX > extents[0])
                {
                    minX = extents[0];
                }
                if (minY > extents[1])
                {
                    minY = extents[1];
                }
                if (minZ > extents[2])
                {
                    minZ = extents[2];
                }
                if (maxX < extents[3])
                {
                    maxX = extents[3];
                }
                if (maxY < extents[4])
                {
                    maxY = extents[4];
                }
                if (maxZ < extents[5])
                {
                    maxZ = extents[5];
                }
                /*jshint white: true*/
            }

            var node = nodes[nodeIndex];

            if (node == null)
            {
                nodes[nodeIndex] = node = new AABBTreeNode(new AABBBox(), 1, null);
            }
            node.reset(minX, minY, minZ, maxX, maxY, maxZ,
                       (lastNodeIndex + lastNode.escapeNodeOffset - nodeIndex));
        }