Пример #1
0
 private void TraverseOverlapping(KdTreeNode <T> node, AaRect rect, Action <T> action)
 {
     if (node.type == NodeType.Leaf)
     {
         var holder = node.leaf.holder;
         while (holder != null)
         {
             if (AaRect.Overlaps(rect, holder.fitRect))
             {
                 action(holder.body);
             }
             holder = holder.sibling.next;
         }
     }
     else
     {
         var pos = node.DetermineInnerNodePosition(rect);
         if (pos != ChildPosition.More)
         {
             TraverseOverlapping(node.inner.nodeLess, rect, action);
         }
         if (pos != ChildPosition.Less)
         {
             TraverseOverlapping(node.inner.nodeMore, rect, action);
         }
         TraverseOverlapping(node.inner.nodeBoth, rect, action);
     }
 }
Пример #2
0
 private void DrawRect(Pen pen, AaRect rect)
 {
     _graphics.DrawRectangle(
         pen,
         rect.min.x,
         rect.min.y,
         rect.max.x - rect.min.x,
         rect.max.y - rect.min.y
         );
 }
Пример #3
0
 public bool Update(KdTree <T> tree)
 {
     fitRect = tree.GetBodyFitRect(body);
     if (fatRect.Contains(fitRect) && refresh > 0)
     {
         refresh--;
         // body still in fat rect, skipping
         return(false);
     }
     fatRect = tree.GetBodyFatRect(body);
     refresh = tree.newRefresh;
     return(true);
 }
Пример #4
0
        public ChildPosition DetermineInnerNodePosition(AaRect rect)
        {
            float pivot     = inner.pivot;
            float holderMin = ByAxis(rect.min);
            float holderMax = ByAxis(rect.max);

            if (holderMax < pivot)
            {
                return(ChildPosition.Less);
            }
            if (holderMin > pivot)
            {
                return(ChildPosition.More);
            }
            return(ChildPosition.Both);
        }
Пример #5
0
        private void DrawKdRectSplits <T>(KdTreeNode <T> node, AaRect bounds)
        {
            Graphics g = _graphics;

            if (node.type == NodeType.Inner)
            {
                Pen pen = Pens.DarkGray;
                if (node.inner.axis == Axis.X)
                {
                    g.DrawLine(pen, node.inner.pivot, bounds.min.y, node.inner.pivot, bounds.max.y);
                    DrawKdRectSplits(
                        node.inner.nodeLess,
                        AaRect.mm(bounds.min, node.inner.pivot, bounds.max.y)
                        );
                    DrawKdRectSplits(
                        node.inner.nodeMore,
                        AaRect.mm(node.inner.pivot, bounds.min.y, bounds.max)
                        );
                }
                if (node.inner.axis == Axis.Y)
                {
                    g.DrawLine(pen, bounds.min.x, node.inner.pivot, bounds.max.x, node.inner.pivot);
                    DrawKdRectSplits(
                        node.inner.nodeLess,
                        AaRect.mm(bounds.min, bounds.max.x, node.inner.pivot)
                        );
                    DrawKdRectSplits(
                        node.inner.nodeMore,
                        AaRect.mm(bounds.min.x, node.inner.pivot, bounds.max)
                        );
                }
                DrawKdRect(node.inner.nodeBoth);
            }
            if (node.type == NodeType.Leaf)
            {
                var holder = node.leaf.holder;
                while (holder != null)
                {
                    //DrawRect(Pens.DarkRed, holder.fatRect.ExtendSides(V.fill(5)));
                    holder = holder.sibling.next;
                }
            }
        }