From: James Turner Date: Mon, 24 Feb 2014 18:03:17 +0000 (+0000) Subject: Fix failing BucketBox test X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ba38688a83029d286ba4a036db6dd90cf1931b53;p=simgear.git Fix failing BucketBox test - improve behaviour of floorWithEpsilon helper in bucket code, and use in more places so that near-integral values are rounded correctly. --- diff --git a/simgear/bucket/newbucket.cxx b/simgear/bucket/newbucket.cxx index 6b7cd82e..d948932b 100644 --- a/simgear/bucket/newbucket.cxx +++ b/simgear/bucket/newbucket.cxx @@ -102,12 +102,7 @@ SGBucket::SGBucket(const long int bindex) { */ static int floorWithEpsilon(double x) { - double diff = x - static_cast(x); - if ( (x >= 0.0) || (fabs(diff) < SG_EPSILON) ) { - return static_cast(x); - } else { - return static_cast(x) - 1; - } + return static_cast(floor(x + SG_EPSILON)); } #ifndef NO_DEPRECATED_API @@ -152,7 +147,7 @@ void SGBucket::innerSet( double dlon, double dlat ) /* We have more than one tile per degree of * longitude, so we need an x offset. */ - x = (int)((dlon - lon) / span); + x = floorWithEpsilon((dlon - lon) / span); } else { /* We have one or more degrees per tile, * so we need to find the base longitude @@ -185,7 +180,7 @@ void SGBucket::innerSet( double dlon, double dlat ) /* Latitude base and offset are easier, as * tiles always are 1/8 degree of latitude wide. */ - y = (int)((dlat - lat) * 8); + y = floorWithEpsilon((dlat - lat) * 8); } }