コード例 #1
0
        private float SpanByAxis(Axis axis, KdTreeHolder <T> holder)
        {
            var axisMin = ByAxis(axis, holder.fatRect.min);
            var axisMax = ByAxis(axis, holder.fatRect.max);

            return(axisMax - axisMin);
        }
コード例 #2
0
        private void AddAndRefreshInternal(KdTreeHolder <T> holder)
        {
            AssertConsistency();
            KdTreeNode <T> fittingLeaf = DetermineFittingLeaf(holder);

            AddInternal(holder, fittingLeaf);
            RefreshAndMarkParents(fittingLeaf);
            AssertConsistency();
        }
コード例 #3
0
        private KdTreeNode <T> DetermineFittingLeaf(KdTreeHolder <T> holder)
        {
            var node = root;

            while (node.type == NodeType.Inner)
            {
                node = node.DetermineInnerNode(holder);
            }
            return(node);
        }
コード例 #4
0
        private void RemoveInternal(KdTreeHolder <T> holder)
        {
            var node = holder.parent;

            holder.RemoveFromHolderList();
            while (node != null)
            {
                node.count--;
                node = node.parent;
            }
        }
コード例 #5
0
        private void AddInternal(KdTreeHolder <T> holder, KdTreeNode <T> newParent)
        {
            holder.AddToHolderList(newParent);
            var node = newParent;

            while (node != null)
            {
                node.count++;
                node = node.parent;
            }
        }
コード例 #6
0
        public void AddToHolderList(KdTreeNode <T> newParent)
        {
            KdTreeHolder <T> oldfirst = newParent.leaf.holder;

            newParent.leaf.holder = this;
            if (oldfirst != null)
            {
                oldfirst.sibling.prev = this;
            }
            parent       = newParent;
            sibling.next = oldfirst;
            sibling.prev = null;
        }
コード例 #7
0
 private AaRect?CalculateNewBounds()
 {
     if (type == NodeType.Leaf)
     {
         AaRect?          newBounds = null;
         KdTreeHolder <T> holder    = leaf.holder;
         while (holder != null)
         {
             newBounds = AaRects.MergeNullable(newBounds, holder.fatRect);
             holder    = holder.sibling.next;
         }
         return(newBounds);
     }
     return(AaRects.MergeNullable(inner.nodeLess.bounds, inner.nodeBoth.bounds, inner.nodeMore.bounds));
 }
コード例 #8
0
        public KdTreeNode <T> DetermineInnerNode(KdTreeHolder <T> holder)
        {
            var pos = DetermineInnerNodePosition(holder.fatRect);

            switch (pos)
            {
            case ChildPosition.Less:
                return(inner.nodeLess);

            case ChildPosition.More:
                return(inner.nodeMore);

            default:
                return(inner.nodeBoth);
            }
        }
コード例 #9
0
        private void UpdateAndRefreshInternal(KdTreeHolder <T> holder)
        {
            AssertConsistency();
            if (!holder.Update(this))
            {
                return;
            }
            KdTreeNode <T> oldLeaf = holder.parent;
            KdTreeNode <T> newLeaf = DetermineFittingLeaf(holder);

            if (oldLeaf == newLeaf)
            {
                RefreshAndMarkParents(oldLeaf);
                return;
            }

            AssertConsistency();
            RemoveInternal(holder);
            AddInternal(holder, newLeaf);
            RefreshAndMarkParents(oldLeaf);
            RefreshAndMarkParents(newLeaf);
            AssertConsistency();
        }
コード例 #10
0
 internal void DisposeHolder(KdTreeHolder <T> holder)
 {
     holder.sibling.prev = null;
     holder.sibling.next = null;
     allocationCacheHolder.Add(holder);
 }
コード例 #11
0
 private static int CompareByY(KdTreeHolder <T> a, KdTreeHolder <T> b)
 {
     return(a.fatRect.max.y.CompareTo(b.fatRect.max.y));
 }