/// <summary> /// Create an octree /// </summary> /// <param name="size"></param> public Octree(DepthsByDiameter maxDepth, TType defaultValue) { depth = maxDepth; root = new OctreeNode <TType>( new Coordinate(0, 0, 0), (int)Math.Pow(2, (int)depth), defaultValue ); }
/// <summary> /// Get a tree from the given node depth /// </summary> /// <param name="position">The position of the node to get</param> /// <param name="diameter">The diameter/depth of the child tree we are grabbing (how large it is, now how deep it is in the parent)</param> /// <returns></returns> public Octree <TType> getTreeAt(Coordinate position, DepthsByDiameter diameter) { int expectedSize = GetSizeOfNodeFromDepth(diameter); OctreeNode <TType> childTreeRootNode = root.getNodeAt( position, expectedSize ); // trim the grabbed node to the selected size and push it into a tree as the root. childTreeRootNode.makeNodeRoot(expectedSize); return(new Octree <TType>(childTreeRootNode)); }
/// <summary> /// Get the diameter of a node with the given depth. /// </summary> /// <param name="depth"></param> /// <returns>The size of node with the given max depth</returns> public static int GetSizeOfNodeFromDepth(DepthsByDiameter depth) { return((int)Math.Pow(2, (int)depth)); }
/// <summary> /// Get the diameter of a node at the given depth of this tree using maths /// </summary> /// <param name="depth"></param> /// <returns></returns> int getNodeSizeAtDepth(DepthsByDiameter depth) { return((int)(root.size * (1 / Math.Pow(2, (int)depth)))); }