diff options
author | Eliot Horowitz <eliot@10gen.com> | 2010-07-19 10:30:54 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-07-19 10:30:54 -0400 |
commit | 0b72ae6d718785ebcfa983fb281272fcd2e8f733 (patch) | |
tree | ba88eac818af430c55798e90e74a99ce47c37990 /db/geo | |
parent | 970ef45329bcfc2fa8ebd8b00ef0dfd8bd00244c (diff) | |
download | mongo-0b72ae6d718785ebcfa983fb281272fcd2e8f733.tar.gz |
earth radius constants and simple test SERVER-1342
Diffstat (limited to 'db/geo')
-rw-r--r-- | db/geo/2d.cpp | 14 | ||||
-rw-r--r-- | db/geo/core.h | 6 |
2 files changed, 19 insertions, 1 deletions
diff --git a/db/geo/2d.cpp b/db/geo/2d.cpp index 84987e37c3c..51359d4dbfd 100644 --- a/db/geo/2d.cpp +++ b/db/geo/2d.cpp @@ -34,6 +34,10 @@ namespace mongo { + double EARTH_RADIUS_KM = 6371; + double EARTH_RADIUS_MILES = EARTH_RADIUS_KM * 0.621371192; + + GeoBitSets geoBitSets; const string GEO2DNAME = "2d"; @@ -554,7 +558,7 @@ namespace mongo { { Point BNA (-1.5127, 0.6304); Point LAX (-2.0665, 0.5924); - + double dist1 = spheredist_rad(BNA, LAX); double dist2 = spheredist_rad(LAX, BNA); @@ -562,6 +566,14 @@ namespace mongo { assert( 0.45305 <= dist1 && dist1 <= 0.45307 ); assert( 0.45305 <= dist2 && dist2 <= 0.45307 ); } + { + Point JFK (-73.77694444, 40.63861111 ); + Point LAX (-118.40, 33.94); + + double dist = spheredist_deg(JFK, LAX) * EARTH_RADIUS_MILES; + assert( dist > 2469 && dist < 2470 ); + } + } } } geoUnitTest; diff --git a/db/geo/core.h b/db/geo/core.h index edb5ea7f61b..dff174907a3 100644 --- a/db/geo/core.h +++ b/db/geo/core.h @@ -387,7 +387,12 @@ namespace mongo { double _y; }; + + extern double EARTH_RADIUS_KM; + extern double EARTH_RADIUS_MILES; + // WARNING: _x and _y MUST be longitude and latitude in that order + // note: multiply by earth radius for distance inline double spheredist_rad( const Point& p1, const Point& p2 ) { // this uses the n-vector formula: http://en.wikipedia.org/wiki/N-vector // If you try to match the code to the formula, note that I inline the cross-product. @@ -413,4 +418,5 @@ namespace mongo { Point( p2._x * (M_PI/180), p2._y * (M_PI/180)) ); } + } |