]> git.mxchange.org Git - simgear.git/blobdiff - simgear/bucket/newbucket.cxx
canvas::Layout: support for contents margins.
[simgear.git] / simgear / bucket / newbucket.cxx
index beb20d087f47ee9c14c4c0ce0c1ca10df9802aee..fb9a62a17715beed1575ad28ccb46b0c7ec11ffe 100644 (file)
@@ -64,14 +64,17 @@ void SGBucket::make_bad()
     lat = -1000;
 }
 
+#ifndef NO_DEPRECATED_API
+
 // constructor for specified location
 SGBucket::SGBucket(const double dlon, const double dlat) {
     set_bucket(dlon, 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
@@ -99,16 +102,26 @@ 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
+
+void SGBucket::set_bucket(double dlon, double dlat)
+{
+    innerSet(dlon, dlat);
+}
+
+
+void SGBucket::set_bucket(const SGGeod& geod)
+{
+    innerSet(geod.getLongitudeDeg(), geod.getLatitudeDeg());
 }
 
+#endif
+
 // Set the bucket params for the specified lat and lon
-void SGBucket::set_bucket( double dlon, double dlat )
+void SGBucket::innerSet( double dlon, double dlat )
 {
     if ((dlon < -180.0) || (dlon >= 180.0)) {
         SG_LOG(SG_TERRAIN, SG_WARN, "SGBucket::set_bucket: passed longitude:" << dlon);
@@ -134,7 +147,7 @@ void SGBucket::set_bucket( 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
@@ -167,15 +180,10 @@ void SGBucket::set_bucket( 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);
     }
 }
 
-void SGBucket::set_bucket(const SGGeod& geod)
-{
-    set_bucket(geod.getLongitudeDeg(), geod.getLatitudeDeg());
-}
-
 // Build the path name for this bucket
 std::string SGBucket::gen_base_path() const {
     // long int index;
@@ -297,7 +305,10 @@ SGBucket SGBucket::sibling(int dx, int dy) const
     
     double tmp = get_center_lon() + dx * span;
     tmp = SGMiscd::normalizePeriodic(-180.0, 180.0, tmp);
-    return SGBucket(tmp, clat);
+    
+    SGBucket b;
+    b.innerSet(tmp, clat);
+    return b;
 }
 
 std::string SGBucket::gen_index_str() const
@@ -309,6 +320,7 @@ std::string SGBucket::gen_index_str() const
        return (std::string)tmp;
 }
 
+#ifndef NO_DEPRECATED_API
 // find the bucket which is offset by the specified tile units in the
 // X & Y direction.  We need the current lon and lat to resolve
 // ambiguities when going from a wider tile to a narrower one above or
@@ -335,7 +347,7 @@ SGBucket sgBucketOffset( double dlon, double dlat, int dx, int dy ) {
 
     return result;
 }
-
+#endif
 
 // calculate the offset between two buckets
 void sgBucketDiff( const SGBucket& b1, const SGBucket& b2, int *dx, int *dy ) {
@@ -396,11 +408,11 @@ 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)
         {
-            SGBucket b(lon, lat);
+            SGBucket b(SGGeod::fromDeg(lon, lat));
             if (!b.isValid()) {
                 continue;
             }