*
* Written by Curtis L. Olson, started February 1999.
*
- * Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
+ * Copyright (C) 1999 Curtis L. Olson - http://www.flightgear.org/~curt
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* 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
#include <simgear/compiler.h>
#include <simgear/constants.h>
+#include <simgear/math/SGMath.hxx>
-#ifdef SG_HAVE_STD_INCLUDES
-# include <cmath>
-# include <cstdio> // sprintf()
-#else
-# include <math.h>
-# include <stdio.h> // sprintf()
-#endif
-
-#include STL_IOSTREAM
-
-// I don't understand ... <math.h> or <cmath> 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 <cmath>
+#include <cstdio> // sprintf()
+#include <ostream>
+#include <string>
/**
* standard size of a bucket in degrees (1/8 of a degree)
class SGBucket {
private:
- double cx, cy; // centerpoint (lon, lat) in degrees of bucket
- int lon; // longitude index (-180 to 179)
- int lat; // latitude index (-90 to 89)
- int x; // x subdivision (0 to 7)
- int y; // y subdivision (0 to 7)
+ 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)
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
*/
SGBucket(const long int bindex);
- /**
- * Default destructor.
- */
- ~SGBucket();
-
/**
* Reset a bucket to represent a new lat and lon
* @param dlon longitude 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);
+
/**
* Create an impossible bucket.
* This is useful if you are comparing cur_bucket to last_bucket
* 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.
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;
}
}
* @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.
/**
* @return the lon of the lower left corner of
* the 1x1 chunk containing this tile.
*/
- inline int get_lon() const { return lon; }
+ inline int get_chunk_lon() const { return lon; }
/**
* @return the lat of the lower left corner of
* the 1x1 chunk containing this tile.
*/
- inline int get_lat() const { return lat; }
+ inline int get_chunk_lat() const { return lat; }
/**
* @return the x coord within the 1x1 degree chunk this tile.
// 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
* @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;
}