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); } }
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 ); }
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); }
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); }
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; } } }