~foxtrotgps-team/foxtrotgps/trunk

« back to all changes in this revision

Viewing changes to src/converter.c

  • Committer: Paul Wise
  • Date: 2018-03-06 03:32:21 UTC
  • Revision ID: pabs3@bonedaddy.net-20180306033221-lzyia8y0cpw95j1b
Remove trailing whitespace

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
        int pixel_y;
31
31
 
32
32
        lat_m = atanh(sin(lat));
33
 
        
34
 
        
35
 
        
36
 
        pixel_y = -( (lat_m * TILESIZE * exp(zoom * M_LN2) ) / (2*M_PI)) + 
 
33
 
 
34
 
 
35
 
 
36
        pixel_y = -( (lat_m * TILESIZE * exp(zoom * M_LN2) ) / (2*M_PI)) +
37
37
                    (exp(zoom * M_LN2) * (TILESIZE/2) );
38
38
 
39
39
 
47
47
{
48
48
        int pixel_x;
49
49
 
50
 
        pixel_x = ( (lon * TILESIZE * exp(zoom * M_LN2) ) / (2*M_PI) ) + 
 
50
        pixel_x = ( (lon * TILESIZE * exp(zoom * M_LN2) ) / (2*M_PI) ) +
51
51
                    ( exp(zoom * M_LN2) * (TILESIZE/2) );
52
52
        return pixel_x;
53
53
}
57
57
                int pixel_x)
58
58
{
59
59
        float lon;
60
 
        
61
 
        lon = ((pixel_x - ( exp(zoom * M_LN2) * (TILESIZE/2) ) ) *2*M_PI) / 
 
60
 
 
61
        lon = ((pixel_x - ( exp(zoom * M_LN2) * (TILESIZE/2) ) ) *2*M_PI) /
62
62
                        (TILESIZE * exp(zoom * M_LN2) );
63
 
        
 
63
 
64
64
        return lon;
65
65
}
66
66
 
72
72
 
73
73
        lat_m = (-( pixel_y - ( exp(zoom * M_LN2) * (TILESIZE/2) ) ) * (2*M_PI)) /
74
74
                                (TILESIZE * exp(zoom * M_LN2));
75
 
        
76
 
        lat = asin(tanh(lat_m));        
77
 
        
 
75
 
 
76
        lat = asin(tanh(lat_m));
 
77
 
78
78
        return lat;
79
79
}
80
80
 
84
84
        static char latmin[20];
85
85
        int degrees;
86
86
        float minutes;
87
 
        
 
87
 
88
88
        degrees = abs( (lat>0) ? floor(lat) : ceil(lat) );
89
89
        minutes = (fabs(lat) - (float)degrees) * 60;
90
 
        
 
90
 
91
91
        g_sprintf(      latmin,
92
 
                        "%d°%.3f' %s", 
 
92
                        "%d°%.3f' %s",
93
93
                        degrees,
94
94
                        minutes,
95
95
                        (lat>0) ? "N" : "S");
96
 
        
 
96
 
97
97
        return latmin;
98
98
}
99
99
 
103
103
        static char lonmin[20];
104
104
        int degrees;
105
105
        float minutes;
106
 
        
 
106
 
107
107
        degrees = abs( (lon>0) ? floor(lon) : ceil(lon) );
108
108
        minutes = (fabs(lon) - (float)degrees) * 60;
109
 
        
 
109
 
110
110
        g_sprintf(      lonmin,
111
111
                        "%d°%.3f' %s",
112
112
                        degrees,
113
113
                        minutes,
114
114
                        (lon>0) ? "E" : "W");
115
 
        
 
115
 
116
116
        return lonmin;
117
117
}
118
118
 
122
122
        static char latsec[20];
123
123
        int degrees, full_minutes;
124
124
        float minutes, seconds;
125
 
        
 
125
 
126
126
        degrees = abs( (lat>0) ? floor(lat) : ceil(lat) );
127
127
        minutes = (fabs(lat) - (float)degrees) * 60;
128
128
        full_minutes = floor(minutes);
129
129
        seconds = (minutes - (float)full_minutes) * 60;
130
 
        
 
130
 
131
131
        g_sprintf(      latsec,
132
 
                        "%d°%d'%.2f\" %s", 
 
132
                        "%d°%d'%.2f\" %s",
133
133
                        degrees,
134
134
                        full_minutes,
135
135
                        seconds,
136
136
                        (lat>0) ? "N" : "S");
137
 
        
 
137
 
138
138
        return latsec;
139
139
}
140
140
 
144
144
        static char lonmin[20];
145
145
        int degrees, full_minutes;
146
146
        float minutes, seconds;
147
 
        
 
147
 
148
148
        degrees = abs( (lon>0) ? floor(lon) : ceil(lon) );
149
149
        minutes = (fabs(lon) - (float)degrees) * 60;
150
150
        full_minutes = floor(minutes);
151
151
        seconds = (minutes - (float)full_minutes) * 60;
152
 
        
 
152
 
153
153
        g_sprintf(      lonmin,
154
154
                        "%d°%d'%.2f\" %s",
155
155
                        degrees,
156
156
                        full_minutes,
157
157
                        seconds,
158
158
                        (lon>0) ? "E" : "W");
159
 
        
 
159
 
160
160
        return lonmin;
161
161
}
162
162
 
170
170
                    cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(lon2-lon1) );
171
171
 
172
172
        tmp2 = tmp;
173
 
        
 
173
 
174
174
        bearing = (tmp2<0) ? tmp2+M_PI*2 : tmp2;
175
175
 
176
 
        
 
176
 
177
177
 
178
178
        return bearing;
179
179
}
183
183
{
184
184
        float distance = 0;
185
185
        double tmp;
186
 
        
 
186
 
187
187
        tmp = sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(lon2 - lon1);
188
 
        
 
188
 
189
189
        distance = 6371.0 *  acos(tmp);
190
190
 
191
 
        
192
 
        
 
191
 
 
192
 
193
193
        return distance;
194
194
}
195
195
 
201
201
 
202
202
        while (zoom>=2)
203
203
        {
204
 
                
 
204
 
205
205
                pixel_x1 = lon2pixel((float)zoom, lon_min);
206
206
                pixel_y1 = lat2pixel((float)zoom, lat_max);
207
 
                
 
207
 
208
208
                pixel_x2 = lon2pixel((float)zoom, lon_max);
209
209
                pixel_y2 = lat2pixel((float)zoom, lat_min);
210
 
                
211
 
                
 
210
 
 
211
 
212
212
                if(     (pixel_x1+width)  > pixel_x2    &&
213
213
                        (pixel_y1+height) > pixel_y2 )
214
214
                {
215
215
                        return zoom;
216
216
                }
217
217
                zoom--;
218
 
        }       
219
 
        
 
218
        }
 
219
 
220
220
        return zoom;
221
221
}