]> git.mxchange.org Git - simgear.git/blob - Lib/Bucket/newbucket.cxx
Fixed an IRIX warning message where an inline function is referenced
[simgear.git] / Lib / Bucket / newbucket.cxx
1 /**************************************************************************
2  * newbucket.hxx -- new bucket routines for better world modeling
3  *
4  * Written by Curtis L. Olson, started February 1999.
5  *
6  * Copyright (C) 1999  Curtis L. Olson - curt@flightgear.org
7  *
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.
12  *
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.
17  *
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.
21  *
22  * $Id$
23  **************************************************************************/
24
25
26 #ifdef HAVE_CONFIG_H
27 #  include "config.h"
28 #endif
29
30
31 #include <Misc/fgpath.hxx>
32
33 #include "newbucket.hxx"
34
35
36 // Build the path name for this bucket
37 string FGBucket::gen_base_path() const {
38     // long int index;
39     int top_lon, top_lat, main_lon, main_lat;
40     char hem, pole;
41     char raw_path[256];
42
43     top_lon = lon / 10;
44     main_lon = lon;
45     if ( (lon < 0) && (top_lon * 10 != lon) ) {
46         top_lon -= 1;
47     }
48     top_lon *= 10;
49     if ( top_lon >= 0 ) {
50         hem = 'e';
51     } else {
52         hem = 'w';
53         top_lon *= -1;
54     }
55     if ( main_lon < 0 ) {
56         main_lon *= -1;
57     }
58     
59     top_lat = lat / 10;
60     main_lat = lat;
61     if ( (lat < 0) && (top_lat * 10 != lat) ) {
62         top_lat -= 1;
63     }
64     top_lat *= 10;
65     if ( top_lat >= 0 ) {
66         pole = 'n';
67     } else {
68         pole = 's';
69         top_lat *= -1;
70     }
71     if ( main_lat < 0 ) {
72         main_lat *= -1;
73     }
74
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);
78
79     FGPath path( raw_path );
80
81     return path.str();
82 }
83
84
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;
92
93     // walk dy units in the lat direction
94     result.set_bucket( dlon, clat );
95
96     // find the lon span for the new latitude
97     double span = bucket_span( clat );
98
99     // walk dx units in the lon direction
100     double tmp = dlon + dx * span;
101     while ( tmp < -180.0 ) {
102         tmp += 360.0;
103     }
104     while ( tmp >= 180.0 ) {
105         tmp -= 360.0;
106     }
107     result.set_bucket( tmp, clat );
108
109     return result;
110 }
111
112
113 // calculate the offset between two buckets
114 void fgBucketDiff( const FGBucket& b1, const FGBucket& b2, int *dx, int *dy ) {
115
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;
120
121 #ifdef HAVE_RINT
122     *dy = (int)rint( diff_lat / FG_BUCKET_SPAN );
123 #else
124     if ( diff_lat > 0 ) {
125         *dy = (int)( diff_lat / FG_BUCKET_SPAN + 0.5 );
126     } else {
127         *dy = (int)( diff_lat / FG_BUCKET_SPAN - 0.5 );
128     }
129 #endif
130
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;
135     double span;
136     if ( bucket_span(c1_lat) <= bucket_span(c2_lat) ) {
137         span = bucket_span(c1_lat);
138     } else {
139         span = bucket_span(c2_lat);
140     }
141
142 #ifdef HAVE_RINT
143     *dx = (int)rint( diff_lon / span );
144 #else
145     if ( diff_lon > 0 ) {
146         *dx = (int)( diff_lon / span + 0.5 );
147     } else {
148         *dx = (int)( diff_lon / span - 0.5 );
149     }
150 #endif
151 }
152
153