18 using System.Diagnostics;
19 using Lucene.Net.Index;
20 using Lucene.Net.Search;
21 using Lucene.Net.Search.Function;
22 using Lucene.Net.Spatial.Util;
23 using Spatial4n.Core.Distance;
24 using Spatial4n.Core.Shapes;
25 using Spatial4n.Core.Shapes.Impl;
27 namespace Lucene.Net.Spatial.Vector
35 private readonly Point from;
39 this.strategy = strategy;
47 private readonly
double[] ptX, ptY;
48 private readonly
IBits validX, validY;
50 private readonly Point from;
51 private readonly DistanceCalculator calculator;
52 private readonly
double nullValue;
56 this.enclosingInstance = enclosingInstance;
63 from = enclosingInstance.from;
64 calculator = enclosingInstance.strategy.GetSpatialContext().GetDistCalc();
65 nullValue = (enclosingInstance.strategy.GetSpatialContext().IsGeo() ? 180 :
double.MaxValue);
68 public override float FloatVal(
int doc)
70 return (
float)DoubleVal(doc);
73 public override double DoubleVal(
int doc)
78 Debug.Assert(validY.Get(doc));
79 return calculator.Distance(from, ptX[doc], ptY[doc]);
84 public override string ToString(
int doc)
86 return enclosingInstance.Description() +
"=" + FloatVal(doc);
95 public override string Description()
97 return "DistanceValueSource(" + strategy +
", " + from +
")";
100 public override bool Equals(
object o)
102 if (
this == o)
return true;
105 if (that == null)
return false;
107 if (!from.Equals(that.from))
return false;
108 if (!strategy.Equals(that.strategy))
return false;
113 public override int GetHashCode()