/usr/include/simgear/bucket/newbucket.hxx is in libsimgear-dev 3.0.0-6+b2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | /**************************************************************************
* newbucket.hxx -- new bucket routines for better world modeling
*
* Written by Curtis L. Olson, started February 1999.
*
* 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
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* 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 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
#define _NEWBUCKET_HXX
#include <simgear/compiler.h>
#include <simgear/constants.h>
#include <simgear/math/SGMath.hxx>
#include <cmath>
#include <cstdio> // sprintf()
#include <ostream>
#include <string>
#include <vector>
/**
* standard size of a bucket in degrees (1/8 of a degree)
*/
#define SG_BUCKET_SPAN 0.125
/**
* half of a standard SG_BUCKET_SPAN
*/
#define SG_HALF_BUCKET_SPAN ( 0.5 * SG_BUCKET_SPAN )
// return the horizontal tile span factor based on latitude
static double sg_bucket_span( double l ) {
if ( l >= 89.0 ) {
return 12.0;
} else if ( l >= 86.0 ) {
return 4.0;
} else if ( l >= 83.0 ) {
return 2.0;
} else if ( l >= 76.0 ) {
return 1.0;
} else if ( l >= 62.0 ) {
return 0.5;
} else if ( l >= 22.0 ) {
return 0.25;
} else if ( l >= -22.0 ) {
return 0.125;
} else if ( l >= -62.0 ) {
return 0.25;
} else if ( l >= -76.0 ) {
return 0.5;
} else if ( l >= -83.0 ) {
return 1.0;
} else if ( l >= -86.0 ) {
return 2.0;
} else if ( l >= -89.0 ) {
return 4.0;
} else {
return 12.0;
}
}
/**
* A class to manage world scenery tiling.
* This class encapsulates the world tiling scheme. It provides ways
* to calculate a unique tile index from a lat/lon, and it can provide
* information such as the dimensions of a given tile.
*/
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)
public:
/**
* Default constructor.
*/
SGBucket();
/**
* 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);
/**
* 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
* 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);
/**
* 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( double dlon, double dlat );
/**
* 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);
/**
* 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;
}
/**
* Generate the unique scenery tile index for this bucket
*
* The index is constructed as follows:
*
* 9 bits - to represent 360 degrees of longitude (-180 to 179)
* 8 bits - to represent 180 degrees of latitude (-90 to 89)
*
* Each 1 degree by 1 degree tile is further broken down into an 8x8
* grid. So we also need:
*
* 3 bits - to represent x (0 to 7)
* 3 bits - to represent y (0 to 7)
* @return tile index
*/
inline long int gen_index() const {
return ((lon + 180) << 14) + ((lat + 90) << 6) + (y << 3) + x;
}
/**
* Generate the unique scenery tile index for this bucket in ascii
* 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;
}
/**
* Build the base path name for this bucket.
* @return base path in string form
*/
std::string gen_base_path() const;
/**
* @return the center lon of a tile.
*/
inline double get_center_lon() const {
double span = sg_bucket_span( lat + y / 8.0 + SG_HALF_BUCKET_SPAN );
if ( span >= 1.0 ) {
return lon + get_width() / 2.0;
} else {
return lon + x * span + get_width() / 2.0;
}
}
/**
* @return the center lat of a tile.
*/
inline double get_center_lat() const {
return lat + y / 8.0 + SG_HALF_BUCKET_SPAN;
}
/**
* @return the width of the tile in degrees.
*/
double get_width() const;
/**
* @return the height of the tile in degrees.
*/
double get_height() const;
/**
* @return the width of the tile in meters.
*/
double get_width_m() const;
/**
* @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_chunk_lon() const { return lon; }
/**
* @return the lat of the lower left corner of
* the 1x1 chunk containing this tile.
*/
inline int get_chunk_lat() const { return lat; }
/**
* @return the x coord within the 1x1 degree chunk this tile.
*/
inline int get_x() const { return x; }
/**
* @return the y coord within the 1x1 degree chunk this tile.
*/
inline int get_y() const { return y; }
// friends
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
* Return the bucket which is offset from the specified dlon, dlat by
* the specified tile units in the X & Y direction.
* @param dlon starting lon in degrees
* @param dlat starting lat in degrees
* @param x number of bucket units to offset in x (lon) direction
* @param y number of bucket units to offset in y (lat) direction
* @return offset bucket
*/
SGBucket sgBucketOffset( double dlon, double dlat, int x, int y );
/**
* \relates SGBucket
* Calculate the offset between two buckets (in quantity of buckets).
* @param b1 bucket 1
* @param b2 bucket 2
* @param dx offset distance (lon) in tile units
* @param dy offset distance (lat) in tile units
*/
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;
}
/**
* Compare two bucket structures for equality.
* @param b1 bucket 1
* @param b2 bucket 2
* @return comparison result
*/
inline bool
operator== ( const SGBucket& b1, const SGBucket& b2 )
{
return ( b1.lon == b2.lon &&
b1.lat == b2.lat &&
b1.x == b2.x &&
b1.y == b2.y );
}
#endif // _NEWBUCKET_HXX
|