20 using Spatial4n.Core.Context;
21 using Spatial4n.Core.Exceptions;
22 using Spatial4n.Core.Shapes;
24 namespace Spatial4n.Core.Exceptions
36 namespace Lucene.Net.Spatial.Queries
38 public class SpatialArgs
40 public static readonly
double DEFAULT_DISTERRPCT = 0.025d;
42 public SpatialOperation Operation {
get;
set; }
44 public SpatialArgs(SpatialOperation operation, Shape shape)
46 if (operation == null || shape == null)
47 throw new ArgumentException(
"operation and shape are required");
48 this.Operation = operation;
61 public static double CalcDistanceFromErrPct(Shape shape,
double distErrPct, SpatialContext ctx)
63 if (distErrPct < 0 || distErrPct > 0.5)
65 throw new ArgumentException(
"distErrPct " + distErrPct +
" must be between [0 to 0.5]",
"distErrPct");
67 if (distErrPct == 0 || shape is Point)
71 Rectangle bbox = shape.GetBoundingBox();
74 double diagonalDist = ctx.GetDistCalc().Distance(
75 ctx.MakePoint(bbox.GetMinX(), bbox.GetMinY()), bbox.GetMaxX(), bbox.GetMaxY());
76 return diagonalDist*0.5*distErrPct;
87 public double ResolveDistErr(SpatialContext ctx,
double defaultDistErrPct)
91 double? distErrPct = (this.distErrPct ?? defaultDistErrPct);
92 return CalcDistanceFromErrPct(Shape, distErrPct.Value, ctx);
98 public void Validate()
100 if (Operation.IsTargetNeedsArea() && !Shape.HasArea())
102 throw new ArgumentException(Operation +
" only supports geometry with area");
106 public override String ToString()
108 return SpatialArgsParser.WriteSpatialArgs(
this);
115 public Shape Shape {
get;
set; }
124 public double? DistErrPct
126 get {
return distErrPct; }
130 distErrPct = value.Value;
133 private double? distErrPct;
140 public double? DistErr {
get;
set; }