();
- todo.push(node);
- QuadNode current;
- do {
- current = todo.pop();
- for (QuadNode child : current.quads) {
- if (child == null) {
- continue;
- }
- // If the child isn't holding a list of cuboids itself
- // (which would make it the list holder link for its children)
- // Then we need to fix it's children as well
- if (child.cuboids.size() == 0) {
- todo.push(child);
- }
- child.nextListHolder = node;
- }
- } while (!todo.isEmpty());
- }
-
- private QuadNode ascendFirstSearch(QuadNode node, int x, int z) {
- while (node != null && (node.x > x || node.z > z || (node.x + node.size) < x || (node.z + node.size) < z)) {
- node = node.parent;
- }
- if (node == null)
- return null;
- return descendAndSearch(node, x, z);
- }
-
- private void beginTree(QuadCuboid cuboid) {
- int size = 128;
- int minSize = Math.abs(cuboid.lowCoords[0] - cuboid.highCoords[0]);
- int minSizeB = Math.abs(cuboid.lowCoords[2] - cuboid.highCoords[2]);
- if (minSize < minSizeB) {
- minSize = minSizeB;
- }
- while (size < minSize) {
- size = size << 1;
- }
- root = new QuadNode(cuboid.lowCoords[0], cuboid.lowCoords[2], size - 1, null);
- }
-
- /**
- * Returns -1 for too small, 0 for minimal, 1 for larger than needed
- *
- * Fit is based on the larger side. Means more tests but consumes an order of magnitude or less memory.
- *
- * @param node
- * @param cuboid
- * @return
- */
- private int containerFit(QuadNode node, QuadCuboid cuboid) {
- int minSizeA = Math.abs(cuboid.lowCoords[0] - cuboid.highCoords[0]);
- int minSizeB = Math.abs(cuboid.lowCoords[2] - cuboid.highCoords[2]);
- int fitSize;
- if (minSizeA < minSizeB) {
- fitSize = minSizeB;
- } else {
- fitSize = minSizeA;
- }
-
- if (node.size < fitSize) {
- return -1;
- } else if (node.size == 1 || (node.size >> 1) < fitSize) {
- return 0;
- } else {
- return 1;
- }
- }
-
- private QuadNode descendAndCreate(QuadNode start, QuadCuboid cuboid) {
- QuadNode next = start;
- while (containerFit(next, cuboid) > 0) {
- int i = 0;
- int nX = 0;
- int nZ = 0;
- int half = (next.size >> 1);
- if (cuboid.lowCoords[0] > (next.x + half)) {
- i++;
- nX = half + 1;
- }
- if (cuboid.lowCoords[2] > (next.z + half)) {
- i += 2;
- nZ = half + 1;
- }
- if (next.quads[i] == null) {
- next.quads[i] = new QuadNode(next.x + nX, next.z + nZ, half, next);
- }
- next = next.quads[i];
- }
- return next;
- }
-
- private QuadNode descendAndSearch(QuadNode node, int x, int z) {
- QuadNode next = node;
- while (next != null) {
- node = next;
- int half = node.size >> 1;
- int i = 0;
- if (x > (node.x + half)) {
- i++;
- }
- if (z > (node.z + half)) {
- i += 2;
- }
- next = node.quads[i];
- }
- return node;
- }
-
- private QuadNode descendNoCreate(QuadNode start, QuadCuboid cuboid) {
- QuadNode next = start;
- while (containerFit(next, cuboid) > 0) {
- int i = 0;
- int nX = 0;
- int nZ = 0;
- int half = (next.size >> 1);
- if (cuboid.lowCoords[0] > (next.x + half)) {
- i++;
- nX = half + 1;
- }
- if (cuboid.lowCoords[2] > (next.z + half)) {
- i += 2;
- nZ = half + 1;
- }
- if (next.quads[i] == null) {
- next = new QuadNode(next.x + nX, next.z + nZ, half, next);
- } else {
- next = next.quads[i];
- }
- }
- return next;
- }
-
- public BookmarkedResult findOverlappingCuboids(int x, int y, int z) {
- return relatedSearch(null, x, y, z);
- }
-
- public BookmarkedResult findOverlappingCuboidsFromBookmark(BookmarkedResult bookmark, int x, int y, int z) {
- return relatedSearch(bookmark.bookmark, x, y, z);
- }
-
- /**
- * Oftentimes a node will overlap with the neighbors of a node Since we always search for the next node based on the
- * lower left we know that the left and bottom will not go over the edge, leaving only the top, right, and upper
- * right possibilities need be regarded. Spits out a list of cuboids that are fit for "insertion" although we just
- * use them for the search and actually attach the original cuboid. We also return the remainder shard if we
- * generated any others. At the other end we only include a node if it's shard didn't re-shard. Keeps the tree
- * search spaces minimal.
- */
- private List generateShards(QuadNode node, QuadCuboid cuboid) {
- List shards = new ArrayList(4);
- int top = node.z + node.size;
- int right = node.x + node.size;
- int tmp;
-
- // find a shard above if it exists
- if (top < cuboid.highCoords[2]) {
- // Find out if it extends past the top only or the right and top
- // Limit the "top" shard to only directly above the original node
- if (right < cuboid.highCoords[0]) {
- tmp = right;
- } else {
- tmp = cuboid.highCoords[0];
- }
- shards.add(new QuadCuboid(cuboid.lowCoords[0], 0, top + 1, tmp, 0, cuboid.highCoords[2]));
- }
- // Find a shard to the right
- if (right < cuboid.highCoords[0]) {
- // find if we extend past the top as well
- // Limit the "right" shard to only directly right
- if (top < cuboid.highCoords[2]) {
- tmp = top;
- } else {
- tmp = cuboid.highCoords[2];
- }
- shards.add(new QuadCuboid(right + 1, 0, cuboid.lowCoords[2], cuboid.highCoords[0], 0, tmp));
- }
- // Check for a top right shard
- if (right < cuboid.highCoords[0] && top < cuboid.highCoords[2]) {
- shards.add(new QuadCuboid(right + 1, 0, top + 1, cuboid.highCoords[0], 0, cuboid.highCoords[2]));
- }
- // include the remainder as a shard if we generated any others
- if (shards.size() > 0) {
- shards.add(new QuadCuboid(cuboid.lowCoords[0], 0, cuboid.lowCoords[2], right, 0, top));
- }
- return shards;
- }
-
- public List getAllOverlapsWith(QuadCuboid cuboid) {
- if (root == null)
- return Collections.emptyList();
-
- // if this cuboid falls outside of the tree, we need to repot the tree
- // to
- // gain a wider perspective!
- if (!nodeFullyContainsCuboid(root, cuboid)) {
- repotTree(cuboid);
- }
- QuadNode node = root;
- node = descendNoCreate(node, cuboid);
- // Now that we have our target we potentially need to generate shards
- // and
- // target their nodes as well
- List targets = getAllTargetsNoCreate(node, cuboid);
- Deque children = new ArrayDeque();
- Set cuboids = new HashSet(256);
- // Generous initial capacity for speed
- QuadNode childTarget;
- // Of note: adding all the cuboids to the set and then testing is faster
- // than testing as we go and potentially getting out faster
- // This is especially true when there is less likely to be an overlap
- // anyway
- for (QuadNode target : targets) {
- // Drill down to the children nodes to get the smaller cuboids
- // contained therein
- children.add(target);
- do {
- childTarget = children.pop();
- for (QuadNode child : childTarget.quads) {
- if (child == null) {
- continue;
- }
- children.push(child);
- cuboids.addAll(child.cuboids);
- }
- } while (!children.isEmpty());
- // Then ascend backup and add the ones there
- while (target != null) {
- cuboids.addAll(target.cuboids);
- target = target.nextListHolder;
- }
- }
- List overlaps = new ArrayList();
- for (QuadCuboid pc : cuboids) {
- if (cuboid.overlaps(pc)) {
- overlaps.add(pc);
- }
- }
- return overlaps;
- }
-
- // Finds all the nodes that a cuboid should reside in (handles sharding)
- private List getAllTargets(QuadNode initialNode, QuadCuboid cuboid) {
- List targets = new ArrayList();
- // Generate the initial shards
- Deque shards = new ArrayDeque();
- shards.addAll(generateShards(initialNode, cuboid));
-
- QuadNode node;
- while (!shards.isEmpty()) {
- QuadCuboid shard = shards.pop();
- node = descendAndCreate(root, shard);
- List newShards = generateShards(node, shard);
- // If no shards were made then this is is the bounding node for this
- // shard. Include it.
- if (newShards.size() == 0) {
- targets.add(node);
- } else {
- shards.addAll(newShards);
- }
- }
-
- // If the initial shard attempt turns out to not have had
- // to generate shards then we need to add the initial node
- if (targets.size() == 0) {
- targets.add(initialNode);
- }
-
- return targets;
- }
-
- // Finds all the nodes that a cuboid should reside in (handles sharding)
- private List getAllTargetsNoCreate(QuadNode initialNode, QuadCuboid cuboid) {
- List targets = new ArrayList();
- // Generate the initial shards
- Deque shards = new ArrayDeque();
- shards.addAll(generateShards(initialNode, cuboid));
-
- QuadNode node;
- while (!shards.isEmpty()) {
- QuadCuboid shard = shards.pop();
- node = descendNoCreate(root, shard);
- List newShards = generateShards(node, shard);
- // If no shards were made then this is is the bounding node for this
- // shard. Include it.
- if (newShards.size() == 0) {
- targets.add(node);
- } else {
- shards.addAll(newShards);
- }
- }
-
- // If the initial shard attempt turns out to not have had
- // to generate shards then we need to add the initial node
- if (targets.size() == 0) {
- targets.add(initialNode);
- }
-
- return targets;
- }
-
- private List getMatchingCuboids(QuadNode target, int x, int y, int z) {
- List matches = new ArrayList();
- while (target != null) {
- for (QuadCuboid potential : target.cuboids) {
- if (potential.includesPoint(x, y, z)) {
- matches.add(potential);
- }
- }
- target = target.nextListHolder;
- }
- return matches;
- }
-
- public void insert(QuadCuboid cuboid) {
- if (root == null) {
- beginTree(cuboid);
- }
- // if this cuboid falls outside of the tree, we need to repot the tree
- // to
- // gain a wider perspective!
- if (!nodeFullyContainsCuboid(root, cuboid)) {
- repotTree(cuboid);
- }
- QuadNode node = root;
- node = descendAndCreate(node, cuboid);
- // Now that we have our target we potentially need to generate shards
- // and
- // target their nodes as well
- List targets = getAllTargets(node, cuboid);
- // Add the cuboid everywhere it belongs
- for (QuadNode target : targets) {
- addAndFixListHolders(target, cuboid);
- }
- }
-
- /**
- * Attempts to insert the node ONLY if there are no overlaps with existing nodes
- *
- * @param cuboid
- * cuboid to insert
- * @return success or failure
- */
- public boolean insertIfNoOverlaps(QuadCuboid cuboid) {
- if (root == null) {
- insert(cuboid);
- return true;
- }
- // if this cuboid falls outside of the tree, we need to repot the tree
- // to
- // gain a wider perspective!
- if (!nodeFullyContainsCuboid(root, cuboid)) {
- repotTree(cuboid);
- }
- QuadNode node = root;
- node = descendAndCreate(node, cuboid);
- // Now that we have our target we potentially need to generate shards
- // and target their nodes as well
- List targets = getAllTargets(node, cuboid);
- Deque children = new ArrayDeque();
- Set cuboids = new HashSet(256);
- // Generous initial capacity for speed
- QuadNode childTarget;
- // Of note: adding all the cuboids to the set and then testing is faster
- // than testing as we go and potentially getting out faster
- // This is especially true when there is less likely to be an overlap
- // anyway
- for (QuadNode target : targets) {
- // Drill down to the children nodes to get the smaller cuboids
- // contained therein
- children.add(target);
- do {
- childTarget = children.pop();
- for (QuadNode child : childTarget.quads) {
- if (child == null) {
- continue;
- }
- children.push(child);
- cuboids.addAll(child.cuboids);
- }
- } while (!children.isEmpty());
- // Then ascend backup and add the ones there
- while (target != null) {
- cuboids.addAll(target.cuboids);
- target = target.nextListHolder;
- }
- }
- for (QuadCuboid pc : cuboids) {
- if (cuboid.overlaps(pc)) {
- for (QuadNode target : targets) {
- if (target.cuboids.size() == 0) {
- pruneTree(node);
- }
- }
- return false;
- }
- }
- // Add the cuboid everywhere it belongs
- for (QuadNode target : targets) {
- addAndFixListHolders(target, cuboid);
- }
- return true;
- }
-
- private boolean nodeFullyContainsCuboid(QuadNode node, QuadCuboid cuboid) {
- return node.x <= cuboid.lowCoords[0] && node.z <= cuboid.lowCoords[2]
- && (node.x + node.size) >= cuboid.highCoords[0] && (node.z + node.size) >= cuboid.highCoords[2];
- }
-
- public boolean overlapsExisting(QuadCuboid cuboid) {
- if (root == null) {
- return false;
- }
- // if this cuboid falls outside of the tree, we need to repot the tree
- // to
- // gain a wider perspective!
- if (!nodeFullyContainsCuboid(root, cuboid)) {
- repotTree(cuboid);
- }
- QuadNode node = root;
- node = descendNoCreate(node, cuboid);
- // Now that we have our target we potentially need to generate shards
- // and
- // target their nodes as well
- List targets = getAllTargetsNoCreate(node, cuboid);
- Deque children = new ArrayDeque();
- Set cuboids = new HashSet(256);
- // Generous initial capacity for speed
- QuadNode childTarget;
- // Of note: adding all the cuboids to the set and then testing is faster
- // than testing as we go and potentially getting out faster
- // This is especially true when there is less likely to be an overlap
- // anyway
- for (QuadNode target : targets) {
- // Drill down to the children nodes to get the smaller cuboids
- // contained therein
- children.add(target);
- do {
- childTarget = children.pop();
- for (QuadNode child : childTarget.quads) {
- if (child == null) {
- continue;
- }
- children.push(child);
- cuboids.addAll(child.cuboids);
- }
- } while (!children.isEmpty());
- // Then ascend backup and add the ones there
- while (target != null) {
- cuboids.addAll(target.cuboids);
- target = target.nextListHolder;
- }
- }
- for (QuadCuboid pc : cuboids) {
- if (cuboid.overlaps(pc)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Removes any node from the tree that no longer serves a purpose, starting from the node given and moving up
- *
- * @param node
- */
- private void pruneTree(QuadNode node) {
- int i;
- while (node.parent != null && node.quads[0] == null && node.quads[1] == null && node.quads[2] == null
- && node.quads[3] == null) {
- i = 0;
- if (node.x != node.parent.x)
- i++;
-
- if (node.z != node.parent.z)
- i += 2;
-
- node = node.parent;
- node.quads[i] = null;
- }
- }
-
- private BookmarkedResult relatedSearch(QuadNode bookmark, int x, int y, int z) {
- if (bookmark == null)
- bookmark = root;
-
- QuadNode node = ascendFirstSearch(bookmark, x, z);
- return new BookmarkedResult(node, getMatchingCuboids(node, x, y, z));
- }
-
- public void remove(QuadCuboid cuboid) {
- // No root? No-Op!
- if (root == null) {
- return;
- }
- QuadNode node;
- // Should not create any new nodes, but only if the cuboid is, in fact,
- // in
- // the tree
- node = descendAndCreate(root, cuboid);
- // Using the same algorithm that was used during creation will give us
- // the
- // same list of nodes to examine
- List targets = getAllTargets(node, cuboid);
- for (QuadNode target : targets) {
- removeAndFixListHolders(target, cuboid);
- }
- }
-
- private void removeAndFixListHolders(QuadNode node, QuadCuboid cuboid) {
- node.cuboids.remove(cuboid);
- // This wasn't our only cuboid, so no fix needed
- if (node.cuboids.size() > 0)
- return;
-
- // Descend the tree. When we find a node with no children we know it
- // needs a new list holder
- Deque todo = new ArrayDeque();
- todo.push(node);
- QuadNode current;
- do {
- current = todo.pop();
- for (QuadNode child : current.quads) {
- if (child == null) {
- continue;
- }
- // If the child isn't holding a list of cuboids itself
- // (which would make it the list holder link for its children)
- // Then we need to fix its children as well
- if (child.cuboids.size() == 0)
- todo.push(child);
-
- child.nextListHolder = node.nextListHolder;
- }
- } while (!todo.isEmpty());
- pruneTree(node);
- }
-
- /**
- * Grow the tree beyond the root in the direction of the target node
- *
- * @param cuboid
- */
- private void repotTree(QuadCuboid cuboid) {
- QuadNode oldRoot;
- int i;
- do {
- oldRoot = root;
- root = new QuadNode(oldRoot.x, oldRoot.z, (oldRoot.size << 1) + 1, null);
- oldRoot.parent = root;
- // Figure out the best direction to grow in (that is, which quadrant
- // is the old root in the new root?)
- // We start at lower left (quad 0)
- i = 0;
- // The target is left of us
- if (cuboid.lowCoords[0] < root.x) {
- i++;
- root.x -= oldRoot.size + 1;
- }
- // The target is below us
- if (cuboid.lowCoords[2] < root.z) {
- i += 2;
- root.z -= oldRoot.size + 1;
- }
- root.quads[i] = oldRoot;
- } while (!nodeFullyContainsCuboid(root, cuboid));
- }
-
- public List search(int x, int y, int z) {
- QuadNode node = descendAndSearch(root, x, z);
- return getMatchingCuboids(node, x, y, z);
- }
-}
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/Circle.java b/src/main/java/net/citizensnpcs/api/util/prtree/Circle.java
deleted file mode 100644
index 9b4ec6ef..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/Circle.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * A simple circular data structure.
- *
- * @param
- * the element type
- */
-class Circle {
- private int currentPos;
- private final List data;
-
- public Circle(int size) {
- data = new ArrayList(size);
- }
-
- public void add(T t) {
- data.add(t);
- }
-
- public T get(int pos) {
- pos %= data.size();
- return data.get(pos);
- }
-
- public T getNext() {
- T ret = data.get(currentPos++);
- currentPos %= data.size();
- return ret;
- }
-
- public int getNumElements() {
- return data.size();
- }
-
- public void reset() {
- currentPos = 0;
- }
-}
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/DataComparators.java b/src/main/java/net/citizensnpcs/api/util/prtree/DataComparators.java
deleted file mode 100644
index 17690437..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/DataComparators.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-import java.util.Comparator;
-
-class DataComparators implements NodeComparators {
- private final MBRConverter converter;
-
- public DataComparators(MBRConverter converter) {
- this.converter = converter;
- }
-
- public Comparator getMaxComparator(final int axis) {
- return new Comparator() {
- public int compare(T t1, T t2) {
- double d1 = converter.getMax(axis, t1);
- double d2 = converter.getMax(axis, t2);
- return Double.compare(d1, d2);
- }
- };
- }
-
- public Comparator getMinComparator(final int axis) {
- return new Comparator() {
- public int compare(T t1, T t2) {
- double d1 = converter.getMin(axis, t1);
- double d2 = converter.getMin(axis, t2);
- return Double.compare(d1, d2);
- }
- };
- }
-}
\ No newline at end of file
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/DistanceCalculator.java b/src/main/java/net/citizensnpcs/api/util/prtree/DistanceCalculator.java
deleted file mode 100644
index 2c84478a..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/DistanceCalculator.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-/**
- * A class that can calculate the distance to a given object stored in the PRTree
- *
- * @param
- * the data type to calculate distances to
- */
-public interface DistanceCalculator {
- /**
- * Calculate the distance between the given object and the point
- *
- * @param t
- * the object to calculate the distance to
- * @param p
- * the point
- * @return The calculated distance
- */
- double distanceTo(T t, PointND p);
-}
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/DistanceResult.java b/src/main/java/net/citizensnpcs/api/util/prtree/DistanceResult.java
deleted file mode 100644
index 61c6292d..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/DistanceResult.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-/**
- * Class to hold object and distance to it
- *
- * @param
- * The node type
- */
-public class DistanceResult {
- private final double dist;
- private final T t;
-
- /**
- * Create a new DistanceResult with a given object and distance
- *
- * @param t
- * the object we are measuring the distance to
- * @param dist
- * the actual distance to the object
- */
- public DistanceResult(T t, double dist) {
- this.t = t;
- this.dist = dist;
- }
-
- /**
- * Get the object
- *
- * @return The node object
- */
- public T get() {
- return t;
- }
-
- /**
- * Get the distance
- *
- * @return The distance to the node object
- */
- public double getDistance() {
- return dist;
- }
-}
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/InternalNode.java b/src/main/java/net/citizensnpcs/api/util/prtree/InternalNode.java
deleted file mode 100644
index 9e20028e..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/InternalNode.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-import java.util.List;
-import java.util.PriorityQueue;
-
-class InternalNode extends NodeBase, T> {
- public InternalNode(Object[] data) {
- super(data);
- }
-
- @Override
- public MBR computeMBR(MBRConverter converter) {
- MBR ret = null;
- for (int i = 0, s = size(); i < s; i++)
- ret = getUnion(ret, get(i).getMBR(converter));
- return ret;
- }
-
- public void expand(MBR mbr, MBRConverter converter, List found, List> nodesToExpand) {
- for (int i = 0, s = size(); i < s; i++) {
- Node n = get(i);
- if (mbr.intersects(n.getMBR(converter)))
- nodesToExpand.add(n);
- }
- }
-
- public void find(MBR mbr, MBRConverter converter, List result) {
- for (int i = 0, s = size(); i < s; i++) {
- Node n = get(i);
- if (mbr.intersects(n.getMBR(converter)))
- n.find(mbr, converter, result);
- }
- }
-
- public void nnExpand(DistanceCalculator dc, NodeFilter filter, List> drs, int maxHits,
- PriorityQueue> queue, MinDistComparator> mdc) {
- int s = size();
- for (int i = 0; i < s; i++) {
- Node n = get(i);
- MBR mbr = n.getMBR(mdc.converter);
- double minDist = MinDist.get(mbr, mdc.p);
- int t = drs.size();
- // drs is sorted so we can check only the last entry
- if (t < maxHits || minDist <= drs.get(t - 1).getDistance())
- queue.add(n);
- }
- }
-}
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/InternalNodeComparators.java b/src/main/java/net/citizensnpcs/api/util/prtree/InternalNodeComparators.java
deleted file mode 100644
index 8b01c672..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/InternalNodeComparators.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-import java.util.Comparator;
-
-class InternalNodeComparators implements NodeComparators> {
- private final MBRConverter converter;
-
- public InternalNodeComparators(MBRConverter converter) {
- this.converter = converter;
- }
-
- public Comparator> getMaxComparator(final int axis) {
- return new Comparator>() {
- public int compare(Node n1, Node n2) {
- double d1 = n1.getMBR(converter).getMax(axis);
- double d2 = n2.getMBR(converter).getMax(axis);
- return Double.compare(d1, d2);
- }
- };
- }
-
- public Comparator> getMinComparator(final int axis) {
- return new Comparator>() {
- public int compare(Node n1, Node n2) {
- double d1 = n1.getMBR(converter).getMin(axis);
- double d2 = n2.getMBR(converter).getMin(axis);
- return Double.compare(d1, d2);
- }
- };
- }
-}
\ No newline at end of file
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/LeafBuilder.java b/src/main/java/net/citizensnpcs/api/util/prtree/LeafBuilder.java
deleted file mode 100644
index 6076d4e4..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/LeafBuilder.java
+++ /dev/null
@@ -1,189 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
-/**
- * A builder of internal nodes used during bulk loading of a PR-Tree. A PR-Tree is build by building a pseudo R-Tree and
- * grabbing the leaf nodes (and then repeating until you have just one root node). This class creates the leaf nodes
- * without building the full pseudo tree.
- */
-class LeafBuilder {
-
- private final int branchFactor;
- private final int dimensions;
-
- public LeafBuilder(int dimensions, int branchFactor) {
- this.dimensions = dimensions;
- this.branchFactor = branchFactor;
- }
-
- private void addGetterAndSplitter(List> nodes, Comparator tcomp,
- Circle> getters) {
- Comparator> comp = new NodeUsageComparator(tcomp);
- Collections.sort(nodes, comp);
- List> sortedNodes = new ArrayList>(nodes);
- getters.add(new Noder(sortedNodes));
- }
-
- public void buildLeafs(Collection extends T> ls, NodeComparators comparators, NodeFactory nf,
- List leafNodes) {
- List> nodes = new ArrayList>(ls.size());
- for (T t : ls)
- nodes.add(new NodeUsage(t, 1));
-
- Circle> getters = new Circle>(dimensions * 2);
-
- for (int i = 0; i < dimensions; i++)
- addGetterAndSplitter(nodes, comparators.getMinComparator(i), getters);
-
- for (int i = 0; i < dimensions; i++)
- addGetterAndSplitter(nodes, comparators.getMaxComparator(i), getters);
-
- getLeafs(1, ls.size(), getters, nf, leafNodes);
- }
-
- private void getLeafs(int id, int totalNumberOfElements, Circle> getters, NodeFactory nf,
- List leafNodes) {
- List partitionsToExpand = new ArrayList();
- int[] pos = new int[2 * dimensions];
- partitionsToExpand.add(new Partition(id, totalNumberOfElements, pos));
- while (!partitionsToExpand.isEmpty()) {
- Partition p = partitionsToExpand.remove(0);
- // Get the extreme nodes
- getters.reset();
- for (int i = 0; i < getters.getNumElements(); i++) {
- int nodesToGet = Math.min(p.numElementsLeft, branchFactor);
- if (nodesToGet == 0)
- break;
- Noder noder = getters.getNext();
- leafNodes.add(noder.getNextNode(p, i, nodesToGet, nf));
- p.numElementsLeft -= nodesToGet;
- }
- // Split the rest of the elements
- if (p.numElementsLeft > 0) {
- int splitPos = getSplitPos(p.id) % getters.getNumElements();
- Noder s = getters.get(splitPos);
- s.split(p, splitPos, p.numElementsLeft, p.id, 2 * p.id, 2 * p.id + 1, partitionsToExpand);
- }
- }
- }
-
- private int getSplitPos(int n) {
- // id is generated by the power of twos so get biggest n where 2 ^ n < id
- // id: 1 -> splitPos 0, id: 2 -> 1, 3 -> 1, 4 -> 2, 5 -> 2, 7 -> 2, 8 -> 3
- int splitPos = 0;
- while (n >= 2) {
- n >>= 1;
- splitPos++;
- }
- return splitPos;
- }
-
- private static class Noder {
- private final List> data;
-
- private Noder(List> data) {
- this.data = data;
- }
-
- /**
- * Get the next node.
- *
- * @param p
- * the Partition to get a node from
- * @param gi
- * the current getter index
- * @param maxObjects
- * use at most this many objects
- * @param nf
- * the NodeFactory used to create the nodes
- * @return the next node
- */
- private N getNextNode(Partition p, int gi, int maxObjects, NodeFactory nf) {
-
- Object nodeData[] = new Object[maxObjects];
- int s = data.size();
- for (int i = 0; i < maxObjects; i++) {
- while (p.currentPositions[gi] < s && isUsedNode(p, p.currentPositions[gi])) {
- p.currentPositions[gi]++;
- }
- NodeUsage nu = data.set(p.currentPositions[gi], null);
- nodeData[i] = nu.getData();
- nu.use();
- }
-
- for (int i = 0; i < nodeData.length; i++) {
- if (nodeData[i] == null) {
- for (int j = 0; j < data.size(); j++)
- System.err.println(j + ": " + data.get(j));
- throw new NullPointerException("Null data found at: " + i);
- }
- }
- return nf.create(nodeData);
- }
-
- private boolean isUsedNode(Partition p, int pos) {
- NodeUsage nu = data.get(pos);
- return nu == null || nu.isUsed() || nu.getOwner() != p.id;
- }
-
- private int markPart(int numToMark, int fromId, int toId, int startPos) {
- NodeUsage nu;
- while (numToMark > 0) {
- while ((nu = data.get(startPos)) == null || nu.getOwner() != fromId)
- startPos++;
- nu.changeOwner(toId);
- numToMark--;
- }
- return startPos;
- }
-
- private void split(Partition p, int gi, int nodesToMark, int fromId, int toId1, int toId2,
- List partitionsToExpand) {
- int sizePart2 = nodesToMark / 2;
- int sizePart1 = nodesToMark - sizePart2;
- int startPos = p.currentPositions[gi];
- int startPos2 = markPart(sizePart1, fromId, toId1, startPos);
- markPart(sizePart2, fromId, toId2, startPos2);
- partitionsToExpand.add(0, new Partition(toId1, sizePart1, p.currentPositions));
- int[] pos = p.currentPositions.clone();
- pos[gi] = startPos2;
- partitionsToExpand.add(1, new Partition(toId2, sizePart2, pos));
- }
- }
-
- private static class NodeUsageComparator implements Comparator> {
- private Comparator sorter;
-
- public NodeUsageComparator(Comparator sorter) {
- this.sorter = sorter;
- }
-
- public int compare(NodeUsage n1, NodeUsage n2) {
- return sorter.compare(n1.getData(), n2.getData());
- }
- }
-
- private static class Partition {
- private int[] currentPositions;
- private final int id;
- private int numElementsLeft;
-
- public Partition(int id, int numElementsLeft, int[] currentPositions) {
- this.id = id;
- this.numElementsLeft = numElementsLeft;
- this.currentPositions = currentPositions;
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "{id: " + id + ", numElementsLeft: " + numElementsLeft
- + ", currentPositions: " + Arrays.toString(currentPositions) + "}";
- }
- }
-}
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/LeafNode.java b/src/main/java/net/citizensnpcs/api/util/prtree/LeafNode.java
deleted file mode 100644
index 763d2815..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/LeafNode.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import java.util.PriorityQueue;
-
-class LeafNode extends NodeBase {
-
- public LeafNode(Object[] data) {
- super(data);
- }
-
- private void add(List> drs, DistanceResult dr, int maxHits) {
- int n = drs.size();
- if (n == maxHits)
- drs.remove(n - 1);
- int pos = Collections.binarySearch(drs, dr, comp);
- if (pos < 0) {
- // binarySearch return -(pos + 1) for new entries
- pos = -(pos + 1);
- }
- drs.add(pos, dr);
- }
-
- @Override
- public MBR computeMBR(MBRConverter converter) {
- MBR ret = null;
- for (int i = 0, s = size(); i < s; i++)
- ret = getUnion(ret, getMBR(get(i), converter));
- return ret;
- }
-
- public void expand(MBR mbr, MBRConverter converter, List found, List> nodesToExpand) {
- find(mbr, converter, found);
- }
-
- public void find(MBR mbr, MBRConverter converter, List result) {
- for (int i = 0, s = size(); i < s; i++) {
- T t = get(i);
- if (mbr.intersects(t, converter))
- result.add(t);
- }
- }
-
- public MBR getMBR(T t, MBRConverter converter) {
- return new SimpleMBR(t, converter);
- }
-
- public void nnExpand(DistanceCalculator dc, NodeFilter filter, List> drs, int maxHits,
- PriorityQueue> queue, MinDistComparator> mdc) {
- for (int i = 0, s = size(); i < s; i++) {
- T t = get(i);
- if (filter.accept(t)) {
- double dist = dc.distanceTo(t, mdc.p);
- int n = drs.size();
- if (n < maxHits || dist < drs.get(n - 1).getDistance()) {
- add(drs, new DistanceResult(t, dist), maxHits);
- }
- }
- }
- }
-
- private static final Comparator> comp = new Comparator>() {
- public int compare(DistanceResult> d1, DistanceResult> d2) {
- return Double.compare(d1.getDistance(), d2.getDistance());
- }
- };
-}
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/MBR.java b/src/main/java/net/citizensnpcs/api/util/prtree/MBR.java
deleted file mode 100644
index d7f34dff..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/MBR.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-/**
- * A minimum bounding box for n dimensions.
- */
-public interface MBR {
- /**
- * @return the number of dimensions this bounding box has
- */
- int getDimensions();
-
- /**
- * Get the maximum value for the given axis
- *
- * @param axis
- * the axis to use
- * @return the x max value
- */
- double getMax(int axis);
-
- /**
- * Get the minimum value for the given axis
- *
- * @param axis
- * the axis to use
- * @return the min value
- */
- double getMin(int axis);
-
- /**
- * Check if the other MBR intersects this one
- *
- * @param other
- * the MBR to check against
- * @return true if the given MBR intersects with this MBR
- */
- boolean intersects(MBR other);
-
- /**
- * Check if this MBR intersects the rectangle given by the object and the MBRConverter.
- *
- * @param t
- * a rectangular object
- * @param converter
- * the MBRConverter
- * @return true if the given MBR intersects with the given object
- * @param
- * the object type
- */
- boolean intersects(T t, MBRConverter converter);
-
- /**
- * Return a new MBR that is the union of this mbr and the other
- *
- * @param mbr
- * the MBR to create a union with
- * @return the new MBR
- */
- MBR union(MBR mbr);
-}
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/MBR2D.java b/src/main/java/net/citizensnpcs/api/util/prtree/MBR2D.java
deleted file mode 100644
index d0dddcfd..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/MBR2D.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-/**
- * A minimum bounding rectangle
- */
-public interface MBR2D {
- /**
- * Get the maximum x value
- *
- * @return the x max value
- */
- double getMaxX();
-
- /**
- * Get the maximum y value
- *
- * @return the y max value
- */
- double getMaxY();
-
- /**
- * Get the minimum x value
- *
- * @return the x min value
- */
- double getMinX();
-
- /**
- * Get the minimum y value
- *
- * @return the y min value
- */
- double getMinY();
-
- /**
- * Check if the other MBR intersects this one
- *
- * @param other
- * the MBR to check against
- * @return true if the given MBR intersects with this MBR
- */
- boolean intersects(MBR2D other);
-
- /**
- * Return a new MBR that is the union of this mbr and the other
- *
- * @param mbr
- * the MBR to create a union with
- * @return the new MBR
- */
- MBR2D union(MBR2D mbr);
-}
\ No newline at end of file
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/MBRConverter.java b/src/main/java/net/citizensnpcs/api/util/prtree/MBRConverter.java
deleted file mode 100644
index 9679af46..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/MBRConverter.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-/**
- * A class that given a T can tell the minimum and maximum ordinates for that object.
- *
- * @param
- * the data type stored in the PRTree
- */
-public interface MBRConverter {
- /**
- * @return the number of dimensions this converter cares about
- */
- int getDimensions();
-
- /**
- * Get the maximum coordinate value for the given t
- *
- * @param axis
- * the axis to get the max value for
- * @param t
- * the object to get the mbr ordinate for
- * @return the max value for the given axis
- */
- double getMax(int axis, T t);
-
- /**
- * Get the minimum coordinate value for the given t.
- *
- * @param axis
- * the axis to get the min value for
- * @param t
- * the object to get the mbr ordinate for
- * @return the min value for the given axis
- */
- double getMin(int axis, T t);
-}
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/MinDist.java b/src/main/java/net/citizensnpcs/api/util/prtree/MinDist.java
deleted file mode 100644
index 26de6a74..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/MinDist.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-/**
- * Class that can calculate the MINDIST between a point and a rectangle
- */
-public class MinDist {
- /**
- * Do not instantiate
- */
- private MinDist() {
- // empty
- }
-
- /**
- * Calculate the MINDIST between the given MBRND and the given point
- *
- * @param mbr
- * the bounding box to use
- * @param p
- * the point
- * @return the squared distance
- */
- public static double get(MBR mbr, PointND p) {
- double res = 0;
- for (int i = 0; i < p.getDimensions(); i++) {
- double o = p.getOrd(i);
- double rv = r(o, mbr.getMin(i), mbr.getMax(i));
- double dr = o - rv;
- res += dr * dr;
- }
- return res;
- }
-
- private static double r(double x, double min, double max) {
- double r = x;
- if (x < min)
- r = min;
- if (x > max)
- r = max;
- return r;
- }
-}
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/MinDist2D.java b/src/main/java/net/citizensnpcs/api/util/prtree/MinDist2D.java
deleted file mode 100644
index 12a4487c..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/MinDist2D.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-/**
- * Class that can calculate the MINDIST between a point and a rectangle
- */
-public class MinDist2D {
- /**
- * Do not instantiate
- */
- private MinDist2D() {
- // empty
- }
-
- /**
- * Calculate the MINDIST between the given rectangle and the given point
- *
- * @param minx
- * the rectangle minimum x point
- * @param miny
- * the rectangle minimum y point
- * @param maxx
- * the rectangle maximum x point
- * @param maxy
- * the rectangle maximum y point
- * @param x
- * the point
- * @param y
- * the point
- * @return the squared distance
- */
- public static double get(double minx, double miny, double maxx, double maxy, double x, double y) {
- double rx = r(x, minx, maxx);
- double ry = r(y, miny, maxy);
- double xd = x - rx;
- double yd = y - ry;
- return xd * xd + yd * yd;
- }
-
- private static double r(double x, double min, double max) {
- double r = x;
- if (x < min)
- r = min;
- if (x > max)
- r = max;
- return r;
- }
-}
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/MinDistComparator.java b/src/main/java/net/citizensnpcs/api/util/prtree/MinDistComparator.java
deleted file mode 100644
index 44e9b400..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/MinDistComparator.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-import java.util.Comparator;
-
-/**
- * A comparator that uses the MINDIST metrics to sort Nodes
- *
- * @param
- * the data stored in the nodes
- * @param
- * the actual node
- */
-class MinDistComparator> implements Comparator {
- public final MBRConverter converter;
- public final PointND p;
-
- public MinDistComparator(MBRConverter converter, PointND p) {
- this.converter = converter;
- this.p = p;
- }
-
- public int compare(S t1, S t2) {
- MBR mbr1 = t1.getMBR(converter);
- MBR mbr2 = t2.getMBR(converter);
- return Double.compare(MinDist.get(mbr1, p), MinDist.get(mbr2, p));
- }
-}
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/NearestNeighbour.java b/src/main/java/net/citizensnpcs/api/util/prtree/NearestNeighbour.java
deleted file mode 100644
index 3f1dfd40..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/NearestNeighbour.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-import java.util.PriorityQueue;
-import java.util.ArrayList;
-import java.util.List;
-
-import net.citizensnpcs.api.util.prtree.DistanceResult;
-import net.citizensnpcs.api.util.prtree.NodeFilter;
-
-class NearestNeighbour {
-
- private final MBRConverter converter;
- private final DistanceCalculator dc;
- private final NodeFilter filter;
- private final int maxHits;
- private final PointND p;
- private final Node root;
-
- public NearestNeighbour(MBRConverter converter, NodeFilter filter, int maxHits, Node root,
- DistanceCalculator dc, PointND p) {
- this.converter = converter;
- this.filter = filter;
- this.maxHits = maxHits;
- this.root = root;
- this.dc = dc;
- this.p = p;
- }
-
- /**
- * @return the nearest neighbour
- */
- public List> find() {
- List> ret = new ArrayList>(maxHits);
- MinDistComparator> nc = new MinDistComparator>(converter, p);
- PriorityQueue> queue = new PriorityQueue>(20, nc);
- queue.add(root);
- while (!queue.isEmpty()) {
- Node n = queue.remove();
- n.nnExpand(dc, filter, ret, maxHits, queue, nc);
- }
- return ret;
- }
-}
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/Node.java b/src/main/java/net/citizensnpcs/api/util/prtree/Node.java
deleted file mode 100644
index 967542c2..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/Node.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-import java.util.List;
-import java.util.PriorityQueue;
-
-/**
- * A node in a Priority R-Tree
- *
- * @param
- * the data type of the elements stored in this node
- */
-interface Node {
- /**
- * Visit this node and add the leafs to the found list and add any child nodes to the list of nodes to expand.
- *
- * @param mbr
- * the query rectangle
- * @param converter
- * the MBR converter to use for the actual objects
- * @param found
- * the List of leaf nodes
- * @param nodesToExpand
- * the List of nodes that needs to be expanded
- */
- void expand(MBR mbr, MBRConverter converter, List found, List> nodesToExpand);
-
- /**
- * Find nodes that intersect with the given MBR.
- *
- * @param mbr
- * the query rectangle
- * @param converter
- * the MBR converter to use for the actual objects
- * @param result
- * the List to add the found nodes to
- */
- void find(MBR mbr, MBRConverter converter, List result);
-
- /**
- * Get the MBR of this node
- *
- * @param converter
- * the MBR converter to use for the actual objects
- * @return the MBR for this node
- */
- MBR getMBR(MBRConverter converter);
-
- /**
- * Expand the nearest neighbour search
- *
- * @param dc
- * the DistanceCalculator to use when calculating distances
- * @param filter
- * the NodeFilter to use when getting node objects
- * @param currentFinds
- * the currently found results, this list will be populated
- * @param maxHits
- * the maximum number of entries to store
- * @param queue
- * where to store child nodes that needs expansion
- * @param mdc
- * the MinDistComparator to use
- */
- void nnExpand(DistanceCalculator dc, NodeFilter filter, List> currentFinds, int maxHits,
- PriorityQueue> queue, MinDistComparator> mdc);
-
- /**
- * Get the size of the node, that is how many data elements it holds
- *
- * @return the number of elements (leafs or child nodes) that this node has
- */
- int size();
-
-}
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/NodeBase.java b/src/main/java/net/citizensnpcs/api/util/prtree/NodeBase.java
deleted file mode 100644
index 417adb0c..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/NodeBase.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-/**
- * @param
- * the type of the child entries
- * @param
- * the type of the data entries
- */
-abstract class NodeBase implements Node {
- private Object[] data;
- private MBR mbr;
-
- public NodeBase(Object[] data) {
- this.data = data;
- }
-
- public abstract MBR computeMBR(MBRConverter converter);
-
- @SuppressWarnings("unchecked")
- public N get(int i) {
- return (N) data[i];
- }
-
- public MBR getMBR(MBRConverter converter) {
- if (mbr == null)
- mbr = computeMBR(converter);
- return mbr;
- }
-
- public MBR getUnion(MBR m1, MBR m2) {
- if (m1 == null)
- return m2;
- return m1.union(m2);
- }
-
- public int size() {
- return data.length;
- }
-}
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/NodeComparators.java b/src/main/java/net/citizensnpcs/api/util/prtree/NodeComparators.java
deleted file mode 100644
index c93c4ee9..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/NodeComparators.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-import java.util.Comparator;
-
-interface NodeComparators {
- /**
- * Get a comparator for the given axis
- *
- * @param axis
- * the axis that the comparator will use
- * @return the comparator
- */
- Comparator getMaxComparator(int axis);
-
- /**
- * Get a comparator for the given axis
- *
- * @param axis
- * the axis that the comparator will use
- * @return the comparator
- */
- Comparator getMinComparator(int axis);
-}
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/NodeFactory.java b/src/main/java/net/citizensnpcs/api/util/prtree/NodeFactory.java
deleted file mode 100644
index 0bcf55c4..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/NodeFactory.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-/**
- * A factory that creates the nodes (either leaf or internal).
- *
- * @param
- * the data stored in the node
- * @param
- * the type of the node
- */
-interface NodeFactory {
- /**
- * Create a new node
- *
- * @param data
- * the data entries for the node, fully filled.
- * @return the new node
- */
- N create(Object[] data);
-}
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/NodeFilter.java b/src/main/java/net/citizensnpcs/api/util/prtree/NodeFilter.java
deleted file mode 100644
index 0a36c899..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/NodeFilter.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-/**
- * A node object filterer.
- *
- * @param
- * the node type
- */
-public interface NodeFilter {
- /**
- * Check if the given node object is accepted
- *
- * @param t
- * the node user data
- * @return True if the node is accepted, false otherwise
- */
- boolean accept(T t);
-}
\ No newline at end of file
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/NodeGetter.java b/src/main/java/net/citizensnpcs/api/util/prtree/NodeGetter.java
deleted file mode 100644
index b194a867..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/NodeGetter.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-import java.util.List;
-
-/**
- * A class that can get the next available node.
- *
- * @param
- * the type of the node
- */
-interface NodeGetter {
- /**
- * Get the next node.
- *
- * @param maxObjects
- * use at most this many objects
- * @return the next node
- */
- N getNextNode(int maxObjects);
-
- /**
- * Check if there is unused data in this NodeGetter.
- *
- * @return true if there is unused data, false otherwise
- */
- boolean hasMoreData();
-
- /**
- * Check if we can get more nodes from this NodeGetter.
- *
- * @return true if there are more nodes, false otherwise
- */
- boolean hasMoreNodes();
-
- /**
- * Split this NodeGetter into the low and high parts.
- *
- * @param lowId
- * the id of the low part
- * @param highId
- * the id of the high part
- * @return a list with the two sublists
- */
- List extends NodeGetter> split(int lowId, int highId);
-}
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/NodeUsage.java b/src/main/java/net/citizensnpcs/api/util/prtree/NodeUsage.java
deleted file mode 100644
index 257f4244..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/NodeUsage.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-/**
- * A node used while building the leaf sets, holds the actual data and an identifier for the partition this node belongs
- * to.
- *
- * @param
- * the data type of the stored item
- */
-class NodeUsage {
- private final T data;
- private int id;
-
- public NodeUsage(T data, int id) {
- this.data = data;
- this.id = id;
- }
-
- public void changeOwner(int id) {
- this.id = id;
- }
-
- public T getData() {
- return data;
- }
-
- public int getOwner() {
- return id;
- }
-
- public boolean isUsed() {
- return id < 0;
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "{data: " + data + ", id: " + id + "}";
- }
-
- public void use() {
- if (id >= 0)
- id = -id;
- else
- throw new RuntimeException("Trying to use already used node");
- }
-}
diff --git a/src/main/java/net/citizensnpcs/api/util/prtree/PRTree.java b/src/main/java/net/citizensnpcs/api/util/prtree/PRTree.java
deleted file mode 100644
index 88550b4a..00000000
--- a/src/main/java/net/citizensnpcs/api/util/prtree/PRTree.java
+++ /dev/null
@@ -1,304 +0,0 @@
-package net.citizensnpcs.api.util.prtree;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * A Priority R-Tree, a spatial index, for N dimensions. This tree only supports bulk loading.
- *
- * @param
- * the data type stored in the PRTree
- */
-public class PRTree {
-
- private final int branchFactor;
- private final MBRConverter converter;
-
- private int height;
- private int numLeafs;
- private Node root;
-
- /**
- * Create a new PRTree using the specified branch factor.
- *
- * @param converter
- * the MBRConverter to use for this tree
- * @param branchFactor
- * the number of child nodes for each internal node.
- */
- public PRTree(MBRConverter converter, int branchFactor) {
- this.converter = converter;
- this.branchFactor = branchFactor;
- }
-
- public void clear() {
- root = null;
- height = 0;
- numLeafs = 0;
- }
-
- private int estimateSize(int dataSize) {
- return (int) (1.0 / (branchFactor - 1) * dataSize);
- }
-
- /**
- * Find all objects that intersect the given rectangle. Note, this find method will only use two dimensions, no
- * matter how many dimensions the PRTree actually has.
- *
- * @param xmin
- * the minimum value of the x coordinate when searching
- * @param ymin
- * the minimum value of the y coordinate when searching
- * @param xmax
- * the maximum value of the x coordinate when searching
- * @param ymax
- * the maximum value of the y coordinate when searching
- * @return an iterable of the elements inside the query rectangle
- * @throws IllegalArgumentException
- * if xmin > xmax or ymin > ymax
- */
- public Iterable find(double xmin, double ymin, double xmax, double ymax) {
- return find(new SimpleMBR(xmin, xmax, ymin, ymax));
- }
-
- /**
- * Finds all objects that intersect the given rectangle and stores the found node in the given list. Note, this find
- * method will only use two dimensions, no matter how many dimensions the PRTree actually has.
- *
- * @param xmin
- * the minimum value of the x coordinate when searching
- * @param ymin
- * the minimum value of the y coordinate when searching
- * @param xmax
- * the maximum value of the x coordinate when searching
- * @param ymax
- * the maximum value of the y coordinate when searching
- * @param resultNodes
- * the list that will be filled with the result
- */
- public void find(double xmin, double ymin, double xmax, double ymax, List resultNodes) {
- find(new SimpleMBR(xmin, xmax, ymin, ymax), resultNodes);
- }
-
- /**
- * Find all objects that intersect the given rectangle.
- *
- * @param query
- * the bounds of the query
- * @throws IllegalArgumentException
- * if xmin > xmax or ymin > ymax
- * @return an iterable of the elements inside the query rectangle
- */
- public Iterable find(final MBR query) {
- validateRect(query);
- return new Iterable() {
- @Override
- public Iterator iterator() {
- return new Finder(query);
- }
- };
- }
-
- /**
- * Finds all objects that intersect the given rectangle and stores the found node in the given list.
- *
- * @param query
- * the bounds of the query
- * @param resultNodes
- * the list that will be filled with the result
- */
- public void find(MBR query, List resultNodes) {
- validateRect(query);
- root.find(query, converter, resultNodes);
- }
-
- /**
- * Get the height of this tree.
- *
- * @return the total height of this tree
- */
- public int getHeight() {
- return height;
- }
-
- /**
- * Get an N dimensional minimum bounding box of the data stored in this tree.
- *
- * @return the MBR of the whole PRTree
- */
- public MBR getMBR() {
- return root.getMBR(converter);
- }
-
- /**
- * Get a 2 dimensional minimum bounding rectangle of the data stored in this tree.
- *
- * @return the MBR of the whole PRTree
- */
- public MBR2D getMBR2D() {
- MBR mbr = getMBR();
- if (mbr == null)
- return null;
- return new SimpleMBR2D(mbr.getMin(0), mbr.getMin(1), mbr.getMax(0), mbr.getMax(1));
- }
-
- /**
- * Get the number of data leafs in this tree.
- *
- * @return the total number of leafs in this tree
- */
- public int getNumberOfLeaves() {
- return numLeafs;
- }
-
- /**
- * Check if this tree is empty
- *
- * @return true if the number of leafs is 0, false otherwise
- */
- public boolean isEmpty() {
- return numLeafs == 0;
- }
-
- /**
- * Bulk load data into this tree.
- *
- * Create the leaf nodes that each hold (up to) branchFactor data entries. Then use the leaf nodes as data until we
- * can fit all nodes into the root node.
- *
- * @param data
- * the collection of data to store in the tree.
- * @throws IllegalStateException
- * if the tree is already loaded
- */
- public void load(Collection extends T> data) {
- if (root != null)
- throw new IllegalStateException("Tree is already loaded");
- numLeafs = data.size();
- LeafBuilder lb = new LeafBuilder(converter.getDimensions(), branchFactor);
-
- List> leafNodes = new ArrayList>(estimateSize(numLeafs));
- lb.buildLeafs(data, new DataComparators(converter), new LeafNodeFactory(), leafNodes);
-
- height = 1;
- List extends Node> nodes = leafNodes;
- while (nodes.size() > branchFactor) {
- height++;
- List> internalNodes = new ArrayList>(estimateSize(nodes.size()));
- lb.buildLeafs(nodes, new InternalNodeComparators(converter), new InternalNodeFactory(), internalNodes);
- nodes = internalNodes;
- }
- setRoot(nodes);
- }
-
- /**
- * Get the nearest neighbour of the given point
- *
- * @param dc
- * the DistanceCalculator to use.
- * @param filter
- * a NodeFilter that can be used to ignore some leaf nodes.
- * @param maxHits
- * the maximum number of entries to find.
- * @param p
- * the point to find the nearest neighbour to.
- * @return A List of DistanceResult with up to maxHits results. Will return an empty list if this tree is empty.
- */
- public List> nearestNeighbour(DistanceCalculator dc, NodeFilter filter, int maxHits,
- PointND p) {
- if (isEmpty())
- return Collections.emptyList();
- NearestNeighbour nn = new NearestNeighbour(converter, filter, maxHits, root, dc, p);
- return nn.find();
- }
-
- private