Permalink
Browse files

LUCENE-4375 Fix use of BBoxWithin BBoxIntersects and IsWithin

+ dotnetifying all getters/setters in SpatialArgs .NET

git-svn-id: https://svn.apache.org/repos/asf/lucene.net/trunk@1388489 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 68b970f commit 7058cbcdba5f10ca05692a1362c6b73e5867cc2c @synhershko synhershko committed Sep 21, 2012
@@ -93,7 +93,7 @@ private AbstractField DoubleField(string field, double value)
public override ValueSource MakeValueSource(SpatialArgs args)
{
- return new BBoxSimilarityValueSource(this, new AreaSimilarity(args.GetShape().GetBoundingBox(), queryPower, targetPower));
+ return new BBoxSimilarityValueSource(this, new AreaSimilarity(args.Shape.GetBoundingBox(), queryPower, targetPower));
}
public override Query MakeQuery(SpatialArgs args)
@@ -116,7 +116,7 @@ public override Filter MakeFilter(SpatialArgs args)
private Query MakeSpatialQuery(SpatialArgs args)
{
- Rectangle bbox = args.GetShape().GetBoundingBox();
+ Rectangle bbox = args.Shape.GetBoundingBox();
Query spatial = null;
// Useful for understanding Relations:
@@ -168,7 +168,7 @@ public ShapeFieldCacheProvider<Point> GetCacheProvider()
public ValueSource MakeValueSource(SpatialArgs args, DistanceCalculator calc)
{
var p = (PointPrefixTreeFieldCacheProvider)GetCacheProvider();
- Point point = args.GetShape().GetCenter();
+ Point point = args.Shape.GetCenter();
return new ShapeFieldCacheDistanceValueSource(point, calc, p);
}
@@ -44,10 +44,10 @@ public void SetPrefixGridScanLevel(int prefixGridScanLevel)
public override Filter MakeFilter(SpatialArgs args)
{
var op = args.Operation;
- if (!SpatialOperation.Is(op, SpatialOperation.IsWithin, SpatialOperation.Intersects, SpatialOperation.BBoxWithin, SpatialOperation.BBoxIntersects))
+ if (op != SpatialOperation.Intersects)
throw new UnsupportedSpatialOperation(op);
- Shape shape = args.GetShape();
+ Shape shape = args.Shape;
int detailLevel = grid.GetLevelForDistance(args.ResolveDistErr(ctx, distErrPct));
@@ -39,12 +39,10 @@ public TermQueryPrefixTreeStrategy(SpatialPrefixTree grid, string fieldName)
public override Filter MakeFilter(SpatialArgs args)
{
SpatialOperation op = args.Operation;
- if (
- !SpatialOperation.Is(op, SpatialOperation.IsWithin, SpatialOperation.Intersects, SpatialOperation.BBoxWithin,
- SpatialOperation.BBoxIntersects))
+ if (op != SpatialOperation.Intersects)
throw new UnsupportedSpatialOperation(op);
- Shape shape = args.GetShape();
+ Shape shape = args.Shape;
int detailLevel = grid.GetLevelForDistance(args.ResolveDistErr(ctx, distErrPct));
var cells = grid.GetNodes(shape, detailLevel, false);
var filter = new TermsFilter();
@@ -40,14 +40,13 @@ public class SpatialArgs
public static readonly double DEFAULT_DISTERRPCT = 0.025d;
public SpatialOperation Operation { get; set; }
- private Shape shape;
- public SpatialArgs(SpatialOperation operation, Shape shape)
+ public SpatialArgs(SpatialOperation operation, Shape shape)
{
if (operation == null || shape == null)
throw new ArgumentException("operation and shape are required");
this.Operation = operation;
- this.shape = shape;
+ this.Shape = shape;
}
/// <summary>
@@ -90,15 +89,15 @@ public double ResolveDistErr(SpatialContext ctx, double defaultDistErrPct)
if (DistErr != null)
return DistErr.Value;
double? distErrPct = (this.distErrPct ?? defaultDistErrPct);
- return CalcDistanceFromErrPct(shape, distErrPct.Value, ctx);
+ return CalcDistanceFromErrPct(Shape, distErrPct.Value, ctx);
}
/// <summary>
/// Check if the arguments make sense -- throw an exception if not
/// </summary>
public void Validate()
{
- if (Operation.IsTargetNeedsArea() && !shape.HasArea())
+ if (Operation.IsTargetNeedsArea() && !Shape.HasArea())
{
throw new ArgumentException(Operation + " only supports geometry with area");
}
@@ -113,21 +112,7 @@ public override String ToString()
// Getters & Setters
//------------------------------------------------
- /// <summary>
- /// Considers {@link SpatialOperation#BBoxWithin} in returning the shape.
- /// </summary>
- /// <returns></returns>
- public Shape GetShape()
- {
- if (shape != null && (Operation == SpatialOperation.BBoxWithin || Operation == SpatialOperation.BBoxIntersects))
- return shape.GetBoundingBox();
- return shape;
- }
-
- public void SetShape(Shape shape)
- {
- this.shape = shape;
- }
+ public Shape Shape { get; set; }
/// <summary>
/// A measure of acceptable error of the shape as a fraction. This effectively
@@ -37,7 +37,7 @@ public static String WriteSpatialArgs(SpatialArgs args)
var str = new StringBuilder();
str.Append(args.Operation.GetName());
str.Append('(');
- str.Append(args.GetShape());
+ str.Append(args.Shape);
if (args.DistErrPct != null)
str.Append(" distErrPct=").Append(String.Format("{0:0.00}%", args.DistErrPct*100d));
if (args.DistErr != null)
@@ -28,8 +28,17 @@ public class SpatialOperation
private static readonly IList<SpatialOperation> list = new List<SpatialOperation>();
// Geometry Operations
+
+ /// <summary>
+ /// Bounding box of the *indexed* shape.
+ /// </summary>
public static readonly SpatialOperation BBoxIntersects = new SpatialOperation("BBoxIntersects", true, false, false);
+
+ /// <summary>
+ /// Bounding box of the *indexed* shape.
+ /// </summary>
public static readonly SpatialOperation BBoxWithin = new SpatialOperation("BBoxWithin", true, false, false);
+
public static readonly SpatialOperation Contains = new SpatialOperation("Contains", true, true, false);
public static readonly SpatialOperation Intersects = new SpatialOperation("Intersects", true, false, false);
public static readonly SpatialOperation IsEqualTo = new SpatialOperation("IsEqualTo", false, false, false);
@@ -89,14 +89,14 @@ public override AbstractField[] CreateIndexableFields(Shape shape)
public override ValueSource MakeValueSource(SpatialArgs args)
{
- Point p = args.GetShape().GetCenter();
+ Point p = args.Shape.GetCenter();
return new DistanceValueSource(this, p, ctx.GetDistCalc());
}
public override Query MakeQuery(SpatialArgs args)
{
// For starters, just limit the bbox
- var shape = args.GetShape();
+ var shape = args.Shape;
if (!(shape is Rectangle || shape is Circle))
throw new InvalidShapeException("Only Rectangles and Circles are currently supported, found ["
+ shape.GetType().Name + "]");//TODO
@@ -123,7 +123,7 @@ public override Query MakeQuery(SpatialArgs args)
SpatialOperation.IsWithin))
{
spatial = MakeWithin(bbox);
- var circle = args.GetShape() as Circle;
+ var circle = args.Shape as Circle;
if (circle != null)
{
// Make the ValueSource
@@ -163,7 +163,7 @@ public override Query MakeQuery(SpatialArgs args)
public override Filter MakeFilter(SpatialArgs args)
{
- var circle = args.GetShape() as Circle;
+ var circle = args.Shape as Circle;
if (circle != null)
{
if (SpatialOperation.Is(args.Operation,
@@ -0,0 +1,7 @@
+[San Francisco] G5391959 @ Intersects(-122.524918 37.674973 -122.360123 37.817108)
+[Wellington] G2179537 @ Intersects(174.711456 -41.360779 174.854279 -41.213837)
+[Barcelona] G6544100 G3128760 @ Intersects(2.127228 41.333313 2.226105 41.408844)
+
+
+
+
@@ -1,7 +0,0 @@
-[San Francisco] G5391959 @ IsWithin(-122.524918 37.674973 -122.360123 37.817108)
-[Wellington] G2179537 @ IsWithin(174.711456 -41.360779 174.854279 -41.213837)
-[Barcelona] G6544100 G3128760 @ IsWithin(2.127228 41.333313 2.226105 41.408844)
-
-
-
-
@@ -44,7 +44,7 @@ public void testStatesBBox()
{
getAddAndVerifyIndexedDocuments(DATA_STATES_BBOX);
- executeQueries(SpatialMatchConcern.FILTER, QTEST_States_IsWithin_BBox);
+ executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_Intersects_BBox);
executeQueries(SpatialMatchConcern.FILTER, QTEST_States_Intersects_BBox);
}
@@ -38,7 +38,7 @@ public abstract class StrategyTestCase : SpatialTestCase
public static readonly String DATA_COUNTRIES_BBOX = "countries-bbox.txt";
public static readonly String DATA_WORLD_CITIES_POINTS = "world-cities-points.txt";
- public static readonly String QTEST_States_IsWithin_BBox = "states-IsWithin-BBox.txt";
+ public static readonly String QTEST_Cities_Intersects_BBox = "cities-Intersects-BBox.txt";
public static readonly String QTEST_States_Intersects_BBox = "states-Intersects-BBox.txt";
public static readonly String QTEST_Cities_IsWithin_BBox = "cities-IsWithin-BBox.txt";
public static readonly String QTEST_Simple_Queries_BBox = "simple-Queries-BBox.txt";

0 comments on commit 7058cbc

Please sign in to comment.