X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fbucket%2Fnewbucket.hxx;h=58008e5c06ec21735b3dc3ec045df8709e2e9ab7;hb=c1762c709e10e3e51de13bbade9da7869e13871d;hp=2ba7de551e669d4a0da76fa0f5c901cf5265b8b4;hpb=4e7fe460a5c5c1b64dd1d540bc197dbb89614b7f;p=simgear.git diff --git a/simgear/bucket/newbucket.hxx b/simgear/bucket/newbucket.hxx index 2ba7de55..58008e5c 100644 --- a/simgear/bucket/newbucket.hxx +++ b/simgear/bucket/newbucket.hxx @@ -31,30 +31,12 @@ #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 // sprintf() +#include +#include /** * standard size of a bucket in degrees (1/8 of a degree) @@ -113,7 +95,6 @@ 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) @@ -133,6 +114,13 @@ public: */ SGBucket(const double dlon, const double dlat); + /** + * Construct a bucket given a specific location. + * @param dlon longitude specified in degrees + * @param dlat latitude specified in degrees + */ + SGBucket(const SGGeod& geod); + /** 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 @@ -146,11 +134,6 @@ public: */ SGBucket(const long int bindex); - /** - * Default destructor. - */ - ~SGBucket(); - /** * Reset a bucket to represent a new lat and lon * @param dlon longitude specified in degrees @@ -165,6 +148,13 @@ public: */ void set_bucket( double *lonlat ); + /** + * Reset a bucket to represent a new lat and lon + * @param dlon longitude specified in degrees + * @param dlat latitude specified in degrees + */ + void set_bucket(const SGGeod& geod); + /** * Create an impossible bucket. * This is useful if you are comparing cur_bucket to last_bucket @@ -200,18 +190,19 @@ public: * string form. * @return tile index in string form */ - inline string gen_index_str() const { + inline std::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::sprintf(tmp, "%ld", + (((long)lon + 180) << 14) + ((lat + 90) << 6) + + (y << 3) + x); + return (std::string)tmp; } /** * 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. @@ -252,7 +243,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. /** @@ -279,10 +287,15 @@ public: // 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); + } + /** * \relates SGBucket @@ -313,10 +326,10 @@ void sgBucketDiff( const SGBucket& b1, const SGBucket& b2, int *dx, int *dy ); * @param out output stream * @param b bucket */ -inline ostream& -operator<< ( ostream& out, const SGBucket& b ) +inline std::ostream& +operator<< ( std::ostream& out, const SGBucket& b ) { - return out << b.lon << ":" << b.x << ", " << b.lat << ":" << b.y; + return out << b.lon << ":" << (int)b.x << ", " << b.lat << ":" << (int)b.y; }