From 505de4703b91cdd4d625a0b612dac566ea5cf8ca Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 11 Feb 1999 01:09:33 +0000 Subject: [PATCH] Added a routine to calculate the offset in bucket units between two buckets. --- Bucket/newbucket.cxx | 49 ++++++++++++++++++++++++++++++++++++++++++++ Bucket/newbucket.hxx | 39 +++++++++++++++++++---------------- 2 files changed, 70 insertions(+), 18 deletions(-) diff --git a/Bucket/newbucket.cxx b/Bucket/newbucket.cxx index 66eca096..f57c7f72 100644 --- a/Bucket/newbucket.cxx +++ b/Bucket/newbucket.cxx @@ -24,6 +24,11 @@ **************************************************************************/ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + + #include "newbucket.hxx" @@ -99,7 +104,51 @@ FGBucket fgBucketOffset( double dlon, double dlat, int dx, int dy ) { } +// calculate the offset between two buckets +void fgBucketDiff( const FGBucket& b1, const FGBucket& b2, int *dx, int *dy ) { + + // Latitude difference + double c1_lat = b1.get_center_lat(); + double c2_lat = b2.get_center_lat(); + double diff_lat = c2_lat - c1_lat; + +#ifdef HAVE_RINT + *dy = (int)rint( diff_lat / FG_BUCKET_SPAN ); +#else + if ( diff_lat > 0 ) { + *dy = (int)( diff_lat / FG_BUCKET_SPAN + 0.5 ); + } else { + *dy = (int)( diff_lat / FG_BUCKET_SPAN - 0.5 ); + } +#endif + + // longitude difference + double c1_lon = b1.get_center_lon(); + double c2_lon = b2.get_center_lon(); + double diff_lon = c2_lon - c1_lon; + double span; + if ( bucket_span(c1_lat) <= bucket_span(c2_lat) ) { + span = bucket_span(c1_lat); + } else { + span = bucket_span(c2_lat); + } + +#ifdef HAVE_RINT + *dx = (int)rint( diff_lon / span ); +#else + if ( diff_lon > 0 ) { + *dx = (int)( diff_lon / span + 0.5 ); + } else { + *dx = (int)( diff_lon / span - 0.5 ); + } +#endif +} + + // $Log$ +// Revision 1.2 1999/02/11 01:09:33 curt +// Added a routine to calculate the offset in bucket units between two buckets. +// // Revision 1.1 1999/02/08 23:52:16 curt // Added a new "newbucket.[ch]xx" FGBucket class to replace the old // fgBUCKET struct and C routines. This FGBucket class adjusts the tile diff --git a/Bucket/newbucket.hxx b/Bucket/newbucket.hxx index e2958edc..ac24b999 100644 --- a/Bucket/newbucket.hxx +++ b/Bucket/newbucket.hxx @@ -75,13 +75,14 @@ public: string gen_base_path(); // return the center lon of a tile - double get_center_lon(); + double get_center_lon() const; // return the center lat of a tile - double get_center_lat(); + double get_center_lat() const; // friends friend ostream& operator<< ( ostream&, const FGBucket& ); + friend bool operator== ( const FGBucket&, const FGBucket& ); }; @@ -224,7 +225,7 @@ inline long int FGBucket::gen_index() { // return the center lon of a tile -inline double FGBucket::get_center_lon() { +inline double FGBucket::get_center_lon() const { double span = bucket_span( lat + y / 8.0 + FG_HALF_BUCKET_SPAN ); if ( span >= 1.0 ) { @@ -236,7 +237,7 @@ inline double FGBucket::get_center_lon() { // return the center lat of a tile -inline double FGBucket::get_center_lat() { +inline double FGBucket::get_center_lat() const { return lat + y / 8.0 + FG_HALF_BUCKET_SPAN; } @@ -246,14 +247,25 @@ inline double FGBucket::get_center_lat() { FGBucket fgBucketOffset( double dlon, double dlat, int x, int y ); +// calculate the offset between two buckets +void fgBucketDiff( const FGBucket& b1, const FGBucket& b2, int *dx, int *dy ); + + /* // Given a lat/lon, fill in the local tile index array void fgBucketGenIdxArray(fgBUCKET *p1, fgBUCKET *tiles, int width, int height); +*/ +inline ostream& +operator<< ( ostream& out, const FGBucket& b ) +{ + return out << b.lon << ":" << b.x << ", " << b.lat << ":" << b.y; +} + inline bool -operator== ( const fgBUCKET& b1, const fgBUCKET& b2 ) +operator== ( const FGBucket& b1, const FGBucket& b2 ) { return ( b1.lon == b2.lon && b1.lat == b2.lat && @@ -261,6 +273,7 @@ operator== ( const fgBUCKET& b1, const fgBUCKET& b2 ) b1.y == b2.y ); } +/* inline string fgBucketGenIndex( const fgBUCKET& p ) { @@ -269,27 +282,17 @@ fgBucketGenIndex( const fgBUCKET& p ) return string( index_str ); } -inline string -fgBucketGenBasePath( const fgBUCKET& p ) -{ - char base_path[256]; - fgBucketGenBasePath( &p, base_path ); - return string( base_path ); -} - */ -inline ostream& -operator<< ( ostream& out, const FGBucket& b ) -{ - return out << b.lon << ":" << b.x << ", " << b.lat << ":" << b.y; -} #endif // _NEWBUCKET_HXX // $Log$ +// Revision 1.2 1999/02/11 01:09:34 curt +// Added a routine to calculate the offset in bucket units between two buckets. +// // Revision 1.1 1999/02/08 23:52:16 curt // Added a new "newbucket.[ch]xx" FGBucket class to replace the old // fgBUCKET struct and C routines. This FGBucket class adjusts the tile -- 2.39.5