Index: contrib/spatial/src/java/org/apache/lucene/spatial/tier/projections/IProjector.java =================================================================== --- contrib/spatial/src/java/org/apache/lucene/spatial/tier/projections/IProjector.java (révision 819480) +++ contrib/spatial/src/java/org/apache/lucene/spatial/tier/projections/IProjector.java (copie de travail) @@ -25,4 +25,5 @@ public interface IProjector { public String coordsAsString(double latitude, double longitude); public double[] coords(double latitude, double longitude); + public double[] range(); } \ No newline at end of file Index: contrib/spatial/src/java/org/apache/lucene/spatial/tier/projections/SinusoidalProjector.java =================================================================== --- contrib/spatial/src/java/org/apache/lucene/spatial/tier/projections/SinusoidalProjector.java (révision 819480) +++ contrib/spatial/src/java/org/apache/lucene/spatial/tier/projections/SinusoidalProjector.java (copie de travail) @@ -14,9 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.lucene.spatial.tier.projections; +import java.lang.Math; + /** * Based on Sinusoidal Projections * Project a latitude / longitude on a 2D cartesian map @@ -26,7 +27,8 @@ * release. */ public class SinusoidalProjector implements IProjector { - + public static final double LATITUDE_RANGE= java.lang.Math.PI; + public static final double LONGITUDE_RANGE = 2* java.lang.Math.PI; public String coordsAsString(double latitude, double longitude) { return null; @@ -41,4 +43,9 @@ } + public double[] range() { + double ranges[]= { LATITUDE_RANGE, LONGITUDE_RANGE}; + return ranges; + } + } Index: contrib/spatial/src/java/org/apache/lucene/spatial/tier/projections/CartesianTierPlotter.java =================================================================== --- contrib/spatial/src/java/org/apache/lucene/spatial/tier/projections/CartesianTierPlotter.java (révision 819480) +++ contrib/spatial/src/java/org/apache/lucene/spatial/tier/projections/CartesianTierPlotter.java (copie de travail) @@ -24,6 +24,7 @@ */ public class CartesianTierPlotter { public static final String DEFALT_FIELD_PREFIX = "_tier_"; + public static final double EARTH_CIRC_MILES= 28892.0d; final int tierLevel; int tierLength; @@ -31,7 +32,6 @@ int tierVerticalPosDivider; final IProjector projector; final String fieldPrefix; - Double idd = new Double(180); public CartesianTierPlotter (int tierLevel, IProjector projector, String fieldPrefix) { @@ -88,22 +88,19 @@ public double getTierBoxId (double latitude, double longitude) { double[] coords = projector.coords(latitude, longitude); + double[] ranges= projector.range(); - double id = getBoxId(coords[0]) + (getBoxId(coords[1]) / tierVerticalPosDivider); + double id = getBoxCoord(coords[0], ranges[0]) + (getBoxCoord(coords[1], ranges[1]) / tierVerticalPosDivider); return id ; } - private double getBoxId (double coord){ + private double getBoxCoord (double coord, double range){ - return Math.floor(coord / (idd / this.tierLength)); + return Math.floor(coord * (this.tierLength / range)); } - @SuppressWarnings("unused") - private double getBoxId (double coord, int tierLen){ - return Math.floor(coord / (idd / tierLen) ); - } /** * get the string name representing current tier * _localTier<tiedId> @@ -133,23 +130,17 @@ * Distances less than a mile return 15, finer granularity is * in accurate */ - public int bestFit(double miles){ - - //28,892 a rough circumference of the earth - int circ = 28892; - - double r = miles / 2.0; - - double corner = r - Math.sqrt(Math.pow(r, 2) / 2.0d); - double times = circ / corner; - int bestFit = (int)Math.ceil(log2(times)) + 1; - - if (bestFit > 15) { - // 15 is the granularity of about 1 mile - // finer granularity isn't accurate with standard java math - return 15; - } - return bestFit; + public int bestFit(double range){ + double times= EARTH_CIRC_MILES / (2.0d * range); + + int bestFit = (int)Math.ceil(log2(times)); + + if (bestFit > 15) { + // 15 is the granularity of about 1 mile + // finer granularity isn't accurate with standard java math + return 15; + } + return bestFit; } /**