blob: 3839809eeef7216a314be9d744d00218afc1aed7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
/* dervative of (*P->fwd) projection */
#define PJ_LIB__
#include <math.h>
#include "proj.h"
#include "projects.h"
int pj_deriv(PJ_LP lp, double h, const PJ *P, struct DERIVS *der) {
PJ_XY t;
/* get rid of constness until we can do it for real */
PJ *Q = (PJ *) P;
if (nullptr==Q->fwd)
return 1;
lp.lam += h;
lp.phi += h;
if (fabs(lp.phi) > M_HALFPI)
return 1;
h += h;
t = (*Q->fwd)(lp, Q);
if (t.x == HUGE_VAL)
return 1;
der->x_l = t.x;
der->y_p = t.y;
der->x_p = t.x;
der->y_l = t.y;
lp.phi -= h;
if (fabs(lp.phi) > M_HALFPI)
return 1;
t = (*Q->fwd)(lp, Q);
if (t.x == HUGE_VAL)
return 1;
der->x_l += t.x;
der->y_p -= t.y;
der->x_p -= t.x;
der->y_l += t.y;
lp.lam -= h;
t = (*Q->fwd)(lp, Q);
if (t.x == HUGE_VAL)
return 1;
der->x_l -= t.x;
der->y_p -= t.y;
der->x_p -= t.x;
der->y_l -= t.y;
lp.phi += h;
t = (*Q->fwd)(lp, Q);
if (t.x == HUGE_VAL)
return 1;
der->x_l -= t.x;
der->y_p += t.y;
der->x_p += t.x;
der->y_l -= t.y;
h += h;
der->x_l /= h;
der->y_p /= h;
der->x_p /= h;
der->y_l /= h;
return 0;
}
|