]> git.mxchange.org Git - flightgear.git/commitdiff
Added a routine to calculate the offset in bucket units between two buckets.
authorcurt <curt>
Thu, 11 Feb 1999 01:09:33 +0000 (01:09 +0000)
committercurt <curt>
Thu, 11 Feb 1999 01:09:33 +0000 (01:09 +0000)
Bucket/newbucket.cxx
Bucket/newbucket.hxx

index 66eca0963131354f7ab4d16e5be9c2815d15b788..f57c7f7208c216d17670820b890fe90afc502631 100644 (file)
  **************************************************************************/
 
 
+#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
index e2958edc870720fec7e0e011c26e36865a1f975e..ac24b999b4ae31d61cecead62706e5181351babb 100644 (file)
@@ -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