LUCENE-2184: previous commit broke this

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@933908 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Grant Ingersoll 2010-04-14 10:41:36 +00:00
parent 8703572fc2
commit ddae6f06db
2 changed files with 15 additions and 9 deletions

View File

@ -69,7 +69,7 @@ public class CartesianPolyFilterBuilder {
double longUpperRight = upperRight.getLng(); double longUpperRight = upperRight.getLng();
double longLowerLeft = lowerLeft.getLng(); double longLowerLeft = lowerLeft.getLng();
CartesianTierPlotter ctp = new CartesianTierPlotter( miles, projector, tierPrefix ); CartesianTierPlotter ctp = new CartesianTierPlotter( miles, projector, tierPrefix, minTier, maxTier );
Shape shape = new Shape(ctp.getTierLevelId()); Shape shape = new Shape(ctp.getTierLevelId());
if (longUpperRight < longLowerLeft) { // Box cross the 180 meridian if (longUpperRight < longLowerLeft) { // Box cross the 180 meridian

View File

@ -26,6 +26,8 @@ import org.apache.lucene.spatial.geometry.DistanceUnits;
*/ */
public class CartesianTierPlotter { public class CartesianTierPlotter {
public static final String DEFALT_FIELD_PREFIX = "_tier_"; public static final String DEFALT_FIELD_PREFIX = "_tier_";
public static final int DEFALT_MIN_TIER = 0;
public static final int DEFALT_MAX_TIER = 15;
final int tierLevel; final int tierLevel;
int tierLength; int tierLength;
@ -49,8 +51,8 @@ public class CartesianTierPlotter {
} }
public CartesianTierPlotter(double radius, IProjector projector, public CartesianTierPlotter(double radius, IProjector projector,
String fieldPrefix) { String fieldPrefix, int minTier, int maxTier) {
this(CartesianTierPlotter.bestFit(radius), projector, fieldPrefix); this(CartesianTierPlotter.bestFit(radius, minTier, maxTier), projector, fieldPrefix);
} }
private void setTierLength (){ private void setTierLength (){
@ -143,18 +145,22 @@ public class CartesianTierPlotter {
* in accurate * in accurate
*/ */
static public int bestFit(double range) { static public int bestFit(double range) {
return bestFit(range, DistanceUnits.MILES); return bestFit(range, DEFALT_MIN_TIER, DEFALT_MAX_TIER, DistanceUnits.MILES);
} }
static public int bestFit(double range, DistanceUnits distanceUnit) { static public int bestFit(double range, int minTier, int maxTier) {
return bestFit(range, minTier, maxTier, DistanceUnits.MILES);
}
static public int bestFit(double range, int minTier, int maxTier, DistanceUnits distanceUnit) {
double times = distanceUnit.earthCircumference() / (2.0d * range); double times = distanceUnit.earthCircumference() / (2.0d * range);
int bestFit = (int) Math.ceil(log2(times)); int bestFit = (int) Math.ceil(log2(times));
if (bestFit > 15) { if (bestFit > maxTier) {
// 15 is the granularity of about 1 mile return maxTier;
// finer granularity isn't accurate with standard java math } else if (bestFit < minTier) {
return 15; return minTier;
} }
return bestFit; return bestFit;
} }