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 **************************************************************************/
33 #include <simgear/misc/fgpath.hxx>
35 #include "newbucket.hxx"
38 // Build the path name for this bucket
39 string FGBucket::gen_base_path() const {
41 int top_lon, top_lat, main_lon, main_lat;
47 if ( (lon < 0) && (top_lon * 10 != lon) ) {
63 if ( (lat < 0) && (top_lat * 10 != lat) ) {
77 sprintf(raw_path, "%c%03d%c%02d/%c%03d%c%02d",
78 hem, top_lon, pole, top_lat,
79 hem, main_lon, pole, main_lat);
81 FGPath path( raw_path );
87 // find the bucket which is offset by the specified tile units in the
88 // X & Y direction. We need the current lon and lat to resolve
89 // ambiguities when going from a wider tile to a narrower one above or
90 // below. This assumes that we are feeding in
91 FGBucket fgBucketOffset( double dlon, double dlat, int dx, int dy ) {
92 FGBucket result( dlon, dlat );
93 double clat = result.get_center_lat() + dy * FG_BUCKET_SPAN;
95 // walk dy units in the lat direction
96 result.set_bucket( dlon, clat );
98 // find the lon span for the new latitude
99 double span = bucket_span( clat );
101 // walk dx units in the lon direction
102 double tmp = dlon + dx * span;
103 while ( tmp < -180.0 ) {
106 while ( tmp >= 180.0 ) {
109 result.set_bucket( tmp, clat );
115 // calculate the offset between two buckets
116 void fgBucketDiff( const FGBucket& b1, const FGBucket& b2, int *dx, int *dy ) {
118 // Latitude difference
119 double c1_lat = b1.get_center_lat();
120 double c2_lat = b2.get_center_lat();
121 double diff_lat = c2_lat - c1_lat;
124 *dy = (int)rint( diff_lat / FG_BUCKET_SPAN );
126 if ( diff_lat > 0 ) {
127 *dy = (int)( diff_lat / FG_BUCKET_SPAN + 0.5 );
129 *dy = (int)( diff_lat / FG_BUCKET_SPAN - 0.5 );
133 // longitude difference
134 double c1_lon = b1.get_center_lon();
135 double c2_lon = b2.get_center_lon();
136 double diff_lon = c2_lon - c1_lon;
138 if ( bucket_span(c1_lat) <= bucket_span(c2_lat) ) {
139 span = bucket_span(c1_lat);
141 span = bucket_span(c2_lat);
145 *dx = (int)rint( diff_lon / span );
147 if ( diff_lon > 0 ) {
148 *dx = (int)( diff_lon / span + 0.5 );
150 *dx = (int)( diff_lon / span - 0.5 );