-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added first set of BoundQuadTree classes
- Loading branch information
Showing
10 changed files
with
402 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package at.jotschi.quadtree; | ||
|
||
import java.awt.Dimension; | ||
import java.awt.Point; | ||
|
||
public class BoundsNode<T> extends Node<T> { | ||
|
||
public BoundsNode(Point startCoordinates, Dimension bounds, int depth) { | ||
super(startCoordinates, bounds, depth); | ||
} | ||
|
||
public BoundsNode(Point startCoordinates, Dimension bounds, int depth, | ||
int maxDepth, int maxChildren) { | ||
super(startCoordinates, bounds, depth, maxDepth, maxChildren); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package at.jotschi.quadtree; | ||
|
||
import java.awt.Dimension; | ||
import java.awt.Point; | ||
|
||
@SuppressWarnings("serial") | ||
public class BoundsNodeElement<T> extends NodeElement<T> { | ||
|
||
protected Dimension bounds; | ||
|
||
public BoundsNodeElement(Point coordinates, Dimension bounds, T element) { | ||
super(coordinates, element); | ||
this.bounds = bounds; | ||
} | ||
|
||
public int getWidth() { | ||
return this.bounds.width; | ||
} | ||
|
||
public int getHeight() { | ||
return this.bounds.height; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package at.jotschi.quadtree; | ||
|
||
import java.awt.Dimension; | ||
import java.awt.Point; | ||
|
||
/** | ||
* Creates a new QuadTree that can hold the given type of elements. Each element | ||
* can also have a certain dimension. | ||
* | ||
* @author jotschi | ||
* | ||
* @param <T> | ||
*/ | ||
public class BoundsQuadTree<T> extends QuadTree<T> { | ||
|
||
/** | ||
* Create a new QuadTree with the give start coordinates and size | ||
* | ||
* @param startCorrdinates | ||
* @param size | ||
*/ | ||
public BoundsQuadTree(Point startCoordinates, Dimension size) { | ||
|
||
super(startCoordinates, size); | ||
|
||
this.rootNode = new BoundsNode<T>(startCoordinates, size, 0); | ||
} | ||
|
||
/** | ||
* Add a new element to the QuadTree that has a specific dimension/size | ||
* | ||
* @param point | ||
* @param size | ||
* @param element | ||
*/ | ||
public void insert(Point point, Dimension elementSize, T element) { | ||
|
||
// Check if the element coordinates are within bounds of the quadtree | ||
if (point.x > startCoordinates.x + size.width | ||
|| point.x < startCoordinates.x) { | ||
throw new IndexOutOfBoundsException( | ||
"The x coordinate must be within bounds of [" | ||
+ startCoordinates.x + "] to [" + size.width | ||
+ "] / [" + point.x + "]"); | ||
} | ||
if (point.y > startCoordinates.y + size.height | ||
|| point.y < startCoordinates.y) { | ||
throw new IndexOutOfBoundsException( | ||
"The y coordinate must be within bounds of [" | ||
+ startCoordinates.y + "] to [" + size.height | ||
+ "] / [" + point.y + "]"); | ||
} | ||
|
||
// Check if the right bottom corner is within bounds | ||
if (point.x + elementSize.width > startCoordinates.x + size.width | ||
|| point.x < startCoordinates.x) { | ||
throw new IndexOutOfBoundsException( | ||
"The x coordinate must be within bounds of [" | ||
+ startCoordinates.x + "] to [" + size.width | ||
+ "] / [" + point.x + elementSize.width + "]"); | ||
} | ||
if (point.y + elementSize.height > startCoordinates.y + size.height | ||
|| point.y < startCoordinates.y) { | ||
throw new IndexOutOfBoundsException( | ||
"The y coordinate must be within bounds of [" | ||
+ startCoordinates.y + "] to [" + size.height | ||
+ "] / [" + point.x + elementSize.height + "]"); | ||
} | ||
|
||
this.rootNode.insert(new BoundsNodeElement<T>(point, elementSize, element)); | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.