diff options
author | Mihai Andrei <mihai.andrei@10gen.com> | 2021-02-10 15:58:17 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-03-02 17:14:09 +0000 |
commit | b33f2292ab02214d5626edcd557b3a9f3c09a183 (patch) | |
tree | bf5bf89aa9314bddf4f61ceb73b98188b3018b43 /src/mongo/db/geo | |
parent | 168d5f983a3165d2271569b1fc0dbb671771a87f (diff) | |
download | mongo-b33f2292ab02214d5626edcd557b3a9f3c09a183.tar.gz |
SERVER-52953 $geoNear does not always match coordinate given to 'near' when maxDistance is set to 0
Diffstat (limited to 'src/mongo/db/geo')
-rw-r--r-- | src/mongo/db/geo/geometry_container.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/mongo/db/geo/geometry_container.cpp b/src/mongo/db/geo/geometry_container.cpp index 5a4c066ee28..3fe86c1c20c 100644 --- a/src/mongo/db/geo/geometry_container.cpp +++ b/src/mongo/db/geo/geometry_container.cpp @@ -1288,7 +1288,15 @@ double GeometryContainer::minDistance(const PointWithCRS& otherPoint) const { double minDistance = -1; if (nullptr != _point) { - minDistance = S2Distance::distanceRad(otherPoint.point, _point->point); + // SERVER-52953: Calculating the distance between identical points can sometimes result + // in a small positive value due to a loss of floating point precision on certain + // platforms. As such, we perform a simple equality check to guarantee that equivalent + // points will always produce a distance of 0. + if (_point->point == otherPoint.point) { + minDistance = 0; + } else { + minDistance = S2Distance::distanceRad(otherPoint.point, _point->point); + } } else if (nullptr != _line) { minDistance = S2Distance::minDistanceRad(otherPoint.point, _line->line); } else if (nullptr != _polygon) { |