5
#include <grass/display.h>
6
#include <grass/raster.h>
7
#include "local_proto.h"
9
static double round_to(double in, int sd)
13
while (rint(in * mult) < pow(10, sd - 1))
16
out = rint(in * mult);
21
int set_win(struct Cell_head *window, double ux1, double uy1, double ux2,
24
struct Cell_head defwin;
25
double north, south, east, west;
26
double tnorth, tsouth, teast, twest, td;
27
double ncol, nrow, ew, ns, nsr, ewr;
28
int resetres, resetwin, limit;
29
int screen_x, screen_y, button;
33
G_get_default_window(&defwin);
35
north = uy1 > uy2 ? uy1 : uy2;
36
south = uy1 < uy2 ? uy1 : uy2;
37
west = ux1 < ux2 ? ux1 : ux2;
38
east = ux1 > ux2 ? ux1 : ux2;
40
G_limit_south(&south, window->proj);
41
G_limit_north(&north, window->proj);
42
G_limit_east(&east, window->proj);
43
G_limit_west(&west, window->proj);
44
if (window->proj == PROJECTION_LL) {
45
if ((east - west) > 360) {
46
fprintf(stderr, "(longitude range > 360) -> resetting\n");
47
td = (east + west) / 2;
55
nsr = round_to(window->ns_res, 3);
56
ewr = round_to(window->ew_res, 3);
58
td = ceil(north / nsr);
60
td = floor(south / nsr);
62
td = rint(east / ewr);
64
td = rint(west / ewr);
69
if ((ns < 2 * window->ns_res || ew < 2 * window->ew_res) && !hand) {
70
nsr = round_to(nsr / 10.0, 3);
71
ewr = round_to(ewr / 10.0, 3);
72
if (nsr < 0.00000001 || ewr < 0.00000001) {
74
"Minimum resolution supported by d.zoom reached.\n");
79
fprintf(stderr, "\nResolution is too low for selected region.\n");
80
fprintf(stderr, "Buttons:\n");
82
"Left: Increase resolution to n-s = %g e-w = %g\n", nsr,
84
fprintf(stderr, "Middle: Cancel (keep previous region)\n");
85
fprintf(stderr, "Right: Cancel (keep previous region)\n");
87
R_get_location_with_pointer(&screen_x, &screen_y, &button);
91
window->ns_res3 = nsr;
93
window->ew_res3 = ewr;
105
nrow = (tnorth - tsouth) / window->ns_res;
106
ncol = (teast - twest) / window->ew_res;
107
if ((nrow > 10000000 || ncol > 10000000) && !hand) {
108
nsr = round_to(window->ns_res * 10, 3);
109
ewr = round_to(window->ew_res * 10, 3);
110
fprintf(stderr, "\nResolution is too high for selected region.\n");
111
fprintf(stderr, "Buttons:\n");
113
"Left: Decrease resolution to n-s = %.20f e-w = %.20f\n",
115
fprintf(stderr, "Middle: Keep current resolution\n");
116
fprintf(stderr, "Right: Keep current resolution\n");
118
R_get_location_with_pointer(&screen_x, &screen_y, &button);
121
window->ns_res = nsr;
122
window->ns_res3 = nsr;
123
window->ew_res = ewr;
124
window->ew_res3 = ewr;
125
td = rint(tnorth / nsr);
127
td = rint(tsouth / nsr);
129
td = rint(teast / ewr);
131
td = rint(twest / ewr);
136
if (window->proj == PROJECTION_LL) {
142
teast -= 360; /* allow 0->360 as easting (e.g. Mars) */
151
if (tnorth == tsouth)
152
tnorth += window->ns_res;
153
if (window->proj != PROJECTION_LL) {
155
teast += window->ew_res;
158
if ((fabs(teast - twest) <= window->ew_res) ||
159
(fabs(teast - 360 - twest) <= window->ew_res)) {
160
teast -= window->ew_res;
165
/* favour resolution over bounds; round inwards to protect lat/lon */
166
window->north = floor(tnorth / window->ns_res) * window->ns_res;
167
window->south = ceil(tsouth / window->ns_res) * window->ns_res;
168
window->east = floor(teast / window->ew_res) * window->ew_res;
169
window->west = ceil(twest / window->ew_res) * window->ew_res;
172
fprintf(stderr, "\n");
173
print_win(window, north, south, east, west);
174
fprintf(stderr, "\n");
177
limit = print_limit(window, &defwin);
179
G_adjust_Cell_head3(window, 0, 0, 0);
180
G_put_window(window);
181
G_set_window(window);