1 /**************************************************************************
2 * newbucket.hxx -- new bucket routines for better world modeling
4 * Written by Curtis L. Olson, started February 1999.
6 * Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 **************************************************************************/
31 #include <Misc/fgpath.hxx>
33 #include "newbucket.hxx"
36 // Build the path name for this bucket
37 string FGBucket::gen_base_path() const {
39 int top_lon, top_lat, main_lon, main_lat;
45 if ( (lon < 0) && (top_lon * 10 != lon) ) {
61 if ( (lat < 0) && (top_lat * 10 != lat) ) {
75 sprintf(raw_path, "%c%03d%c%02d/%c%03d%c%02d",
76 hem, top_lon, pole, top_lat,
77 hem, main_lon, pole, main_lat);
79 FGPath path( raw_path );
85 // find the bucket which is offset by the specified tile units in the
86 // X & Y direction. We need the current lon and lat to resolve
87 // ambiguities when going from a wider tile to a narrower one above or
88 // below. This assumes that we are feeding in
89 FGBucket fgBucketOffset( double dlon, double dlat, int dx, int dy ) {
90 FGBucket result( dlon, dlat );
91 double clat = result.get_center_lat() + dy * FG_BUCKET_SPAN;
93 // walk dy units in the lat direction
94 result.set_bucket( dlon, clat );
96 // find the lon span for the new latitude
97 double span = bucket_span( clat );
99 // walk dx units in the lon direction
100 double tmp = dlon + dx * span;
101 while ( tmp < -180.0 ) {
104 while ( tmp >= 180.0 ) {
107 result.set_bucket( tmp, clat );
113 // calculate the offset between two buckets
114 void fgBucketDiff( const FGBucket& b1, const FGBucket& b2, int *dx, int *dy ) {
116 // Latitude difference
117 double c1_lat = b1.get_center_lat();
118 double c2_lat = b2.get_center_lat();
119 double diff_lat = c2_lat - c1_lat;
122 *dy = (int)rint( diff_lat / FG_BUCKET_SPAN );
124 if ( diff_lat > 0 ) {
125 *dy = (int)( diff_lat / FG_BUCKET_SPAN + 0.5 );
127 *dy = (int)( diff_lat / FG_BUCKET_SPAN - 0.5 );
131 // longitude difference
132 double c1_lon = b1.get_center_lon();
133 double c2_lon = b2.get_center_lon();
134 double diff_lon = c2_lon - c1_lon;
136 if ( bucket_span(c1_lat) <= bucket_span(c2_lat) ) {
137 span = bucket_span(c1_lat);
139 span = bucket_span(c2_lat);
143 *dx = (int)rint( diff_lon / span );
145 if ( diff_lon > 0 ) {
146 *dx = (int)( diff_lon / span + 0.5 );
148 *dx = (int)( diff_lon / span - 0.5 );