From: ehofman Date: Sun, 1 May 2005 08:50:39 +0000 (+0000) Subject: Phil Cazzola: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=dea7b9050dfc4ae3807213400656996fefc7f60d;p=simgear.git Phil Cazzola: This is a minor bug fix for sgBucketDiff(). If you crossed the bucket size boundary, the answer for dx could be wrong. E.g. going from 0:0, 21:7 to 0:7, 21:7 would give you dx = 7 (correct) but going from 0:0, 21:7 to 0:3, 22:0 would give you dx = 6 (instead of 7) Previously it differenced the center longitudes of the buckets. When you cross a boundary, the center point of the larger bucket now lies on the edge of the smaller bucket. The result was a dx with an integer + 1/2 bucket, which rint() was rounding to the nearest even int. This function only seems to be used in TerraGear. --- diff --git a/simgear/bucket/newbucket.cxx b/simgear/bucket/newbucket.cxx index 916485be..e3c34387 100644 --- a/simgear/bucket/newbucket.cxx +++ b/simgear/bucket/newbucket.cxx @@ -271,16 +271,32 @@ void sgBucketDiff( const SGBucket& b1, const SGBucket& b2, int *dx, int *dy ) { #endif // longitude difference - double c1_lon = b1.get_center_lon(); - double c2_lon = b2.get_center_lon(); - double diff_lon = c2_lon - c1_lon; - double span; - if ( sg_bucket_span(c1_lat) <= sg_bucket_span(c2_lat) ) { + double diff_lon=0.0; + double span=0.0; + + SGBucket tmp_bucket; + // To handle crossing the bucket size boundary + // we need to account for different size buckets. + + if ( sg_bucket_span(c1_lat) <= sg_bucket_span(c2_lat) ) + { span = sg_bucket_span(c1_lat); } else { span = sg_bucket_span(c2_lat); } + diff_lon = b2.get_center_lon() - b1.get_center_lon(); + + if (diff_lon <0.0) + { + diff_lon -= b1.get_width()*0.5 + b2.get_width()*0.5 - span; + } + else + { + diff_lon += b1.get_width()*0.5 + b2.get_width()*0.5 - span; + } + + #ifdef HAVE_RINT *dx = (int)rint( diff_lon / span ); #else