added Quadtree for 2-dimensional claims

This commit is contained in:
BuildTools 2017-01-04 11:37:18 -05:00
parent b3df1993ca
commit affbab5d27

82
src/regions/Quadtree.java Normal file
View file

@ -0,0 +1,82 @@
package regions;
public class Quadtree
{
//STATIC
//==================================================================
public static class Node
{
public final boolean full;
public final Node[] nodes;
public Node(boolean full)
{
this.full = full;
this.nodes = new Node[0];
}
public Node(Node[] nodes)
{
this.full = false;
this.nodes = nodes;
}
}
private static class IntReference
{
int ref;
IntReference(int i)
{
this.ref = i;
}
}
private static Node parseBytes(IntReference index, byte[] bytes, int parentByte)
{
if (parentByte == 0b00000010) return new Node(true);
if (parentByte == 0b00000001) return new Node(false);
byte a = bytes[index.ref++];
return
new Node
(
new Node[]
{
parseBytes(index, bytes, (a >> 6 & 3)),
parseBytes(index, bytes, (a >> 4 & 3)),
parseBytes(index, bytes, (a >> 2 & 3)),
parseBytes(index, bytes, (a & 3))
});
}
public static Node parseBytes(int startAtIndex, byte[] bytes)
{
return parseBytes ( new IntReference(startAtIndex), bytes, 0 );
}
public static Node parseBytes(byte[] bytes)
{
return parseBytes ( new IntReference(0), bytes, 0 );
}
//INSTANCE
//==================================================================
public final Owner owner;
public final Node root;
public Quadtree(Owner owner, byte[] bytes)
{
this.owner = owner;
this.root = parseBytes(bytes);
}
}