~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to display/d.zoom/set.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <stdlib.h>
2
 
#include <string.h>
3
 
#include <math.h>
4
 
#include <grass/gis.h>
5
 
#include <grass/display.h>
6
 
#include <grass/raster.h>
7
 
#include "local_proto.h"
8
 
 
9
 
static double round_to(double in, int sd)
10
 
{
11
 
    double mult = 1, out;
12
 
 
13
 
    while (rint(in * mult) < pow(10, sd - 1))
14
 
        mult *= 10.0;
15
 
 
16
 
    out = rint(in * mult);
17
 
    out = out / mult;
18
 
    return out;
19
 
}
20
 
 
21
 
int set_win(struct Cell_head *window, double ux1, double uy1, double ux2,
22
 
            double uy2, int hand)
23
 
{
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;
30
 
 
31
 
    resetwin = 1;
32
 
 
33
 
    G_get_default_window(&defwin);
34
 
 
35
 
    north = uy1 > uy2 ? uy1 : uy2;
36
 
    south = uy1 < uy2 ? uy1 : uy2;
37
 
    west = ux1 < ux2 ? ux1 : ux2;
38
 
    east = ux1 > ux2 ? ux1 : ux2;
39
 
 
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;
48
 
            east = td + 180;
49
 
            west = td - 180;
50
 
        }
51
 
    }
52
 
 
53
 
    resetres = 1;
54
 
    while (resetres) {
55
 
        nsr = round_to(window->ns_res, 3);
56
 
        ewr = round_to(window->ew_res, 3);
57
 
 
58
 
        td = ceil(north / nsr);
59
 
        tnorth = td * nsr;
60
 
        td = floor(south / nsr);
61
 
        tsouth = td * nsr;
62
 
        td = rint(east / ewr);
63
 
        teast = td * ewr;
64
 
        td = rint(west / ewr);
65
 
        twest = td * ewr;
66
 
 
67
 
        ns = tnorth - tsouth;
68
 
        ew = teast - twest;
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) {
73
 
                fprintf(stderr,
74
 
                        "Minimum resolution supported by d.zoom reached.\n");
75
 
                resetwin = 0;
76
 
                break;
77
 
            }
78
 
 
79
 
            fprintf(stderr, "\nResolution is too low for selected region.\n");
80
 
            fprintf(stderr, "Buttons:\n");
81
 
            fprintf(stderr,
82
 
                    "Left:   Increase resolution to n-s = %g e-w = %g\n", nsr,
83
 
                    ewr);
84
 
            fprintf(stderr, "Middle: Cancel (keep previous region)\n");
85
 
            fprintf(stderr, "Right:  Cancel (keep previous region)\n");
86
 
 
87
 
            R_get_location_with_pointer(&screen_x, &screen_y, &button);
88
 
 
89
 
            if (button == 1) {
90
 
                window->ns_res = nsr;
91
 
                window->ns_res3 = nsr;
92
 
                window->ew_res = ewr;
93
 
                window->ew_res3 = ewr;
94
 
            }
95
 
            else {
96
 
                resetres = 0;
97
 
                resetwin = 0;
98
 
            }
99
 
        }
100
 
        else {
101
 
            resetres = 0;
102
 
        }
103
 
    }
104
 
 
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");
112
 
        fprintf(stderr,
113
 
                "Left:   Decrease resolution to n-s = %.20f e-w = %.20f\n",
114
 
                nsr, ewr);
115
 
        fprintf(stderr, "Middle: Keep current resolution\n");
116
 
        fprintf(stderr, "Right:  Keep current resolution\n");
117
 
 
118
 
        R_get_location_with_pointer(&screen_x, &screen_y, &button);
119
 
 
120
 
        if (button == 1) {
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);
126
 
            tnorth = td * nsr;
127
 
            td = rint(tsouth / nsr);
128
 
            tsouth = td * nsr;
129
 
            td = rint(teast / ewr);
130
 
            teast = td * ewr;
131
 
            td = rint(twest / ewr);
132
 
            twest = td * ewr;
133
 
        }
134
 
    }
135
 
 
136
 
    if (window->proj == PROJECTION_LL) {
137
 
        if (tnorth > 90)
138
 
            tnorth = 90;
139
 
        if (tsouth < -90)
140
 
            tsouth = -90;
141
 
        if (teast > 360)
142
 
            teast -= 360;       /* allow 0->360 as easting (e.g. Mars) */
143
 
        if (twest > 360)
144
 
            twest -= 360;
145
 
        if (teast < -180)
146
 
            teast += 360;
147
 
        if (twest < -180)
148
 
            twest += 360;
149
 
    }
150
 
 
151
 
    if (tnorth == tsouth)
152
 
        tnorth += window->ns_res;
153
 
    if (window->proj != PROJECTION_LL) {
154
 
        if (teast == twest)
155
 
            teast += window->ew_res;
156
 
    }
157
 
    else {
158
 
        if ((fabs(teast - twest) <= window->ew_res) ||
159
 
            (fabs(teast - 360 - twest) <= window->ew_res)) {
160
 
            teast -= window->ew_res;
161
 
        }
162
 
    }
163
 
 
164
 
    if (resetwin) {
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;
170
 
 
171
 
        if (!hand) {
172
 
            fprintf(stderr, "\n");
173
 
            print_win(window, north, south, east, west);
174
 
            fprintf(stderr, "\n");
175
 
        }
176
 
 
177
 
        limit = print_limit(window, &defwin);
178
 
 
179
 
        G_adjust_Cell_head3(window, 0, 0, 0);
180
 
        G_put_window(window);
181
 
        G_set_window(window);
182
 
        redraw();
183
 
    }
184
 
 
185
 
    return 1;
186
 
}