added javadocs for Tree superclass
This commit is contained in:
parent
e307755656
commit
22698adb36
2 changed files with 78 additions and 6 deletions
|
@ -1,11 +1,40 @@
|
||||||
package regions;
|
package regions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a superclass for octrees, quadtrees, and any other spatial trees.<p>
|
||||||
|
*
|
||||||
|
* concept credit to Don Meagher, who first named and described Octrees in his 1980 paper,
|
||||||
|
* "Octree Encoding: A New Technique for the Representation, Manipulation and Display of
|
||||||
|
* Arbitrary 3-D Objects by Computer."<p>
|
||||||
|
*
|
||||||
|
* The idea works like this:<p>
|
||||||
|
*
|
||||||
|
* For some arbitrary shape, you first define the bounding box of the shape (or the
|
||||||
|
* smallest box your shape will fit inside of). This box outlines the minimum and maximum
|
||||||
|
* x, y, and z dimensions of the shape.<p>
|
||||||
|
*
|
||||||
|
* Next, you divide this cube evenly into 8 sections (2 x 2 x 2) and determine which sections
|
||||||
|
* your shape fills, which ones it leaves empty, and which ones your shape partially
|
||||||
|
* intersects.<p>
|
||||||
|
*
|
||||||
|
* Intersected cubes are divided again into 8 subsections, and the process repeats until you
|
||||||
|
* have divided and subdivided your bounding box into <i>only</i> full (<tt>true</tt>) and
|
||||||
|
* empty (<tt>false</tt>) cubes<p>
|
||||||
|
*
|
||||||
|
* Then, given any point in space, you can quickly determine whether the point is inside or
|
||||||
|
* outside your shape by navigating the tree to reach the smallest cube your point is in.
|
||||||
|
*
|
||||||
|
* @author Kevin Mathewson
|
||||||
|
*
|
||||||
|
*/
|
||||||
public abstract class Tree
|
public abstract class Tree
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Tree node containing a boolean and an array of sub-nodes
|
||||||
|
*/
|
||||||
public static class Node
|
public static class Node
|
||||||
{
|
{
|
||||||
public boolean full;
|
public boolean full;
|
||||||
public Node parent;
|
|
||||||
public Node[] children;
|
public Node[] children;
|
||||||
|
|
||||||
public Node(boolean full)
|
public Node(boolean full)
|
||||||
|
@ -23,8 +52,12 @@ public abstract class Tree
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
static class IntReference
|
* Defines an object containing a single int field. Used by the <tt>parseBytes()</tt>
|
||||||
|
* method to track its current <tt>index</tt> in the byte array. <tt>Node parseBytes()</tt>
|
||||||
|
* is a nested, self-calling method, and <tt>index</tt> increments with each call.
|
||||||
|
*/
|
||||||
|
static final class IntReference
|
||||||
{
|
{
|
||||||
int ref;
|
int ref;
|
||||||
|
|
||||||
|
@ -35,18 +68,51 @@ public abstract class Tree
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An abstract method, implemented slightly differently by octrees and quadtrees because
|
||||||
|
* octrees have 8 branches per node and quadtrees only 4.<p>
|
||||||
|
*
|
||||||
|
* Given a byte array, interprets each byte as four 2-bit values, where 00 = partially full,
|
||||||
|
* 01 = empty (<tt>false</tt>) and 10 = full (<tt>true</tt>). Octree nodes use 2 bytes
|
||||||
|
* each, Quadtree nodes use 1 byte each. Assumes a depth-first arrangement.<p>
|
||||||
|
*
|
||||||
|
* @param index current position in the byte array
|
||||||
|
* @param bytes byte array, presumably read from a binary file
|
||||||
|
* @param parentByte the 2-bit value (00000010, 00000001 or 00000000)
|
||||||
|
* @return a new Node
|
||||||
|
*/
|
||||||
abstract Node parseBytes(IntReference index, byte[] bytes, int parentByte);
|
abstract Node parseBytes(IntReference index, byte[] bytes, int parentByte);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simplified public alias for the package-private abstract method
|
||||||
|
* <tt>Node parseBytes(IntReference index, byte[] bytes, int parentByte)</tt><p>
|
||||||
|
*
|
||||||
|
* Given a byte array, interprets each byte as four 2-bit values, where 00 = partially full,
|
||||||
|
* 01 = empty (<tt>false</tt>) and 10 = full (<tt>true</tt>). Octree nodes use 2 bytes
|
||||||
|
* each, Quadtree nodes use 1 byte each. Assumes a depth-first arrangement.<p>
|
||||||
|
*
|
||||||
|
* @param startAtIndex where in the byte[] array to begin
|
||||||
|
* @param bytes byte array, presumably read from a binary file
|
||||||
|
* @return a new Node
|
||||||
|
*/
|
||||||
public Node parseBytes(int startAtIndex, byte[] bytes)
|
public Node parseBytes(int startAtIndex, byte[] bytes)
|
||||||
{
|
{
|
||||||
return parseBytes ( new IntReference(startAtIndex), bytes, 0 );
|
return parseBytes ( new IntReference(startAtIndex), bytes, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simplified public alias for the package-private abstract method
|
||||||
|
* <tt>Node parseBytes(IntReference index, byte[] bytes, int parentByte)</tt><p>
|
||||||
|
*
|
||||||
|
* Given a byte array, interprets each byte as four 2-bit values, where 00 = partially full,
|
||||||
|
* 01 = empty (<tt>false</tt>) and 10 = full (<tt>true</tt>). Octree nodes use 2 bytes
|
||||||
|
* each, Quadtree nodes use 1 byte each. Assumes a depth-first arrangement.<p>
|
||||||
|
*
|
||||||
|
* @param bytes byte array, presumably read from a binary file
|
||||||
|
* @return a new Node
|
||||||
|
*/
|
||||||
public Node parseBytes(byte[] bytes)
|
public Node parseBytes(byte[] bytes)
|
||||||
{
|
{
|
||||||
return parseBytes ( new IntReference(0), bytes, 0 );
|
return parseBytes ( new IntReference(0), bytes, 0 );
|
||||||
|
|
6
src/regions/World.java
Normal file
6
src/regions/World.java
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
package regions;
|
||||||
|
|
||||||
|
public class World
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue