]> git.mxchange.org Git - simgear.git/blobdiff - simgear/bucket/newbucket.cxx
Fix #1783: repeated error message on console
[simgear.git] / simgear / bucket / newbucket.cxx
index 5d2f7a6c8a0d1cf0ab331788f78ed213a9ef684f..fb9a62a17715beed1575ad28ccb46b0c7ec11ffe 100644 (file)
@@ -73,8 +73,8 @@ SGBucket::SGBucket(const double dlon, const double dlat) {
 #endif
 
 SGBucket::SGBucket(const SGGeod& geod) {
-    set_bucket(geod.getLongitudeDeg(),
-                   geod.getLatitudeDeg());
+    innerSet(geod.getLongitudeDeg(),
+             geod.getLatitudeDeg());
 }
 
 // Parse a unique scenery tile index and find the lon, lat, x, and y
@@ -102,12 +102,7 @@ SGBucket::SGBucket(const long int bindex) {
  */
 static int floorWithEpsilon(double x)
 {
-    double diff = x - static_cast<int>(x);
-    if ( (x >= 0.0) || (fabs(diff) < SG_EPSILON) ) {
-        return static_cast<int>(x);
-    } else {
-        return static_cast<int>(x) - 1;
-    }
+    return static_cast<int>(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);
     }
 }
 
@@ -413,7 +408,7 @@ void sgBucketDiff( const SGBucket& b1, const SGBucket& b2, int *dx, int *dy ) {
 void sgGetBuckets( const SGGeod& min, const SGGeod& max, std::vector<SGBucket>& list ) {
     double lon, lat, span;
 
-    for (lat = min.getLatitudeDeg(); lat <= max.getLatitudeDeg(); lat += SG_BUCKET_SPAN) {
+    for (lat = min.getLatitudeDeg(); lat < max.getLatitudeDeg()+SG_BUCKET_SPAN; lat += SG_BUCKET_SPAN) {
         span = sg_bucket_span( lat );
         for (lon = min.getLongitudeDeg(); lon <= max.getLongitudeDeg(); lon += span)
         {