more BitRegion math added

This commit is contained in:
BuildTools 2017-01-23 22:18:03 -05:00
parent 68b965590b
commit a21af80204
8 changed files with 389 additions and 444 deletions

View file

@ -2,64 +2,65 @@ package regions;
import java.util.BitSet; import java.util.BitSet;
public class BitRegion implements UtilBitSet public class BitRegion
{ {
/*---------------------------------------------------------------------------- /*
------------------------------------------------------------------------------
CONSTRUCTORS
------------------------------------------------------------------------------
----------------------------------------------------------------------------*/ CONSTRUCTORS
*/
private int[] min; public int[] getMin() { return min; } protected int[] sides; public int[] getSides() { return sides; }
private int[] max; public int[] getMax() { return max; }
private int[] minTrue; public int[] getMinTrue() { return minTrue; }
private int[] maxTrue; public int[] getMaxTrue() { return maxTrue; }
public final boolean is3D; public final boolean is3D;
protected final BitSet blocks;
protected final BitSet blocks;
/** protected BitRegion(int xSideLength, int zSideLength)
*
*
* @param minX
* @param minZ
*/
public BitRegion(int minX, int minZ)
{ {
this.min = new int[] { minX, minZ }; sides = new int[] { xSideLength, zSideLength };
this.is3D = false; is3D = false;
this.blocks = new BitSet(); blocks = new BitSet();
} }
/** protected BitRegion(int xSideLength, int zSideLength, int ySideLength)
*
*
* @param minX
* @param minZ
* @param minY
*/
public BitRegion(int minX, int minZ, int minY)
{ {
this.min = new int[] { minX, minZ, minY }; sides = new int[] { xSideLength, zSideLength, ySideLength };
this.is3D = true; is3D = true;
this.blocks = new BitSet(); blocks = new BitSet();
}
public static BitRegion new2DBitRegion()
{
return new BitRegion(0, 0);
}
public static BitRegion new3DBitRegion()
{
return new BitRegion(0, 0, 0);
} }
/*---------------------------------------------------------------------------- /*
------------------------------------------------------------------------------
GET VALUE
------------------------------------------------------------------------------
----------------------------------------------------------------------------*/ GET VALUE
*/
/** /**
* * Get number of blocks contained in the region
*
* @return
*/ */
public int getVolume() public int getVolume()
{ {
@ -68,52 +69,170 @@ public class BitRegion implements UtilBitSet
/** /**
* * Get number of blocks contained in the region's bounding box
*
* @return
*/ */
public int getBoundsVolume() public int getBoundsVolume()
{ {
if (max == null) return 0; return is3D ?
(sides[0]) * (sides[1]) * (sides[2]) :
(sides[0]) * (sides[1]);
}
/**
* Get coordinates for the block at the given index in the BitSet
*
* @param index
* @return
*/
protected int[] getCoords(int index)
{
if (++index > getBoundsVolume()) return null;
return is3D ? return is3D ?
(max[0] - min[0]) * (max[1] - min[1]) * (max[2] - min[2]) : getCoords3D(index) :
(max[0] - min[0]) * (max[1] - min[1]); getCoords2D(index);
} }
/** /**
* *
* @param coordinate
* @return
*/
public int getIndex(int x, int z)
{
return (x - min[0]) + (z - min[1]);
}
/**
* *
* @param coordinate * @param index
* @return * @return
*/ */
public int getIndex(int x, int z, int y) protected int[] getCoords3D(int index)
{ {
return (x - min[0]) + (z - min[1]) + (y - min[2]); if (index == 0) return new int[] {0, 0, 0};
}
int[] xzy = new int[3];
int crossSec = sides[0] * sides[1];
xzy[2] = index / crossSec - ((index = index % crossSec) == 0 ? 1 : 0); index = (index == 0 ? crossSec : index);
xzy[1] = index / sides[0] - ((index = index % sides[0]) == 0 ? 1 : 0); index = (index == 0 ? sides[0] : index);
xzy[0] = index - 1;
return xzy;
}
/** /**
* *
* @param index * @param index
* @return * @return
*/ */
public int getCoords(int index) protected int[] getCoords2D(int index)
{ {
return is3D ? if (index == 0) return new int[] {0, 0};
:
; int[] xz = new int[2];
xz[1] = index / sides[0] - ((index = index % sides[0]) == 0 ? 1 : 0); index = (index == 0 ? sides[0] : index);
xz[0] = index - 1;
return xz;
}
/*-------------------------------------
OVERLOADS : getIndex()
-------------------------------------*/
/**
*
* @param coordinate
* @return
*/
public int getIndex(int x, int z)//TODO return -1 if outside bounds
{
return (z * sides[0]) + x;
}
/**
*
* @param coordinate
* @return
*/
public int getIndex(int x, int z, int y)//TODO return -1 if outside bounds
{
return (y * sides[0] * sides[1]) + (z * sides[0]) + x;
}
/*-------------------------------------
OVERLOADS : blockAt()
-------------------------------------*/
/**
*
* @param x
* @param z
* @return
*/
public boolean blockAt(int x, int z)//TODO return false if outside bounds
{
return blocks.get(getIndex(x,z));
}
/**
*
* @param x
* @param z
* @param y
* @return
*/
public boolean blockAt(int x, int z, int y)//TODO return false if outside bounds
{
return blocks.get(getIndex(x, z, y));
}
/**
*
* @param index
* @return
*/
public boolean blockAt(int index)
{
return blocks.get(index);
}
/*----------------------------------------------------------------------------
------------------------------------------------------------------------------
OVERLOADS : shift()
------------------------------------------------------------------------------
----------------------------------------------------------------------------*/
/**
*
* @param shift
* @param fromIndex
*/
public void bitshift(int shift, int fromIndex)
{
if (shift < 1) return;
int toAboveThisIndex = fromIndex + shift - 1;
for (int i = blocks.size() + shift; i > toAboveThisIndex; i++)
{
blocks.set(i - shift, blocks.get(i));
}
blocks.clear(fromIndex, toAboveThisIndex);
}
public void shift(int xShift, int zShift)
{
}
public void shift(int xShift, int zShift, int yShift)
{
} }
@ -124,6 +243,7 @@ public class BitRegion implements UtilBitSet
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
----------------------------------------------------------------------------*/ ----------------------------------------------------------------------------*/
/** /**
* *
*/ */
@ -132,6 +252,30 @@ public class BitRegion implements UtilBitSet
blocks.set(0, getBoundsVolume() - 1); blocks.set(0, getBoundsVolume() - 1);
} }
/**
*
* @param x
* @param z
*/
public void fill(int x, int z)
{
blocks.set(getIndex(x, z));
}
/**
*
* @param x
* @param z
* @param y
*/
public void fill(int x, int z, int y)
{
blocks.set(getIndex(x, z, y));
}
/** /**
* *
* *
@ -157,6 +301,7 @@ public class BitRegion implements UtilBitSet
} }
} }
/** /**
* *
* *
@ -186,6 +331,7 @@ public class BitRegion implements UtilBitSet
} }
} }
/** /**
* *
* *
@ -213,6 +359,7 @@ public class BitRegion implements UtilBitSet
} }
} }
/** /**
* *
* *
@ -247,11 +394,14 @@ public class BitRegion implements UtilBitSet
} }
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
OVERLOADS : clear() OVERLOADS : clear()
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
----------------------------------------------------------------------------*/ ----------------------------------------------------------------------------*/
/** /**
* *
*/ */
@ -260,6 +410,30 @@ public class BitRegion implements UtilBitSet
blocks.clear(); blocks.clear();
} }
/**
*
* @param x
* @param z
*/
public void clear(int x, int z)
{
blocks.clear(getIndex(x, z));
}
/**
*
* @param x
* @param z
* @param y
*/
public void clear(int x, int z, int y)
{
blocks.clear(getIndex(x, z, y));
}
/** /**
* *
* *
@ -285,6 +459,7 @@ public class BitRegion implements UtilBitSet
} }
} }
/** /**
* *
* *
@ -314,6 +489,7 @@ public class BitRegion implements UtilBitSet
} }
} }
/** /**
* *
* *
@ -341,6 +517,7 @@ public class BitRegion implements UtilBitSet
} }
} }
/** /**
* *
* *

View file

@ -0,0 +1,7 @@
package regions;
public class CoordRegion
{
// 2896 is the maximum side length for a 3D, square, resolution 1 region with height 256
// 128 is the coarsest resolution for a 3D region
}

View file

@ -7,15 +7,6 @@ import java.io.OutputStream;
public class Octree extends Tree public class Octree extends Tree
{ {
/*
BYTE CONVERSION
*/
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
FROM BYTES FROM BYTES
@ -32,6 +23,7 @@ public class Octree extends Tree
b = input.read(); b = input.read();
return a == -1 || b == -1 ? return a == -1 || b == -1 ?
new Node( false ) : new Node( false ) :
new Node( new Node[] { parseBytes(input, (a >>> 6 & 3)), new Node( new Node[] { parseBytes(input, (a >>> 6 & 3)),
parseBytes(input, (a >>> 4 & 3)), parseBytes(input, (a >>> 4 & 3)),
@ -52,66 +44,54 @@ public class Octree extends Tree
----------------------------------------------------------------------------*/ ----------------------------------------------------------------------------*/
@Override @Override
public void writeBytes(Node node, OutputStream output) public void writeBytes(Node node, OutputStream output) throws IOException
{ {
try output.write( getByte( node.children[0],
{ node.children[1],
output.write( getByte( node.children[0], node.children[2],
node.children[1], node.children[3]
node.children[2], ));
node.children[3]
));
output.write( getByte( node.children[4], output.write( getByte( node.children[4],
node.children[5], node.children[5],
node.children[6], node.children[6],
node.children[7] node.children[7]
)); ));
}
catch (IOException e) { e.printStackTrace(); }
for (Node child : node.children) for (Node child : node.children)
if (child.children.length > 0) if (child.children.length > 0)
writeBytes(child, output); writeBytes(child, output);
} }
/* /*----------------------------------------------------------------------------
------------------------------------------------------------------------------
CONSTRUCTORS
------------------------------------------------------------------------------
CONSTRUCTORS ----------------------------------------------------------------------------*/
*/
public Octree(int[][] bounds, File file, byte[] bytes) public Octree(File file) throws IOException
{ {
super(bounds, file); super(file);
}
/*-------------------------------------
Methods used by constructors.
-------------------------------------*/
@Override
protected final TreeEditor<Octree> newEditor()
{
return new TreeEditor<Octree>(this, min[0], min[1], min[2]);
} }
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
Methods used by constructors CALCULATIONS
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
----------------------------------------------------------------------------*/ ----------------------------------------------------------------------------*/
@Override
protected final OctreeEditor newEditor()
{
return new OctreeEditor(this);
}
/*
CALCULATIONS
*/
@Override @Override
public Node[] getNodes(Node parentNode, int[][] regionBounds) public Node[] getNodes(Node parentNode, int[][] regionBounds)
{ {

View file

@ -7,15 +7,6 @@ import java.io.OutputStream;
public class Quadtree extends Tree public class Quadtree extends Tree
{ {
/*
BYTE CONVERSION
*/
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
FROM BYTES FROM BYTES
@ -31,6 +22,7 @@ public class Quadtree extends Tree
int a = input.read(); //returns -1 if there are no more bytes int a = input.read(); //returns -1 if there are no more bytes
return a == -1 ? return a == -1 ?
new Node( false ) : new Node( false ) :
new Node( new Node[] { parseBytes(input, (a >>> 6 & 3)), new Node( new Node[] { parseBytes(input, (a >>> 6 & 3)),
parseBytes(input, (a >>> 4 & 3)), parseBytes(input, (a >>> 4 & 3)),
@ -46,17 +38,13 @@ public class Quadtree extends Tree
----------------------------------------------------------------------------*/ ----------------------------------------------------------------------------*/
@Override @Override
public void writeBytes(Node node, OutputStream output) public void writeBytes(Node node, OutputStream output) throws IOException
{ {
try output.write( getByte( node.children[0],
{ node.children[1],
output.write( getByte( node.children[0], node.children[2],
node.children[1], node.children[3]
node.children[2], ));
node.children[3]
));
}
catch (IOException e) { e.printStackTrace(); }
for (Node child : node.children) for (Node child : node.children)
if (child.children.length > 0) if (child.children.length > 0)
@ -64,42 +52,34 @@ public class Quadtree extends Tree
} }
/* /*----------------------------------------------------------------------------
------------------------------------------------------------------------------
CONSTRUCTORS
------------------------------------------------------------------------------
CONSTRUCTORS ----------------------------------------------------------------------------*/
*/
public Quadtree(File file) public Quadtree(File file) throws IOException
{ {
super(file); super(file);
} }
/*---------------------------------------------------------------------------- /*-------------------------------------
------------------------------------------------------------------------------ Methods used by constructors.
Methods used by constructors -------------------------------------*/
------------------------------------------------------------------------------
----------------------------------------------------------------------------*/
@Override @Override
final QuadtreeEditor newEditor() protected final TreeEditor<Quadtree> newEditor()
{ {
return new QuadtreeEditor(this); return new TreeEditor<Quadtree>(this, min[0], min[1]);
} }
/* /*----------------------------------------------------------------------------
------------------------------------------------------------------------------
CALCULATIONS
------------------------------------------------------------------------------
CALCULATIONS ----------------------------------------------------------------------------*/
*/
@Override @Override
public Node[] getNodes(Node parentNode, int[][] regionBounds) public Node[] getNodes(Node parentNode, int[][] regionBounds)

View file

@ -1,7 +1,6 @@
package regions; package regions;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -58,13 +57,13 @@ public abstract class Tree
/* /*
BYTE CONVERSION BYTE CONVERSION
*/ */
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
@ -97,11 +96,11 @@ public abstract class Tree
* *
* @param input DataInputStream of source bytes * @param input DataInputStream of source bytes
* @return a new Node * @return a new Node
* @throws IOException
*/ */
public Node parseBytes(DataInputStream input) public Node parseBytes(DataInputStream input) throws IOException
{ {
try { return parseBytes(input, 0); } return parseBytes(input, 0);
catch (IOException e) { return new Node(false); }
} }
@ -112,28 +111,16 @@ public abstract class Tree
* *
* @param file binary file to read bytes from * @param file binary file to read bytes from
* @return a new Node * @return a new Node
* @throws IOException
*/ */
public Node parseBytes(File file) public Node parseBytes(File file) throws IOException
{ {
if (file.length() == 0) { return new Node(false); } if (file.length() == 0) return new Node(false);
else { return parseBytes(file, 1); }
}
DataInputStream input = new DataInputStream( new BufferedInputStream( new FileInputStream(file) ));
private Node parseBytes(File file, int attempt) Node node = parseBytes(input);
{ input.close();
try return node;
{
DataInputStream input = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
Node node = parseBytes(input);
input.close();
return node;
}
catch (IOException e)
{
e.printStackTrace();
return attempt < 4 ? parseBytes(file, ++attempt) : new Node(false);
}
} }
@ -183,79 +170,17 @@ public abstract class Tree
/** /**
* Parses the tree rooted at this node, appending in depth-first order the result of invoking * Parses the tree below this node, appending in depth-first order the result of invoking
* <tt>{@link #getByte(Node, Node, Node, Node) getByte(children)}</tt> for each encountered * <tt>{@link #getByte(Node, Node, Node, Node) getByte(children)}</tt> for each encountered
* node in the tree, skipping childless nodes.<p> * node in the tree, skipping childless nodes.<p>
* *
* NOTE: assumes an OutputStream that appends with each write. * Assumes an OutputStream that appends with each write.
* *
* @param node the node to be parsed * @param node the node to be parsed
* @return a byte array representing the node and all its child nodes * @return a byte array representing the node and all its child nodes
* @throws IOException
*/ */
public abstract void writeBytes(Node node, OutputStream output); public abstract void writeBytes(Node node, OutputStream output) throws IOException;
/*-------------------------------------
OVERLOADS : getBytes()
-------------------------------------*/
/**
* Parses the tree from the root, appending in depth-first order the result of invoking
* <tt>{@link #getByte(Node, Node, Node, Node) getByte(children)}</tt> for each encountered
* node in the tree, skipping childless nodes.<p>
*
* @return byte array representing the root node and all its child nodes
*/
public byte[] getBytes()
{
ByteArrayOutputStream output = new ByteArrayOutputStream();
writeBytes(root, output);
return output.toByteArray();
}
/**
* Parses the tree below this node, appending in depth-first order the result of invoking
* <tt>{@link #getByte(Node, Node, Node, Node) getByte(children)}</tt> for each encountered
* node in the tree, skipping childless nodes.<p>
*
* @param node the node to parse from
* @return byte array representing the given node and all its child nodes
*/
public byte[] getBytes(Node node)
{
ByteArrayOutputStream output = new ByteArrayOutputStream();
writeBytes(node, output);
return output.toByteArray();
}
/**
* Parses the tree from the root, appending in depth-first order the result of invoking
* <tt>{@link #getByte(Node, Node, Node, Node) getByte(children)}</tt> for each encountered
* node in the tree, skipping childless nodes.<p>
*
* Writes to the given OutputStream, does not close the stream.
*
* @param output the ByteArrayOutputStream to write to
*/
public void getBytes(OutputStream output)
{
writeBytes(root, output);
}
/**
* Parses the tree below this node, appending in depth-first order the result of invoking
* <tt>{@link #getByte(Node, Node, Node, Node) getByte(children)}</tt> for each encountered
* node in the tree, skipping childless nodes.<p>
*
* Writes to the given OutputStream, does not close the stream.
*
* @param node the node to parse from
* @param output the ByteArrayOutputStream to write to
*/
public void getBytes(Node node, OutputStream output)
{
writeBytes(node, output);
}
@ -263,105 +188,93 @@ public abstract class Tree
OVERLOADS : saveToFile() OVERLOADS : saveToFile()
-------------------------------------*/ -------------------------------------*/
/** /**
* Performs <tt>{@link #writeBytes(Node, OutputStream)}</tt> from the root node, using a * Performs <tt>{@link #writeBytes(Node, OutputStream)}</tt> from the root node,
* FileOutputStream of the source file as the OutputStream argument. * using a FileOutputStream of the source file as the OutputStream argument.
* *
* @param node the root node of the tree to be parsed * @param node the root node of the tree to be parsed
* @param destination the file to save to * @param destination the file to save to
* @throws IOException
*/ */
public void saveToFile()//TODO erase existing file contents before writing public void saveToFile() throws IOException
{ {
try FileOutputStream output = new FileOutputStream (new File(file.getAbsolutePath()), true);
{ writeBytes(root, output);
FileOutputStream output = new FileOutputStream (file, true); output.close();
writeBytes(root, output);
output.close();
}
catch (IOException e) { e.printStackTrace(); }
} }
/** /**
* Performs <tt>{@link #writeBytes(Node, OutputStream)}</tt> from the given node, using a * Performs <tt>{@link #writeBytes(Node, OutputStream)}</tt> from the given node,
* FileOutputStream of the source file as the OutputStream argument. * using a FileOutputStream of the source file as the OutputStream argument.
* *
* @param node the root node of the tree to be parsed * @param node the root node of the tree to be parsed
* @param destination the file to save to * @param destination the file to save to
* @throws IOException
*/ */
public void saveToFile(Node node)//TODO erase existing file contents before writing public void saveToFile(Node node) throws IOException
{ {
try FileOutputStream output = new FileOutputStream (new File(file.getAbsolutePath()), true);
{ writeBytes(node, output);
FileOutputStream output = new FileOutputStream (file, true); output.close();
writeBytes(node, output);
output.close();
}
catch (IOException e) { e.printStackTrace(); }
} }
/** /**
* Performs <tt>{@link #writeBytes(Node, OutputStream)}</tt> from the root node, using a * Performs <tt>{@link #writeBytes(Node, OutputStream)}</tt> from the root node,
* FileOutputStream of the given file as the OutputStream argument. * using a FileOutputStream of the given file as the OutputStream argument.
* *
* @param node the root node of the tree to be parsed * @param node the root node of the tree to be parsed
* @param destination the file to save to * @param destination the file to save to
* @throws IOException
*/ */
public void saveToFile(File destination)//TODO erase existing file contents before writing public void saveToFile(File destination) throws IOException
{ {
try FileOutputStream output = new FileOutputStream (new File(destination.getAbsolutePath()), true);
{ writeBytes(root, output);
FileOutputStream output = new FileOutputStream (destination, true); output.close();
writeBytes(root, output);
output.close();
}
catch (IOException e) { e.printStackTrace(); }
} }
/** /**
* Performs <tt>{@link #writeBytes(Node, OutputStream)}</tt> from the given node, using a * Performs <tt>{@link #writeBytes(Node, OutputStream)}</tt> from the given node,
* FileOutputStream of the given file as the OutputStream argument. * using a FileOutputStream of the given file as the OutputStream argument.
* *
* @param node the root node of the tree to be parsed * @param node the root node of the tree to be parsed
* @param destination the file to save to * @param destination the file to save to
* @throws IOException
*/ */
public void saveToFile(Node node, File destination)//TODO erase existing file contents before writing public void saveToFile(Node node, File destination) throws IOException
{ {
try FileOutputStream output = new FileOutputStream (new File(destination.getAbsolutePath()), true);
{ writeBytes(node, output);
FileOutputStream output = new FileOutputStream (destination, true); output.close();
writeBytes(node, output);
output.close();
}
catch (IOException e) { e.printStackTrace(); }
} }
/* /*
CONSTRUCTORS CONSTRUCTORS
*/ */
private int[] min; public int[] getMin() { return min; } protected int[] min; public int[] getMin() { return min; }
private int[] max; public int[] getMax() { return max; } protected int[] max; public int[] getMax() { return max; }
private int[] minTrue; public int[] getMinTrue() { return minTrue; } protected int[] minTrue; public int[] getMinTrue() { return minTrue; }
private int[] maxTrue; public int[] getMaxTrue() { return maxTrue; } protected int[] maxTrue; public int[] getMaxTrue() { return maxTrue; }
public final File file; public final File file;
public final Node root; public final Node root;
public final TreeEditor<?> editor; public final TreeEditor<? extends Tree> editor;
/** /**
* Create a Tree from the given binary file. Invokes <tt>parseBytes()</tt> * Create a Tree from the given binary file. Invokes {@link #parseBytes(File)}
* *
* @param file The source file, and save destination, for this Tree. * @param file The source file, and save destination, for this Tree.
* @see {@link #parseBytes(File)} * @throws IOException
*/ */
public Tree(File file) public Tree(File file) throws IOException
{ {
setBoundsFromFilename(file); setBoundsFromFilename(file);
@ -397,21 +310,27 @@ public abstract class Tree
* *
* @return a new TreeEditor * @return a new TreeEditor
*/ */
protected abstract TreeEditor<? extends TreeEditor.Edit> newEditor(); abstract TreeEditor<? extends Tree> newEditor();
/* /*
CALCULATIONS CALCULATIONS
*/ */
/**
*
* @param parentNode
* @param regionBounds
* @return
*/
public abstract Node[] getNodes(Node parentNode, int[][] regionBounds);
/** /**
@ -423,13 +342,4 @@ public abstract class Tree
{ {
return getNodes(root, regionBounds); return getNodes(root, regionBounds);
} }
/**
*
* @param parentNode
* @param regionBounds
* @return
*/
public abstract Node[] getNodes(Node parentNode, int[][] regionBounds);
} }

View file

@ -1,16 +1,14 @@
package regions; package regions;
import java.util.BitSet; public class TreeBuilder<T extends Tree>
public class TreeBuilder<T extends Tree> extends BitRegion
{ {
public TreeBuilder(int minX, int minZ) public TreeBuilder(int minX, int minZ)
{ {
super(minX, minZ);
} }
public TreeBuilder(int minX, int minZ, int minY) public TreeBuilder(int minX, int minZ, int minY)
{ {
super(minX, minZ, minY);
} }
} }

View file

@ -1,74 +1,18 @@
package regions; package regions;
/** /**
* * Aggregator for all edits waiting to be added. Merges all incoming edits
* * into a growing 'super-edit' that is periodically written to the tree and flushed.
* @author Kevin Mathewson
*
*/ */
public abstract class TreeEditor<T extends TreeEditor.Edit> public class TreeEditor<T extends Tree>
{ {
/** public TreeEditor(Octree tree, int minX, int minZ, int minY)
* Abstract class describing an edit to a Tree object. In general, defines a selection
* of blocks, specifying <tt>true</tt>, <tt>false</tt>, or <tt>no change</tt> for each.
* Dimensions are square or cubic, for quadtrees and octrees respectively.
*/
static abstract class Edit
{ {
/**
* Minimum and maximum bounds [ [min] [max] ].
* Quadtree edits have bounds [x,z], Octree edits have bounds [x,z,y].
*/
private final int[][] bounds;
private int[][] boundsTrue;
private boolean containsTrue = false;
Edit(int[][] bounds)
{
this.bounds = bounds;
this.boundsTrue = this.bounds;
}
} }
/** public TreeEditor(Quadtree tree, int minX, int minZ)
* Aggregator for all edits waiting to be added. Merges all incoming edits
* into a growing 'super-edit' that is periodically written to the tree and flushed.
*/
static class EditQueue<T extends Edit>
{ {
private final TreeEditor editor;
private volatile Edit superEdit;
EditQueue(TreeEditor editor, Edit superEdit)
{
this.editor = editor;
this.superEdit = superEdit;
}
public synchronized T merge(T edit1, T edit2)
{
return null;
}
} }
/*----------------------------------------------------------------------------
------------------------------------------------------------------------------
CONSTRUCTOR
------------------------------------------------------------------------------
----------------------------------------------------------------------------*/
private final EditQueue changeQueue;
public TreeEditor(EditQueue changeQueue)
{
this.changeQueue = changeQueue;
}
/*----------------------------------------------------------------------------
------------------------------------------------------------------------------
METHODS
------------------------------------------------------------------------------
----------------------------------------------------------------------------*/
abstract void addEdit(Edit edit);
} }

View file

@ -1,51 +0,0 @@
package regions;
import java.util.BitSet;
public interface UtilBitSet
{
/*-------------------------------------
OVERLOADS : shift()
-------------------------------------*/
/**
*
* @param bitset
* @param shift
* @return
*/
default BitSet shift(BitSet bitset, int shift)
{
if (shift == 0) return bitset;
if (shift > 0)
{
for (int i = bitset.length() - 1; i > -1; i--)
{
bitset.set(i + shift, bitset.get(i));
}
return bitset;
}
else
{
int length = bitset.length();
for (int i = -shift; i < length; i++)
{
bitset.set(i + shift, bitset.get(i));
}
bitset.clear(length + shift, length);
return bitset;
}
}
/**
*
* @param bitset
* @param shift
* @param fromIndex
* @param toIndex
* @return
*/
default BitSet shift(BitSet bitset, int shift, int fromIndex, int toIndex)
{
}
}