Skip to content

Commit

Permalink
add cmath and/or _USE_MATH_DEFINES for MSVC in proj4 files
Browse files Browse the repository at this point in the history
  • Loading branch information
allixender authored and sahrk committed Nov 13, 2024
1 parent 7832a02 commit 11b5a9f
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 49 deletions.
14 changes: 9 additions & 5 deletions src/lib/proj4lib/include/proj4.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef PROJ4_H
#define PROJ4_H

#define _USE_MATH_DEFINES
#include <math.h>
#include <stdlib.h>
/*
Expand All @@ -21,13 +22,17 @@ extern long double usgs_hypot(long double, long double);

/* some useful constants */

#define FORTPI M_PI_4
#define PI M_PI
#define TWOPI 6.28318530717958647692528676655900576L
#define FORTPI M_PI_4
#define PI M_PI
#define TWOPI 6.28318530717958647692528676655900576L
#define RAD_TO_DEG M_180_PI
#define DEG_TO_RAD M_PI_180

typedef union { long double f; int i; char *s; } PVALUE;
typedef union {
long double f;
int i;
char *s;
} PVALUE;

/* procedure prototypes */

Expand All @@ -49,4 +54,3 @@ long double pj_authlat(long double, long double *);
*/

#endif

17 changes: 9 additions & 8 deletions src/lib/proj4lib/lib/adjlon.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
/* reduce argument to range +/- PI */
#ifndef lint
//static const char SCCSID[]="@(#)adjlon.c 4.3 93/06/12 GIE REL";
// static const char SCCSID[]="@(#)adjlon.c 4.3 93/06/12 GIE
// REL";
#endif
#define _USE_MATH_DEFINES
#include <math.h>
/* note: PI adjusted high
** approx. true val: 3.14159265358979323844
*/
#define SPI 3.14159265359
#define TWOPI 6.2831853071795864769
long double
adjlon (long double lon) {
while ( fabsl(lon) > SPI )
lon += lon < 0. ? TWOPI : -TWOPI;
return( lon );
#define SPI 3.14159265359
#define TWOPI 6.2831853071795864769
long double adjlon(long double lon) {
while (fabsl(lon) > SPI)
lon += lon < 0. ? TWOPI : -TWOPI;
return (lon);
}
39 changes: 20 additions & 19 deletions src/lib/proj4lib/lib/pj_phi2.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
/* determine latitude angle phi-2 */
#ifndef lint
//static const char SCCSID[]="@(#)pj_phi2.c 4.3 93/06/12 GIE REL";
// static const char SCCSID[]="@(#)pj_phi2.c 4.3 93/06/12 GIE
// REL";
#endif
#include "proj4.h"
#define _USE_MATH_DEFINES
#include <math.h>

#define TOL 1.0e-10
#define N_ITER 15

long double
pj_phi2(long double ts, long double e) {
long double eccnth, Phi, con, dphi;
int i;
long double pj_phi2(long double ts, long double e) {
long double eccnth, Phi, con, dphi;
int i;

eccnth = .5 * e;
Phi = M_PI_2 - 2. * atan (ts);
i = N_ITER;
do {
con = e * sin (Phi);
dphi = M_PI_2 - 2. * atan (ts * pow((1. - con) /
(1. + con), eccnth)) - Phi;
Phi += dphi;
} while ( fabsl(dphi) > TOL && --i);
/*
if (i <= 0)
pj_errno = -18;
*/
return Phi;
eccnth = .5 * e;
Phi = M_PI_2 - 2. * atan(ts);
i = N_ITER;
do {
con = e * sin(Phi);
dphi = M_PI_2 - 2. * atan(ts * pow((1. - con) / (1. + con), eccnth)) - Phi;
Phi += dphi;
} while (fabsl(dphi) > TOL && --i);
/*
if (i <= 0)
pj_errno = -18;
*/
return Phi;
}
23 changes: 12 additions & 11 deletions src/lib/proj4lib/lib/pj_qsfn.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
/* determine small q */
#ifndef lint
//static const char SCCSID[]="@(#)pj_qsfn.c 4.3 93/06/12 GIE REL";
// static const char SCCSID[]="@(#)pj_qsfn.c 4.3 93/06/12 GIE
// REL";
#endif
#define _USE_MATH_DEFINES
#include <math.h>

# define EPSILON 1.0e-7
long double
pj_qsfn(long double sinphi, long double e, long double one_es) {
long double con;
#define EPSILON 1.0e-7
long double pj_qsfn(long double sinphi, long double e, long double one_es) {
long double con;

if (e >= EPSILON) {
con = e * sinphi;
return (one_es * (sinphi / (1. - con * con) -
(.5 / e) * log ((1. - con) / (1. + con))));
} else
return (sinphi + sinphi);
if (e >= EPSILON) {
con = e * sinphi;
return (one_es * (sinphi / (1. - con * con) -
(.5 / e) * log((1. - con) / (1. + con))));
} else
return (sinphi + sinphi);
}
13 changes: 7 additions & 6 deletions src/lib/proj4lib/lib/pj_tsfn.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* determine small t */
#ifndef lint
//static const char SCCSID[]="@(#)pj_tsfn.c 4.3 93/06/12 GIE REL";
// static const char SCCSID[]="@(#)pj_tsfn.c 4.3 93/06/12 GIE
// REL";
#endif
#define _USE_MATH_DEFINES
#include <math.h>
long double
pj_tsfn(long double phi, long double sinphi, long double e) {
sinphi *= e;
return (tan (.5 * (M_PI_2 - phi)) /
pow((1. - sinphi) / (1. + sinphi), .5 * e));
long double pj_tsfn(long double phi, long double sinphi, long double e) {
sinphi *= e;
return (tan(.5 * (M_PI_2 - phi)) /
pow((1. - sinphi) / (1. + sinphi), .5 * e));
}

0 comments on commit 11b5a9f

Please sign in to comment.