X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=simgear%2Fbucket%2Fnewbucket.hxx;h=fe0bbbc4abd305b113723e269a76df7e6796e81f;hb=9447d56332028ea18ccde4712cffd75154064769;hp=b7ad1deb62ff4343c4182332c347499fc757fc09;hpb=b2a4cd488dfcfbf1d02fa41f2dfa5ad39aabb13a;p=simgear.git diff --git a/simgear/bucket/newbucket.hxx b/simgear/bucket/newbucket.hxx index b7ad1deb..fe0bbbc4 100644 --- a/simgear/bucket/newbucket.hxx +++ b/simgear/bucket/newbucket.hxx @@ -15,16 +15,20 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * $Id$ **************************************************************************/ /** \file newbucket.hxx * A class and associated utiltity functions to manage world scenery tiling. + * + * Tile borders are aligned along circles of latitude and longitude. + * All tiles are 1/8 degree of latitude high and their width in degrees + * longitude depends on their latitude, adjusted in such a way that + * all tiles cover about the same amount of area of the earth surface. */ #ifndef _NEWBUCKET_HXX @@ -32,30 +36,14 @@ #include #include +#include -#ifdef SG_HAVE_STD_INCLUDES -# include -# include // sprintf() -#else -# include -# include // sprintf() -#endif - -#include STL_IOSTREAM - -// I don't understand ... or should be included -// already depending on how you defined SG_HAVE_STD_INCLUDES, but I -// can go ahead and add this -- CLO -#ifdef __MWERKS__ -SG_USING_STD(sprintf); -SG_USING_STD(fabs); -#endif - -#include STL_STRING - -SG_USING_STD(string); -SG_USING_STD(ostream); +#include +#include +#include +#include +// #define NO_DEPRECATED_API /** * standard size of a bucket in degrees (1/8 of a degree) @@ -71,9 +59,7 @@ SG_USING_STD(ostream); // return the horizontal tile span factor based on latitude static double sg_bucket_span( double l ) { if ( l >= 89.0 ) { - return 360.0; - } else if ( l >= 88.0 ) { - return 8.0; + return 12.0; } else if ( l >= 86.0 ) { return 4.0; } else if ( l >= 83.0 ) { @@ -94,12 +80,10 @@ static double sg_bucket_span( double l ) { return 1.0; } else if ( l >= -86.0 ) { return 2.0; - } else if ( l >= -88.0 ) { - return 4.0; } else if ( l >= -89.0 ) { - return 8.0; + return 4.0; } else { - return 360.0; + return 12.0; } } @@ -114,43 +98,54 @@ static double sg_bucket_span( double l ) { class SGBucket { private: - double cx, cy; // centerpoint (lon, lat) in degrees of bucket short lon; // longitude index (-180 to 179) short lat; // latitude index (-90 to 89) - char x; // x subdivision (0 to 7) - char y; // y subdivision (0 to 7) + unsigned char x; // x subdivision (0 to 7) + unsigned char y; // y subdivision (0 to 7) + void innerSet( double dlon, double dlat ); public: /** - * Default constructor. + * Default constructor, creates an invalid SGBucket */ SGBucket(); + /** + * Check if this bucket refers to a valid tile, or not. + */ + bool isValid() const; + +#ifndef NO_DEPRECATED_API /** * Construct a bucket given a specific location. * @param dlon longitude specified in degrees * @param dlat latitude specified in degrees */ SGBucket(const double dlon, const double dlat); - - /** Construct a bucket. - * @param is_good if false, create an invalid bucket. This is - * useful * if you are comparing cur_bucket to last_bucket and - * you want to * make sure last_bucket starts out as something - * impossible. +#endif + + /** + * Construct a bucket given a specific location. + * + * @param geod Geodetic location */ - SGBucket(const bool is_good); + SGBucket(const SGGeod& geod); /** Construct a bucket given a unique bucket index number. + * * @param bindex unique bucket index */ SGBucket(const long int bindex); +#ifndef NO_DEPRECATED_API /** - * Default destructor. + * Reset a bucket to represent a new location. + * + * @param geod New geodetic location */ - ~SGBucket(); + void set_bucket(const SGGeod& geod); + /** * Reset a bucket to represent a new lat and lon @@ -158,25 +153,16 @@ public: * @param dlat latitude specified in degrees */ void set_bucket( double dlon, double dlat ); - - /** - * Reset a bucket to represent a new lat and lon - * @param lonlat an array of double[2] holding lon and lat - * (specified) in degrees - */ - void set_bucket( double *lonlat ); - +#endif + /** * Create an impossible bucket. * This is useful if you are comparing cur_bucket to last_bucket * and you want to make sure last_bucket starts out as something * impossible. */ - inline void make_bad() { - set_bucket(0.0, 0.0); - lon = -1000; - } - + void make_bad(); + /** * Generate the unique scenery tile index for this bucket * @@ -201,18 +187,13 @@ public: * string form. * @return tile index in string form */ - inline string gen_index_str() const { - char tmp[20]; - sprintf(tmp, "%ld", - (((long)lon + 180) << 14) + ((lat + 90) << 6) + (y << 3) + x); - return (string)tmp; - } - + std::string gen_index_str() const; + /** * Build the base path name for this bucket. * @return base path in string form */ - string gen_base_path() const; + std::string gen_base_path() const; /** * @return the center lon of a tile. @@ -221,9 +202,9 @@ public: double span = sg_bucket_span( lat + y / 8.0 + SG_HALF_BUCKET_SPAN ); if ( span >= 1.0 ) { - return lon + span / 2.0; + return lon + get_width() / 2.0; } else { - return lon + x * span + span / 2.0; + return lon + x * span + get_width() / 2.0; } } @@ -234,6 +215,13 @@ public: return lat + y / 8.0 + SG_HALF_BUCKET_SPAN; } + /** + * @return the highest (furthest from the equator) latitude of this + * tile. This is the top edge for tiles north of the equator, and + * the bottom edge for tiles south + */ + double get_highest_lat() const; + /** * @return the width of the tile in degrees. */ @@ -253,7 +241,24 @@ public: * @return the height of the tile in meters. */ double get_height_m() const; - + + /** + * @return the center of the bucket in geodetic coordinates. + */ + SGGeod get_center() const + { return SGGeod::fromDeg(get_center_lon(), get_center_lat()); } + + /** + * @return the center of the bucket in geodetic coordinates. + */ + SGGeod get_corner(unsigned num) const + { + double lonFac = ((num + 1) & 2) ? 0.5 : -0.5; + double latFac = ((num ) & 2) ? 0.5 : -0.5; + return SGGeod::fromDeg(get_center_lon() + lonFac*get_width(), + get_center_lat() + latFac*get_height()); + } + // Informational methods. /** @@ -278,13 +283,23 @@ public: */ inline int get_y() const { return y; } + /** + * @return bucket offset from this by dx,dy + */ + SGBucket sibling(int dx, int dy) const; + // friends - friend ostream& operator<< ( ostream&, const SGBucket& ); + friend std::ostream& operator<< ( std::ostream&, const SGBucket& ); friend bool operator== ( const SGBucket&, const SGBucket& ); }; +inline bool operator!= (const SGBucket& lhs, const SGBucket& rhs) + { + return !(lhs == rhs); + } +#ifndef NO_DEPRECATED_API /** * \relates SGBucket * Return the bucket which is offset from the specified dlon, dlat by @@ -296,6 +311,7 @@ public: * @return offset bucket */ SGBucket sgBucketOffset( double dlon, double dlat, int x, int y ); +#endif /** @@ -309,17 +325,21 @@ SGBucket sgBucketOffset( double dlon, double dlat, int x, int y ); void sgBucketDiff( const SGBucket& b1, const SGBucket& b2, int *dx, int *dy ); +/** + * \relates SGBucket + * retrieve a list of buckets in the given bounding box + * @param min min lon,lat of bounding box in degrees + * @param max max lon,lat of bounding box in degrees + * @param list standard vector of buckets within the bounding box + */ +void sgGetBuckets( const SGGeod& min, const SGGeod& max, std::vector& list ); + /** * Write the bucket lon, lat, x, and y to the output stream. * @param out output stream * @param b bucket */ -inline ostream& -operator<< ( ostream& out, const SGBucket& b ) -{ - return out << b.lon << ":" << b.x << ", " << b.lat << ":" << b.y; -} - +std::ostream& operator<< ( std::ostream& out, const SGBucket& b ); /** * Compare two bucket structures for equality.