X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fbucket%2Fnewbucket.cxx;h=97b09490208aaa4f4df4ffd9f3313e6f540a10b2;hb=6672a1212cfccb2a08be21ff5271eae9b6f91b2a;hp=d948932b7869e9867322e738442cb950f41d665b;hpb=ba38688a83029d286ba4a036db6dd90cf1931b53;p=simgear.git diff --git a/simgear/bucket/newbucket.cxx b/simgear/bucket/newbucket.cxx index d948932b..97b09490 100644 --- a/simgear/bucket/newbucket.cxx +++ b/simgear/bucket/newbucket.cxx @@ -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& 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& 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) {