diff --git a/vtm/src/org/oscim/utils/QuadTree.java b/vtm/src/org/oscim/utils/QuadTree.java index 31726e28..7002ca50 100644 --- a/vtm/src/org/oscim/utils/QuadTree.java +++ b/vtm/src/org/oscim/utils/QuadTree.java @@ -9,14 +9,19 @@ import org.oscim.utils.quadtree.BoxTree.BoxItem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * Quad-tree with fixed extents. + * This implementation uses int bounding-boxes internally, + * so items extents should be greater than 1. FIXME tests this case + */ public class QuadTree extends BoxTree, T> implements SpatialIndex { + static final Logger log = LoggerFactory.getLogger(QuadTree.class); + public QuadTree(int extents, int maxDepth) { super(extents, maxDepth); } - static final Logger log = LoggerFactory.getLogger(QuadTree.class); - final Pool> boxPool = new Pool>() { @Override protected BoxItem createItem() { @@ -67,10 +72,10 @@ public class QuadTree extends BoxTree, T> implements SpatialIndex< } @Override - public int search(Box bbox, SearchCb cb, Object context) { + public boolean search(Box bbox, SearchCb cb, Object context) { BoxItem box = getBox(bbox); - search(box, cb, context); + boolean finished = search(box, cb, context); boxPool.release(box); - return 0; + return finished; } } diff --git a/vtm/src/org/oscim/utils/RTree.java b/vtm/src/org/oscim/utils/RTree.java index 38b61ab6..b7b18105 100644 --- a/vtm/src/org/oscim/utils/RTree.java +++ b/vtm/src/org/oscim/utils/RTree.java @@ -316,32 +316,24 @@ public class RTree implements SpatialIndex, Iterable { * @param a_context User context to pass as parameter to a_resultCallback * @return Returns the number of entries found */ - public int search(double min[], double max[], SearchCb cb, Object context) { + public boolean search(double min[], double max[], SearchCb cb, Object context) { Rect r = getRect(); r.set(min, max); - /* NOTE: May want to return search result another way, - * perhaps returning the number of found elements here. */ - //int[] foundCount = { 0 }; - //search(mRoot, r, foundCount, cb, context); searchStack(r, cb, context); releaseRect(r); - return 0; //foundCount[0]; + return true; } - public int search(Box bbox, SearchCb cb, Object context) { + public boolean search(Box bbox, SearchCb cb, Object context) { Rect r = getRect(); r.set(bbox); - /* NOTE: May want to return search result another way, - * perhaps returning the number of found elements here. */ - //int[] foundCount = { 0 }; - //search(mRoot, r, foundCount, cb, context); searchStack(r, cb, context); releaseRect(r); - return 0; //foundCount[0]; + return true; } public List search(Box bbox, List results) { @@ -385,7 +377,7 @@ public class RTree implements SpatialIndex, Iterable { /** * Remove all entries from tree. */ - public void removeAll() { + public void clear() { /* Delete all existing nodes */ reset(); diff --git a/vtm/src/org/oscim/utils/SpatialIndex.java b/vtm/src/org/oscim/utils/SpatialIndex.java index b6e74509..fa195441 100644 --- a/vtm/src/org/oscim/utils/SpatialIndex.java +++ b/vtm/src/org/oscim/utils/SpatialIndex.java @@ -6,6 +6,14 @@ import org.oscim.core.Box; public interface SpatialIndex { public interface SearchCb { + /** + * + * TODO should be able to return 'continue', 'stop', + * 'remove-current' + * + * @return false to stop search + */ + boolean call(T item, Object context); } @@ -15,7 +23,9 @@ public interface SpatialIndex { public List search(Box bbox, List results); - public int search(Box bbox, SearchCb cb, Object context); + public boolean search(Box bbox, SearchCb cb, Object context); public int size(); + + public void clear(); }