Skip to content

Commit

Permalink
Added abstract classes for quad tree
Browse files Browse the repository at this point in the history
  • Loading branch information
Jotschi committed May 8, 2011
1 parent ec0475b commit a01492b
Show file tree
Hide file tree
Showing 17 changed files with 565 additions and 393 deletions.
83 changes: 83 additions & 0 deletions src/main/java/at/jotschi/quadtree/AbstractNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package at.jotschi.quadtree;

import java.awt.Dimension;
import java.awt.Point;

public abstract class AbstractNode {

/**
* Default value for amount of elements
*/
protected final int MAX_ELEMENTS = 4;

/**
* Default value for max depth
*/
protected final int MAX_DEPTH = 4;

public static enum Cell {
TOP_LEFT, BOTTOM_RIGHT, BOTTOM_LEFT, TOP_RIGHT
}

protected Dimension bounds;
protected Point startCoordinates;
protected int maxDepth;
protected int maxElements;
protected int depth;

public AbstractNode(Point startCoordinates, Dimension bounds, int depth) {
this.startCoordinates = startCoordinates;
this.bounds = bounds;
this.depth = depth;
this.maxDepth = MAX_DEPTH;
this.maxElements = MAX_ELEMENTS;
}

public AbstractNode(Point startCoordinates, Dimension bounds, int depth,
int maxDepth, int maxChildren) {
this.startCoordinates = startCoordinates;
this.bounds = bounds;
this.maxDepth = maxDepth;
this.maxElements = maxChildren;
this.depth = depth;
}

/**
* Returns the bounds for this Node
*
* @return
*/
public Dimension getBounds() {
return this.bounds;
}

/**
* Returns the startCoordinates for this Node
*
* @return
*/
public Point getStartCoordinates() {
return this.startCoordinates;
}

/**
* Returns the max elements
*
* @return
*/
public int getMaxElements() {
return this.maxElements;
}

/**
* Returns the max depth
*
* @return
*/
public int getMaxDepth() {
return this.maxDepth;
}

public abstract void subdivide();

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
*/
@SuppressWarnings("serial")
public class NodeElement<T> extends Point {
public abstract class AbstractNodeElement<T> extends Point {

private T element;

Expand All @@ -20,10 +20,13 @@ public class NodeElement<T> extends Point {
* @param y
* @param element
*/
public NodeElement(Point coordinates, T element) {
public AbstractNodeElement(Point coordinates, T element) {
super(coordinates);
this.element = element;
}

public AbstractNodeElement(T element) {
this.element = element;
}

/**
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/at/jotschi/quadtree/AbstractQuadTree.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package at.jotschi.quadtree;

import java.awt.Dimension;
import java.awt.Point;

import at.jotschi.quadtree.impl.PointNode;

public abstract class AbstractQuadTree<T> {

protected Dimension size;
protected Point startCoordinates;

public AbstractQuadTree(Point startCoordinates, Dimension size) {
this.size = size;
this.startCoordinates = startCoordinates;
}

/**
* Returns the size
*
* @return
*/
public Dimension getSize() {
return this.size;
}

/**
* Returns the startCoordinates
*
* @return
*/
public Point getStartCoordinates() {
return this.startCoordinates;
}

/**
* Clear the QuadTree
*/
public abstract void clear();


/**
* Return the root node of this quad tree
* @return
*/
public abstract PointNode<T> getRootNode();


}
18 changes: 0 additions & 18 deletions src/main/java/at/jotschi/quadtree/BoundsNode.java

This file was deleted.

24 changes: 0 additions & 24 deletions src/main/java/at/jotschi/quadtree/BoundsNodeElement.java

This file was deleted.

Loading

0 comments on commit a01492b

Please sign in to comment.