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); }
private void AddAndRefreshInternal(KdTreeHolder <T> holder) { AssertConsistency(); KdTreeNode <T> fittingLeaf = DetermineFittingLeaf(holder); AddInternal(holder, fittingLeaf); RefreshAndMarkParents(fittingLeaf); AssertConsistency(); }
private KdTreeNode <T> DetermineFittingLeaf(KdTreeHolder <T> holder) { var node = root; while (node.type == NodeType.Inner) { node = node.DetermineInnerNode(holder); } return(node); }
private void RemoveInternal(KdTreeHolder <T> holder) { var node = holder.parent; holder.RemoveFromHolderList(); while (node != null) { node.count--; node = node.parent; } }
private void AddInternal(KdTreeHolder <T> holder, KdTreeNode <T> newParent) { holder.AddToHolderList(newParent); var node = newParent; while (node != null) { node.count++; node = node.parent; } }
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; }
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)); }
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); } }
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(); }
internal void DisposeHolder(KdTreeHolder <T> holder) { holder.sibling.prev = null; holder.sibling.next = null; allocationCacheHolder.Add(holder); }
private static int CompareByY(KdTreeHolder <T> a, KdTreeHolder <T> b) { return(a.fatRect.max.y.CompareTo(b.fatRect.max.y)); }