diff options
author | Mathias Stearn <mathias@10gen.com> | 2010-08-16 20:15:31 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2010-08-24 14:06:47 -0400 |
commit | 4e234c4959e379e2b1ad43745a7a98df32a2b17b (patch) | |
tree | cfd553b5eeff824305e2fd384a840d8699463139 /db | |
parent | 54572e15b6c8f0484932da032ff9a3b1db8a9a7d (diff) | |
download | mongo-4e234c4959e379e2b1ad43745a7a98df32a2b17b.tar.gz |
$centerSphere test and fixes to make it pass
Diffstat (limited to 'db')
-rw-r--r-- | db/geo/2d.cpp | 28 | ||||
-rw-r--r-- | db/geo/core.h | 6 |
2 files changed, 31 insertions, 3 deletions
diff --git a/db/geo/2d.cpp b/db/geo/2d.cpp index 4e0d3aa3e5f..c8f8566a9c8 100644 --- a/db/geo/2d.cpp +++ b/db/geo/2d.cpp @@ -33,6 +33,7 @@ namespace mongo { #if 0 # define GEODEBUG(x) cout << x << endl; +# define GEODEBUGPRINT(x) PRINT(x) inline void PREFIXDEBUG(GeoHash prefix, const GeoConvert* g){ if (!prefix.constrains()) { cout << "\t empty prefix" << endl; @@ -52,6 +53,7 @@ namespace mongo { } #else # define GEODEBUG(x) +# define GEODEBUGPRINT(x) # define PREFIXDEBUG(x, y) #endif @@ -599,6 +601,22 @@ namespace mongo { assert( dist > 2469 && dist < 2470 ); } + { + Point BNA (-86.67, 36.12); + Point LAX (-118.40, 33.94); + Point JFK (-73.77694444, 40.63861111 ); + assert( spheredist_deg(BNA, BNA) < 1e-6); + assert( spheredist_deg(LAX, LAX) < 1e-6); + assert( spheredist_deg(JFK, JFK) < 1e-6); + + Point zero (0, 0); + Point antizero (0,-180); + + // these were known to cause NaN + assert( spheredist_deg(zero, zero) < 1e-6); + assert( fabs(M_PI-spheredist_deg(zero, antizero)) < 1e-6); + assert( fabs(M_PI-spheredist_deg(antizero, zero)) < 1e-6); + } } } } geoUnitTest; @@ -1148,8 +1166,12 @@ namespace mongo { uassert(13439, "Spherical MaxDistance > PI. Are you sure you are using radians?", _maxDistance < (M_PI*1.05)); _type = GEO_SPHERE; - _xScanDistance = rad2deg(_maxDistance); - _yScanDistance = rad2deg(_maxDistance) / cos(_startPt._y * (M_PI/180)); + _xScanDistance = rad2deg(_maxDistance) / cos(_startPt._y * (M_PI/180)); + _yScanDistance = rad2deg(_maxDistance); + + GEODEBUGPRINT(_maxDistance); + GEODEBUGPRINT(_xScanDistance); + GEODEBUGPRINT(_yScanDistance); } else { uassert(13438, "invalid $center query type: " + type, false); } @@ -1273,7 +1295,7 @@ namespace mongo { d = _g->distance( _start , h ); break; case GEO_SPHERE: - d = _g->distance( _start , h ); + d = spheredist_deg(_startPt, Point(_g, h)); break; } diff --git a/db/geo/core.h b/db/geo/core.h index 6d3c037f588..e0e39c13b1c 100644 --- a/db/geo/core.h +++ b/db/geo/core.h @@ -415,6 +415,12 @@ namespace mongo { (cos_y1*cos_x1 * cos_y2*cos_x2) + (cos_y1*sin_x1 * cos_y2*sin_x2) + (sin_y1 * sin_y2); + + if (cross_prod >= 1 || cross_prod <= -1){ + // fun with floats + assert( fabs(cross_prod)-1 < 1e-6 ); + return cross_prod > 0 ? 0 : M_PI; + } return acos(cross_prod); } |