19 using Lucene.Net.Index;
20 using Lucene.Net.Search.Function;
21 using Spatial4n.Core.Context;
22 using Spatial4n.Core.Distance;
23 using Spatial4n.Core.Shapes;
25 namespace Lucene.Net.Spatial.Util
32 private readonly ShapeFieldCacheProvider<Point> provider;
33 private readonly SpatialContext ctx;
34 private readonly Point from;
40 this.provider = provider;
46 private readonly ShapeFieldCache<Point> cache;
47 private readonly Point from;
48 private readonly DistanceCalculator calculator;
49 private readonly
double nullValue;
53 cache = enclosingInstance.provider.GetCache(reader);
54 this.enclosingInstance = enclosingInstance;
56 from = enclosingInstance.from;
57 calculator = enclosingInstance.ctx.GetDistCalc();
58 nullValue = (enclosingInstance.ctx.IsGeo() ? 180 :
double.MaxValue);
61 public override float FloatVal(
int doc)
63 return (
float)DoubleVal(doc);
66 public override double DoubleVal(
int doc)
68 var vals = cache.GetShapes(doc);
71 double v = calculator.Distance(from, vals[0]);
72 for (
int i = 1; i < vals.Count; i++)
74 v = Math.Min(v, calculator.Distance(from, vals[i]));
81 public override string ToString(
int doc)
83 return enclosingInstance.Description() +
"=" + FloatVal(doc);
92 public override string Description()
94 return GetType().Name +
"(" + provider +
", " + from +
")";
97 public override bool Equals(
object o)
99 if (
this == o)
return true;
103 if (that == null)
return false;
104 if (!ctx.Equals(that.ctx))
return false;
105 if (!from.Equals(that.from))
return false;
106 if (!provider.Equals(that.provider))
return false;
111 public override int GetHashCode()