]> git.mxchange.org Git - simgear.git/blobdiff - simgear/bucket/newbucket.hxx
Remove non-CURL HTTP option.
[simgear.git] / simgear / bucket / newbucket.hxx
index 64aa5f80a3f721f43f1b25c946fe6ae54ae98b4b..fe0bbbc4abd305b113723e269a76df7e6796e81f 100644 (file)
 #include <simgear/math/SGMath.hxx>
 
 #include <cmath>
-#include <cstdio> // sprintf()
-#include <ostream>
 #include <string>
+#include <iosfwd>
+#include <vector>
+
+// #define NO_DEPRECATED_API
 
 /**
  * standard size of a bucket in degrees (1/8 of a degree)
@@ -98,75 +100,69 @@ class SGBucket {
 private:
     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);
-
+#endif
+    
     /**
      * Construct a bucket given a specific location.
-     * @param dlon longitude specified in degrees
-     * @param dlat latitude specified in degrees
+     *
+     * @param geod Geodetic location
      */
     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
-     *  you want to * make sure last_bucket starts out as something
-     *  impossible.
-     */
-    SGBucket(const bool is_good);
-
     /** Construct a bucket given a unique bucket index number.
+     *
      * @param bindex unique bucket index
      */
     SGBucket(const long int bindex);
 
+#ifndef NO_DEPRECATED_API
     /**
-     * Reset a bucket to represent a new lat and lon
-     * @param dlon longitude specified in degrees
-     * @param dlat latitude specified in degrees
+     * Reset a bucket to represent a new location.
+     *
+     * @param geod New geodetic location
      */
-    void set_bucket( double dlon, double dlat );
+    void set_bucket(const SGGeod& geod);
 
-    /**
-     * 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 );
 
     /**
      * 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);
-
+    void set_bucket( double dlon, double dlat );
+#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
      *
@@ -191,14 +187,8 @@ public:
      * string form.
      * @return tile index in string form
      */
-    inline std::string gen_index_str() const {
-       char tmp[20];
-       std::sprintf(tmp, "%ld", 
-                     (((long)lon + 180) << 14) + ((lat + 90) << 6)
-                     + (y << 3) + x);
-       return (std::string)tmp;
-    }
-
+    std::string gen_index_str() const;
+    
     /**
      * Build the base path name for this bucket.
      * @return base path in string form
@@ -225,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.
      */
@@ -286,6 +283,11 @@ 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 std::ostream& operator<< ( std::ostream&, const SGBucket& );
@@ -297,7 +299,7 @@ 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
@@ -309,6 +311,7 @@ inline bool operator!= (const SGBucket& lhs, const SGBucket& rhs)
  * @return offset bucket
  */
 SGBucket sgBucketOffset( double dlon, double dlat, int x, int y );
+#endif
 
 
 /**
@@ -322,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<SGBucket>& list );
+
 /**
  * Write the bucket lon, lat, x, and y to the output stream.
  * @param out output stream
  * @param b bucket
  */
-inline std::ostream&
-operator<< ( std::ostream& out, const SGBucket& b )
-{
-    return out << b.lon << ":" << (int)b.x << ", " << b.lat << ":" << (int)b.y;
-}
-
+std::ostream& operator<< ( std::ostream& out, const SGBucket& b );
 
 /**
  * Compare two bucket structures for equality.