bryan-emmanuel / javageomodel

Automatically exported from code.google.com/p/javageomodel
0 stars 0 forks source link

GeocellManager fails to find points outside highest level tile size #27

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
When searching for a point that is farther away than the top-level tile size, 
the point will never be found. In other words, if I search for a point that is 
farther away from my origin than 1/16 of the world, I will never find that 
point regardless of the distance specified (including 0 or Integer.MAX_VALUE).

I developed a simple patch to address the issue (though it may be possible to 
optimize it)...

Scott

Index: src/main/java/com/beoui/geocell/GeocellManager.java
===================================================================
--- src/main/java/com/beoui/geocell/GeocellManager.java (revision 153)
+++ src/main/java/com/beoui/geocell/GeocellManager.java (working copy)
@@ -367,6 +367,7 @@

        int noDirection [] = {0,0};
        List<Tuple<int[], Double>> sortedEdgesDistances = Arrays.asList(new Tuple<int[], Double>(noDirection, 0d));
+       boolean done = false;

        while(!curGeocells.isEmpty()) {
            closestPossibleNextResultDist = sortedEdgesDistances.get(0).getSecond();
@@ -405,6 +406,8 @@
            Collections.sort(results);
            results = results.subList(0, Math.min(maxResults, results.size()));

+           if (done) break; // Done with search, we've searched everywhere.
+
            sortedEdgesDistances = GeocellUtils.distanceSortedEdges(curGeocells, center);

            if(results.size() == 0 || curGeocells.size() == 4) {
@@ -413,8 +416,13 @@
                        geocells, in which case we should now search the parents of those
                        geocells.*/
                curContainingGeocell = curContainingGeocell.substring(0, Math.max(curContainingGeocell.length() - 1,0));
-               if(curContainingGeocell.length() == 0) {
-                   break;  // Done with search, we've searched everywhere.
+               if (curContainingGeocell.length() == 0) {
+                 // final check - top level tiles
+                 curGeocells.clear();
+                 String[] items = "0123456789abcdef".split("(?!^)");
+                 for (String item : items) curGeocells.add(item);
+                 done = true;
+                 continue;
                }
                List<String> oldCurGeocells = new ArrayList<String>(curGeocells);
                curGeocells.clear();

Original issue reported on code.google.com by sc...@ganyo.com on 14 Jan 2013 at 5:30