> Try #3. Can someone take a look at this please? Please? Please, > please, please?! > > ============================================================ > > SGBucket::set_bucket(double dlon, double dlat) has some bugs, > especially evident at high latitudes. For example, try this test, > which consists of 3 closely-spaced points: > > SGBucket b1(-179.5, 87.5); > printf("b1: lon = %d, lat = %d\n", b1.get_chunk_lon(), > b1.get_chunk_lat()); > > SGBucket b2(-179.0, 87.5); > printf("b2: lon = %d, lat = %d\n", b2.get_chunk_lon(), > b2.get_chunk_lat()); > > SGBucket b3(-178.5, 87.5); > printf("b3: lon = %d, lat = %d\n", b3.get_chunk_lon(), > b3.get_chunk_lat()); > > The output will be: > > b1: lon = -180, lat = 87 > b2: lon = -176, lat = 87 > b3: lon = -180, lat = 87 > Thanks for pointing this one out. I can confirm this bug and did some investigation on this issue. The bug is in the calculation of the left border of the bucket for negative longitudes where longitudes are close to a full degree of longitude.
Here is the problem: if ( (dlon >= 0) || (fabs(diff) < SG_EPSILON) ) { /******** OUPS This gets executed in the eastern hemisphere (lon >= 0) which is good. But in the western hemisphere for longitudes -1, -2, -3, ... -180 this is ___WRONG___ ********/ lon = (int)( (int)(lon / span) * span); } else { /******* All negative longitudes shall be processed here *********/ // cout << " lon = " << lon // << " tmp = " << (int)((lon-1) / span) << endl; lon = (int)( (int)((lon + 1) / span) * span - span); if ( lon < -180 ) { lon = -180; } } Here is a one line patch to fix this issue. Regards, Torsten Index: newbucket.cxx =================================================================== RCS file: /var/cvs/SimGear-0.3/source/simgear/bucket/newbucket.cxx,v retrieving revision 1.9 diff -u -p -r1.9 newbucket.cxx --- newbucket.cxx 28 May 2007 05:00:28 -0000 1.9 +++ newbucket.cxx 27 Mar 2009 10:17:40 -0000 @@ -106,7 +106,7 @@ void SGBucket::set_bucket( double dlon, } else if ( span <= 1.0 ) { x = (int)((dlon - lon) / span); } else { - if ( (dlon >= 0) || (fabs(diff) < SG_EPSILON) ) { + if ( dlon >= 0 ) { lon = (int)( (int)(lon / span) * span); } else { // cout << " lon = " << lon ------------------------------------------------------------------------------ _______________________________________________ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel