]> git.mxchange.org Git - simgear.git/blobdiff - simgear/bucket/newbucket.cxx
Fix missing include in simgear/misc/strutils_test.cxx
[simgear.git] / simgear / bucket / newbucket.cxx
index d948932b7869e9867322e738442cb950f41d665b..97b09490208aaa4f4df4ffd9f3313e6f540a10b2 100644 (file)
@@ -286,6 +286,54 @@ double SGBucket::get_height_m() const {
     return SG_BUCKET_SPAN * degree_height;
 }
 
+unsigned int SGBucket::siblings( int dx, int dy, std::vector<SGBucket>& buckets ) const 
+{
+    if (!isValid()) {
+        SG_LOG(SG_TERRAIN, SG_WARN, "SGBucket::sibling: requesting sibling of invalid bucket");
+        return 0;
+    }
+    
+    double src_span = sg_bucket_span( get_center_lat() );
+   
+    double clat = get_center_lat() + dy * SG_BUCKET_SPAN;
+    // return invalid here instead of clipping, so callers can discard
+    // invalid buckets without having to check if it's an existing one
+    if ((clat < -90.0) || (clat > 90.0)) {
+        return 0;
+    }
+    
+    // find the lon span for the new latitude
+    double trg_span = sg_bucket_span( clat );
+    
+    // if target span < src_span, return multiple buckets...
+    if ( trg_span < src_span ) {
+        // calc center longitude of westernmost sibling
+        double start_lon = get_center_lat() - src_span/2 + trg_span/2;
+        
+        unsigned int num_buckets = src_span/trg_span;
+        for ( unsigned int x = 0; x < num_buckets; x++ ) {
+            double tmp = start_lon + x * trg_span;
+            tmp = SGMiscd::normalizePeriodic(-180.0, 180.0, tmp);
+            
+            SGBucket b;
+            b.innerSet(tmp, clat);
+            
+            buckets.push_back( b );
+        }
+    } else {
+        // just return the single sibling
+        double tmp = get_center_lon() + dx * trg_span;
+        tmp = SGMiscd::normalizePeriodic(-180.0, 180.0, tmp);
+    
+        SGBucket b;
+        b.innerSet(tmp, clat);
+        
+        buckets.push_back( b );
+    }
+    
+    return buckets.size();
+}
+
 SGBucket SGBucket::sibling(int dx, int dy) const
 {
     if (!isValid()) {
@@ -408,7 +456,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)
         {