summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2021-01-08 09:28:20 +0000
committerArne Juul <arnej@verizonmedia.com>2021-01-08 10:56:14 +0000
commit63824702076b738253dc14281ee11db89e976584 (patch)
tree92d7eaa43783b1ad03ccf1a66b9bbed689a80720
parentcf199f338efafad8c0af7de48094bd3d0037b96a (diff)
define two constants
-rw-r--r--searchlib/src/vespa/searchlib/tensor/distance_functions.h18
1 files changed, 12 insertions, 6 deletions
diff --git a/searchlib/src/vespa/searchlib/tensor/distance_functions.h b/searchlib/src/vespa/searchlib/tensor/distance_functions.h
index bccf8c0bdb6..2557a51e0d7 100644
--- a/searchlib/src/vespa/searchlib/tensor/distance_functions.h
+++ b/searchlib/src/vespa/searchlib/tensor/distance_functions.h
@@ -145,6 +145,11 @@ public:
template <typename FloatType>
class GeoDegreesDistance : public DistanceFunction {
public:
+ // in km, as defined by IUGG, see:
+ // https://en.wikipedia.org/wiki/Earth_radius#Mean_radius
+ static constexpr double earth_mean_radius = 6371.0088;
+ static constexpr double degrees_to_radians = M_PI / 180.0;
+
GeoDegreesDistance() {}
// haversine function:
static double hav(double angle) {
@@ -157,10 +162,10 @@ public:
assert(2 == lhs_vector.size());
assert(2 == rhs_vector.size());
// convert to radians:
- double lat_A = lhs_vector[0] * M_PI / 180.0;
- double lat_B = rhs_vector[0] * M_PI / 180.0;
- double lon_A = lhs_vector[1] * M_PI / 180.0;
- double lon_B = rhs_vector[1] * M_PI / 180.0;
+ double lat_A = lhs_vector[0] * degrees_to_radians;
+ double lat_B = rhs_vector[0] * degrees_to_radians;
+ double lon_A = lhs_vector[1] * degrees_to_radians;
+ double lon_B = rhs_vector[1] * degrees_to_radians;
double lat_diff = lat_A - lat_B;
double lon_diff = lon_A - lon_B;
@@ -174,14 +179,15 @@ public:
return hav_central_angle;
}
double convert_threshold(double threshold) const override {
- double half_angle = threshold / (2 * 6371.0088);
+ double half_angle = threshold / (2 * earth_mean_radius);
double rt_hav = sin(half_angle);
return rt_hav * rt_hav;
}
double to_rawscore(double distance) const override {
double hav_diff = sqrt(distance);
// distance in kilometers:
- double d = 2 * asin(hav_diff) * 6371.0088; // Earth mean radius
+ double d = 2 * asin(hav_diff) * earth_mean_radius;
+ // km to rawscore:
return 1.0 / (1.0 + d);
}
double calc_with_limit(const vespalib::eval::TypedCells& lhs,