private OctagonalVector AllocateLowerBoundRoot(OctagonalVector v) { OctagonalVector dV = v - _rootVector; OctagonalVector oldRoot = new OctagonalVector( (dV.X < 0) ? ((-dV.X - 1) >> _depth) + 1 : 0, (dV.Y < 0) ? ((-dV.Y - 1) >> _depth) + 1 : 0, (dV.Z < 0) ? ((-dV.Z - 1) >> _depth) + 1 : 0); List <int> oldRootPath = oldRoot.CalculatePath(); int oldRootPathLength = oldRootPath.Count(); if (oldRootPathLength > 0) { for (int i = 0; i < oldRootPathLength; i++) { _root = new Octant(oldRootPath[i], _root); } _rootVector -= oldRoot << _depth; _depth += oldRootPathLength; } return(dV); }
public Octant GetOrAllocate(int child) { if (_childs[child] == null) { _childs[child] = new Octant(0, null); } return(_childs[child]); }
private void Itterate(Octant octant) { if (octant != null) { if (octant.HasChilds) { _path.Insert(0, 0); for (int i = 0; i <= 7; i++) { _path[0] = i; Itterate(octant[i]); } _path.RemoveAt(0); } _action(octant, _path); } }
public OctagonalVector AllocateNode(OctagonalVector v, OctantNode node) { lock (this) { if (_root == null) { _rootVector = v; _depth = 0; _root = node; return(new OctagonalVector(0, 0, 0)); } OctagonalVector dV = AllocateLowerBoundRoot(v); AllocateVector(dV.CalculatePath(), node); return(dV); } }
void AllocateVector(List <int> vPath, OctantNode node) { int vectorPosition = vPath.Count(); //AllocateUpperBoundRoot while (_depth < vPath.Count) { _root = new Octant(0, _root); _depth++; } //Find Octant Octant current = _root; //Skip missing (zero Octant) path coordinates int vectorDimension = _depth - 1; while (vectorDimension > 0 && vectorPosition <= vectorDimension) { current = current.GetOrAllocate(0); vectorDimension--; } //Find the path while (vectorDimension > 0) { current = current.GetOrAllocate(vPath[vectorDimension--]); } if (vectorPosition > 0) { current[vPath[0]] = node; } else { current[0] = node; } }
public Octant(int childPos, Octant child) { _childs = new Octant[8]; _childs[childPos] = child; }