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

« back to all changes in this revision

Viewing changes to lib/gis/geodesic.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:
28
28
 */
29
29
 
30
30
 
31
 
#define SWAP(a,b) temp=a;a=b;b=temp
32
 
 
33
 
static int adjust_lat(double *);
34
 
static int adjust_lon(double *);
35
 
 
36
 
static double A, B;
37
 
 
 
31
static void adjust_lat(double *);
 
32
static void adjust_lon(double *);
 
33
 
 
34
static struct state {
 
35
    double A, B;
 
36
} state;
 
37
 
 
38
static struct state *st = &state;
38
39
 
39
40
int G_begin_geodesic_equation(double lon1, double lat1, double lon2,
40
41
                              double lat2)
46
47
    adjust_lat(&lat1);
47
48
    adjust_lat(&lat2);
48
49
    if (lon1 > lon2) {
49
 
        register double temp;
50
 
 
51
 
        SWAP(lon1, lon2);
52
 
        SWAP(lat1, lat2);
 
50
        double temp;
 
51
        temp = lon1; lon1 = lon2; lon2 = temp;
 
52
        temp = lat1; lat1 = lat2; lat2 = temp;
53
53
    }
54
54
    if (lon1 == lon2) {
55
 
        A = B = 0.0;
 
55
        st->A = st->B = 0.0;
56
56
        return 0;
57
57
    }
58
58
    lon1 = Radians(lon1);
64
64
    tan1 = tan(lat1);
65
65
    tan2 = tan(lat2);
66
66
 
67
 
    A = (tan2 * cos(lon1) - tan1 * cos(lon2)) / sin21;
68
 
    B = (tan2 * sin(lon1) - tan1 * sin(lon2)) / sin21;
 
67
    st->A = (tan2 * cos(lon1) - tan1 * cos(lon2)) / sin21;
 
68
    st->B = (tan2 * sin(lon1) - tan1 * sin(lon2)) / sin21;
69
69
 
70
70
    return 1;
71
71
}
77
77
    adjust_lon(&lon);
78
78
    lon = Radians(lon);
79
79
 
80
 
    return Degrees(atan(A * sin(lon) - B * cos(lon)));
 
80
    return Degrees(atan(st->A * sin(lon) - st->B * cos(lon)));
81
81
}
82
82
 
83
 
static int adjust_lon(double *lon)
 
83
static void adjust_lon(double *lon)
84
84
{
85
85
    while (*lon > 180.0)
86
86
        *lon -= 360.0;
87
87
    while (*lon < -180.0)
88
88
        *lon += 360.0;
89
 
 
90
 
    return 0;
91
89
}
92
90
 
93
 
static int adjust_lat(double *lat)
 
91
static void adjust_lat(double *lat)
94
92
{
95
93
    if (*lat > 90.0)
96
94
        *lat = 90.0;
97
95
    if (*lat < -90.0)
98
96
        *lat = -90.0;
99
 
 
100
 
    return 0;
101
97
}