/// <summary> /// Get the uncle octant to the given direction of the current octant /// (uncle being an octant bordeing the parent sharing a parent.) /// </summary> /// <param name="direction"></param> /// <param name="uncleValue">Get the value of the uncle, can be used in case no node is returned.</param> /// <returns></returns> OctreeNode <TType> getUncleToThe(Directions.Direction direction, out TType uncleValue) { // we want to make sure we aren't too far up for uncles if (!isRoot && !parent.isRoot) { Octants.Octant currentParentOctant = parent.parent.getChildOctantFor(parent.position); Octants.Octant uncleOctant = currentParentOctant.toThe(direction); // if we have an uncle at this level, return the node and or value from the grandparent if (uncleOctant != null) { OctreeNode <TType> uncleNode = parent.parent.getChild((Octants.Octant)uncleOctant); uncleValue = uncleNode == null ? parent.parent.value : uncleNode.value; return(uncleNode); // if we don't, we want to see if this node's parent has the uncle we need. } else { return(parent.getUncleToThe(direction, out uncleValue)); } } // there's no uncles, only brothers and parents. uncleValue = default; return(null); }
/// <summary> /// Check if the neigboring node(s) in the given direction is(are) solid against this node. /// </summary> /// <param name="direction"></param> /// <returns></returns> TType[] getValuesToThe(Directions.Direction direction) { if (isRoot) { return(new TType[1]); } TType defaultValue; Octants.Octant currentOctant = parent.getChildOctantFor(position); Octants.Octant brotherOctant = currentOctant.toThe(direction); // if the octant shares a parent, move downwards into the found brother OctreeNode <TType> neighborNode; if (brotherOctant != null) { neighborNode = parent.getChild(brotherOctant); defaultValue = parent.value; // else we have to get the cousin } else { neighborNode = getCousinToThe(direction, out defaultValue); } // if we found a node at all, collect the values of that node. if (neighborNode != null) { return(collectBorderValues(neighborNode, direction.Reverse)); // if there is no neighboring node, return the value we generated for the position instead } else { return(new TType[1] { defaultValue }); } }