diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index aeca8e698d..573d34e28f 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -63,7 +63,8 @@ jobs: set PROJ_DIR=%GITHUB_WORKSPACE%\proj_dir # Not directly linked to BUILD_SHARED_LIBS, but a way to test different C++ standard versions if "${{ env.BUILD_SHARED_LIBS }}"=="ON" (set EXTRA_CXX_FLAGS="/std:c++20") - cmake -DCMAKE_BUILD_TYPE="${{ env.BUILD_TYPE }}" -DBUILD_SHARED_LIBS="${{ env.BUILD_SHARED_LIBS }}" -DCMAKE_C_FLAGS="/WX" -DCMAKE_CXX_FLAGS="/WX %EXTRA_CXX_FLAGS%" -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_INSTALL_PREFIX="%PROJ_DIR%" -DPROJ_DB_CACHE_DIR=%PROJ_DB_CACHE_DIR% .. + if "${{ env.BUILD_TYPE }}"=="Release" (set CMAKE_UNITY_BUILD_OPT="-DCMAKE_UNITY_BUILD=ON") + cmake -DCMAKE_BUILD_TYPE="${{ env.BUILD_TYPE }}" -DBUILD_SHARED_LIBS="${{ env.BUILD_SHARED_LIBS }}" -DCMAKE_C_FLAGS="/WX" -DCMAKE_CXX_FLAGS="/WX %EXTRA_CXX_FLAGS%" -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_INSTALL_PREFIX="%PROJ_DIR%" -DPROJ_DB_CACHE_DIR=%PROJ_DB_CACHE_DIR% %CMAKE_UNITY_BUILD_OPT% .. ninja -v ninja install dir %PROJ_DIR%\bin @@ -136,7 +137,7 @@ jobs: PROJ_DIR=${GITHUB_WORKSPACE}/proj_dir mkdir ${PROJ_BUILD} cd ${PROJ_BUILD} - cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DBUILD_SHARED_LIBS=${{ env.BUILD_SHARED_LIBS }} -DCMAKE_INSTALL_PREFIX="${PROJ_DIR}" -DCMAKE_C_FLAGS="-Werror" -DCMAKE_CXX_FLAGS="-Werror" -DUSE_CCACHE=ON -DPROJ_DB_CACHE_DIR=$HOME/.ccache .. + cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DBUILD_SHARED_LIBS=${{ env.BUILD_SHARED_LIBS }} -DCMAKE_INSTALL_PREFIX="${PROJ_DIR}" -DCMAKE_C_FLAGS="-Werror" -DCMAKE_CXX_FLAGS="-Werror" -DUSE_CCACHE=ON -DCMAKE_UNITY_BUILD=ON -DPROJ_DB_CACHE_DIR=$HOME/.ccache .. make -j 2 make install ls ${PROJ_DIR}/bin diff --git a/docs/source/install.rst b/docs/source/install.rst index 64cae1dfde..9e22fe7f31 100644 --- a/docs/source/install.rst +++ b/docs/source/install.rst @@ -315,6 +315,17 @@ All cached entries can be viewed using ``cmake -LAH`` from a build directory. :envvar:`OSGEO4W_ROOT` (if set), otherwise is ``c:/OSGeo4W``. Default for Unix-like is ``/usr/local/``. +.. option:: CMAKE_UNITY_BUILD=OFF + + .. versionadded:: 9.4 + + Default is OFF. This can be set to ON to build PROJ using the + https://cmake.org/cmake/help/latest/variable/CMAKE_UNITY_BUILD.html feature. + This helps speeding PROJ build times. This feature is still considered + experimental for now, and could hide subtle bugs (we are not aware of + any at writing time though). We don't recommend it for mission critical + builds. + .. option:: ENABLE_IPO=OFF Build library using the compiler's `interprocedural optimization diff --git a/include/proj/internal/lru_cache.hpp b/include/proj/internal/lru_cache.hpp index e9f177c713..f343ef1d01 100644 --- a/include/proj/internal/lru_cache.hpp +++ b/include/proj/internal/lru_cache.hpp @@ -73,7 +73,7 @@ template struct KeyValuePair { K key; V value; - KeyValuePair(const K &k, const V &v) : key(k), value(v) {} + KeyValuePair(const K &keyIn, const V &v) : key(keyIn), value(v) {} }; /** @@ -122,17 +122,17 @@ class Cache { cache_.clear(); keys_.clear(); } - void insert(const Key &k, const Value &v) { + void insert(const Key &key, const Value &v) { Guard g(lock_); - const auto iter = cache_.find(k); + const auto iter = cache_.find(key); if (iter != cache_.end()) { iter->second->value = v; keys_.splice(keys_.begin(), keys_, iter->second); return; } - keys_.emplace_front(k, v); - cache_[k] = keys_.begin(); + keys_.emplace_front(key, v); + cache_[key] = keys_.begin(); prune(); } bool tryGet(const Key &kIn, Value &vOut) { @@ -149,9 +149,9 @@ class Cache { * The const reference returned here is only * guaranteed to be valid till the next insert/delete */ - const Value &get(const Key &k) { + const Value &get(const Key &key) { Guard g(lock_); - const auto iter = cache_.find(k); + const auto iter = cache_.find(key); if (iter == cache_.end()) { throw KeyNotFound(); } @@ -163,9 +163,9 @@ class Cache { * The const reference returned here is only * guaranteed to be valid till the next insert/delete */ - const Value *getPtr(const Key &k) { + const Value *getPtr(const Key &key) { Guard g(lock_); - const auto iter = cache_.find(k); + const auto iter = cache_.find(key); if (iter == cache_.end()) { return nullptr; } @@ -176,10 +176,10 @@ class Cache { /** * returns a copy of the stored object (if found) */ - Value getCopy(const Key &k) { return get(k); } - bool remove(const Key &k) { + Value getCopy(const Key &key) { return get(key); } + bool remove(const Key &key) { Guard g(lock_); - auto iter = cache_.find(k); + auto iter = cache_.find(key); if (iter == cache_.end()) { return false; } @@ -187,9 +187,9 @@ class Cache { cache_.erase(iter); return true; } - bool contains(const Key &k) { + bool contains(const Key &key) { Guard g(lock_); - return cache_.find(k) != cache_.end(); + return cache_.find(key) != cache_.end(); } size_t getMaxSize() const { return maxSize_; } diff --git a/src/apps/CMakeLists.txt b/src/apps/CMakeLists.txt index 5c63cab787..d3389883f2 100644 --- a/src/apps/CMakeLists.txt +++ b/src/apps/CMakeLists.txt @@ -1,3 +1,5 @@ +set(CMAKE_UNITY_BUILD OFF) + # Configure executable builds option(BUILD_APPS "Build PROJ applications (default value for BUILD_CCT, BUILD_CS2CS, etc.)" diff --git a/src/conversions/axisswap.cpp b/src/conversions/axisswap.cpp index 1435343fa9..22f6a9adc4 100644 --- a/src/conversions/axisswap.cpp +++ b/src/conversions/axisswap.cpp @@ -52,7 +52,6 @@ It is only necessary to specify the axes that are affected by the swap * ***********************************************************************/ -#define PJ_LIB_ #include #include #include @@ -65,7 +64,7 @@ It is only necessary to specify the axes that are affected by the swap PROJ_HEAD(axisswap, "Axis ordering"); namespace { // anonymous namespace -struct pj_opaque { +struct pj_axisswap_data { unsigned int axis[4]; int sign[4]; }; @@ -73,8 +72,8 @@ struct pj_opaque { static int sign(int x) { return (x > 0) - (x < 0); } -static PJ_XY forward_2d(PJ_LP lp, PJ *P) { - struct pj_opaque *Q = (struct pj_opaque *)P->opaque; +static PJ_XY pj_axisswap_forward_2d(PJ_LP lp, PJ *P) { + struct pj_axisswap_data *Q = (struct pj_axisswap_data *)P->opaque; PJ_XY xy; double in[2] = {lp.lam, lp.phi}; @@ -83,8 +82,8 @@ static PJ_XY forward_2d(PJ_LP lp, PJ *P) { return xy; } -static PJ_LP reverse_2d(PJ_XY xy, PJ *P) { - struct pj_opaque *Q = (struct pj_opaque *)P->opaque; +static PJ_LP pj_axisswap_reverse_2d(PJ_XY xy, PJ *P) { + struct pj_axisswap_data *Q = (struct pj_axisswap_data *)P->opaque; unsigned int i; PJ_COORD out, in; @@ -98,8 +97,8 @@ static PJ_LP reverse_2d(PJ_XY xy, PJ *P) { return out.lp; } -static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P) { - struct pj_opaque *Q = (struct pj_opaque *)P->opaque; +static PJ_XYZ pj_axisswap_forward_3d(PJ_LPZ lpz, PJ *P) { + struct pj_axisswap_data *Q = (struct pj_axisswap_data *)P->opaque; unsigned int i; PJ_COORD out, in; @@ -114,8 +113,8 @@ static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P) { return out.xyz; } -static PJ_LPZ reverse_3d(PJ_XYZ xyz, PJ *P) { - struct pj_opaque *Q = (struct pj_opaque *)P->opaque; +static PJ_LPZ pj_axisswap_reverse_3d(PJ_XYZ xyz, PJ *P) { + struct pj_axisswap_data *Q = (struct pj_axisswap_data *)P->opaque; unsigned int i; PJ_COORD in, out; @@ -134,8 +133,8 @@ static void swap_xy_4d(PJ_COORD &coo, PJ *) { std::swap(coo.xyzt.x, coo.xyzt.y); } -static void forward_4d(PJ_COORD &coo, PJ *P) { - struct pj_opaque *Q = (struct pj_opaque *)P->opaque; +static void pj_axisswap_forward_4d(PJ_COORD &coo, PJ *P) { + struct pj_axisswap_data *Q = (struct pj_axisswap_data *)P->opaque; unsigned int i; PJ_COORD out; @@ -144,8 +143,8 @@ static void forward_4d(PJ_COORD &coo, PJ *P) { coo = out; } -static void reverse_4d(PJ_COORD &coo, PJ *P) { - struct pj_opaque *Q = (struct pj_opaque *)P->opaque; +static void pj_axisswap_reverse_4d(PJ_COORD &coo, PJ *P) { + struct pj_axisswap_data *Q = (struct pj_axisswap_data *)P->opaque; unsigned int i; PJ_COORD out; @@ -156,10 +155,10 @@ static void reverse_4d(PJ_COORD &coo, PJ *P) { } /***********************************************************************/ -PJ *CONVERSION(axisswap, 0) { +PJ *PJ_CONVERSION(axisswap, 0) { /***********************************************************************/ - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_axisswap_data *Q = static_cast( + calloc(1, sizeof(struct pj_axisswap_data))); char *s; unsigned int i, j, n = 0; @@ -266,12 +265,12 @@ PJ *CONVERSION(axisswap, 0) { /* only map fwd/inv functions that are possible with the given axis setup */ if (n == 4) { - P->fwd4d = forward_4d; - P->inv4d = reverse_4d; + P->fwd4d = pj_axisswap_forward_4d; + P->inv4d = pj_axisswap_reverse_4d; } if (n == 3 && Q->axis[0] < 3 && Q->axis[1] < 3 && Q->axis[2] < 3) { - P->fwd3d = forward_3d; - P->inv3d = reverse_3d; + P->fwd3d = pj_axisswap_forward_3d; + P->inv3d = pj_axisswap_reverse_3d; } if (n == 2) { if (Q->axis[0] == 1 && Q->sign[0] == 1 && Q->axis[1] == 0 && @@ -279,8 +278,8 @@ PJ *CONVERSION(axisswap, 0) { P->fwd4d = swap_xy_4d; P->inv4d = swap_xy_4d; } else if (Q->axis[0] < 2 && Q->axis[1] < 2) { - P->fwd = forward_2d; - P->inv = reverse_2d; + P->fwd = pj_axisswap_forward_2d; + P->inv = pj_axisswap_reverse_2d; } } diff --git a/src/conversions/cart.cpp b/src/conversions/cart.cpp index 4fc8210935..286aef3333 100644 --- a/src/conversions/cart.cpp +++ b/src/conversions/cart.cpp @@ -40,8 +40,6 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ -#define PJ_LIB_ - #include "proj_internal.h" #include @@ -224,7 +222,7 @@ static PJ_LP cart_reverse(PJ_XY xy, PJ *P) { } /*********************************************************************/ -PJ *CONVERSION(cart, 1) { +PJ *PJ_CONVERSION(cart, 1) { /*********************************************************************/ P->fwd3d = cartesian; P->inv3d = geodetic; diff --git a/src/conversions/geoc.cpp b/src/conversions/geoc.cpp index 4f8d14988b..a1efc1708d 100644 --- a/src/conversions/geoc.cpp +++ b/src/conversions/geoc.cpp @@ -26,8 +26,6 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ -#define PJ_LIB_ - #include #include "proj.h" @@ -45,7 +43,7 @@ static void inverse(PJ_COORD &coo, PJ *P) { coo = pj_geocentric_latitude(P, PJ_INV, coo); } -static PJ *CONVERSION(geoc, 1) { +static PJ *PJ_CONVERSION(geoc, 1) { P->inv4d = inverse; P->fwd4d = forward; diff --git a/src/conversions/geocent.cpp b/src/conversions/geocent.cpp index a2bc19fe73..cc8b259154 100644 --- a/src/conversions/geocent.cpp +++ b/src/conversions/geocent.cpp @@ -27,8 +27,6 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ -#define PJ_LIB_ - #include "proj.h" #include "proj_internal.h" @@ -50,7 +48,7 @@ static PJ_LP inverse(PJ_XY xy, PJ *P) { return lp; } -PJ *CONVERSION(geocent, 0) { +PJ *PJ_CONVERSION(geocent, 0) { P->is_geocent = 1; P->x0 = 0.0; P->y0 = 0.0; diff --git a/src/conversions/noop.cpp b/src/conversions/noop.cpp index a153ca7f7b..5737417ff8 100644 --- a/src/conversions/noop.cpp +++ b/src/conversions/noop.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include "proj_internal.h" @@ -6,7 +6,7 @@ PROJ_HEAD(noop, "No operation"); static void noop(PJ_COORD &, PJ *) {} -PJ *CONVERSION(noop, 0) { +PJ *PJ_CONVERSION(noop, 0) { P->fwd4d = noop; P->inv4d = noop; P->left = PJ_IO_UNITS_WHATEVER; diff --git a/src/conversions/set.cpp b/src/conversions/set.cpp index 9e11c98475..cfc4df31b5 100644 --- a/src/conversions/set.cpp +++ b/src/conversions/set.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include "proj_internal.h" #include diff --git a/src/conversions/topocentric.cpp b/src/conversions/topocentric.cpp index 63e389cbef..134004ab59 100644 --- a/src/conversions/topocentric.cpp +++ b/src/conversions/topocentric.cpp @@ -25,8 +25,6 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ -#define PJ_LIB_ - #include "proj_internal.h" #include #include @@ -75,7 +73,7 @@ static void topocentric_inv(PJ_COORD &coo, PJ *P) { } /*********************************************************************/ -PJ *CONVERSION(topocentric, 1) { +PJ *PJ_CONVERSION(topocentric, 1) { /*********************************************************************/ struct pj_opaque *Q = static_cast(calloc(1, sizeof(struct pj_opaque))); diff --git a/src/conversions/unitconvert.cpp b/src/conversions/unitconvert.cpp index 08a7dfc9cd..182fe9498a 100644 --- a/src/conversions/unitconvert.cpp +++ b/src/conversions/unitconvert.cpp @@ -63,8 +63,6 @@ Last update: 2017-05-16 * ***********************************************************************/ -#define PJ_LIB_ - #include #include #include @@ -437,7 +435,7 @@ static double get_unit_conversion_factor(const char *name, int *p_is_linear, } /***********************************************************************/ -PJ *CONVERSION(unitconvert, 0) { +PJ *PJ_CONVERSION(unitconvert, 0) { /***********************************************************************/ struct pj_opaque_unitconvert *Q = static_cast( diff --git a/src/deriv.cpp b/src/deriv.cpp index b13fe4c2d5..aff54a647c 100644 --- a/src/deriv.cpp +++ b/src/deriv.cpp @@ -1,5 +1,4 @@ /* dervative of (*P->fwd) projection */ -#define PJ_LIB_ #include diff --git a/src/factors.cpp b/src/factors.cpp index 86e391ec2b..1d975055ab 100644 --- a/src/factors.cpp +++ b/src/factors.cpp @@ -1,5 +1,5 @@ /* projection scale factors */ -#define PJ_LIB_ + #include "proj.h" #include "proj_internal.h" #include diff --git a/src/gauss.cpp b/src/gauss.cpp index 3de7fd7454..04858748d8 100644 --- a/src/gauss.cpp +++ b/src/gauss.cpp @@ -23,7 +23,6 @@ ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#define PJ_LIB_ #include #include diff --git a/src/init.cpp b/src/init.cpp index ff6f558709..6567af1701 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -27,8 +27,6 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ -#define PJ_LIB_ - #include #include #include diff --git a/src/iso19111/operation/parammappings.cpp b/src/iso19111/operation/parammappings.cpp index 1f1515ad2a..00b9b46cce 100644 --- a/src/iso19111/operation/parammappings.cpp +++ b/src/iso19111/operation/parammappings.cpp @@ -922,7 +922,7 @@ const MethodMapping *getProjectionMethodMappings(size_t &nElts) { #define METHOD_NAME_CODE(method) \ { EPSG_NAME_METHOD_##method, EPSG_CODE_METHOD_##method } -const struct MethodNameCode methodNameCodes[] = { +const struct MethodNameCode methodNameCodesList[] = { // Projection methods METHOD_NAME_CODE(TRANSVERSE_MERCATOR), METHOD_NAME_CODE(TRANSVERSE_MERCATOR_SOUTH_ORIENTATED), @@ -1011,8 +1011,8 @@ const struct MethodNameCode methodNameCodes[] = { }; const MethodNameCode *getMethodNameCodes(size_t &nElts) { - nElts = sizeof(methodNameCodes) / sizeof(methodNameCodes[0]); - return methodNameCodes; + nElts = sizeof(methodNameCodesList) / sizeof(methodNameCodesList[0]); + return methodNameCodesList; } #define PARAM_NAME_CODE(method) \ diff --git a/src/lib_proj.cmake b/src/lib_proj.cmake index c49310f16c..7409e6f387 100644 --- a/src/lib_proj.cmake +++ b/src/lib_proj.cmake @@ -258,6 +258,20 @@ set(SRC_LIBPROJ_CORE ${CMAKE_CURRENT_BINARY_DIR}/proj_config.h ) +if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16) + set_property(SOURCE list.cpp # because if sets DO_NOT_DEFINE_PROJ_HEAD + transformations/defmodel.cpp # Evaluator class conflict + transformations/tinshift.cpp # Evaluator class conflict + wkt1_parser.cpp + wkt2_parser.cpp + wkt1_generated_parser.c + wkt2_generated_parser.c + PROPERTY SKIP_UNITY_BUILD_INCLUSION ON) + if(WIN32) + set_property(SOURCE networkfilemanager.cpp PROPERTY SKIP_UNITY_BUILD_INCLUSION ON) + endif() +endif () + set(HEADERS_LIBPROJ proj.h proj_experimental.h diff --git a/src/list.cpp b/src/list.cpp index 13edbf5d61..0b3ccf07c2 100644 --- a/src/list.cpp +++ b/src/list.cpp @@ -1,6 +1,8 @@ /* Projection System: default list of projections */ +#define DO_NOT_DEFINE_PROJ_HEAD + #include "proj.h" #include "proj_internal.h" diff --git a/src/networkfilemanager.cpp b/src/networkfilemanager.cpp index 9bdc069460..35358e6782 100644 --- a/src/networkfilemanager.cpp +++ b/src/networkfilemanager.cpp @@ -1955,24 +1955,25 @@ NS_PROJ_END // --------------------------------------------------------------------------- #ifdef WIN32 -static const char dir_chars[] = "/\\"; +static const char nfm_dir_chars[] = "/\\"; #else -static const char dir_chars[] = "/"; +static const char nfm_dir_chars[] = "/"; #endif -static bool is_tilde_slash(const char *name) { - return *name == '~' && strchr(dir_chars, name[1]); +static bool nfm_is_tilde_slash(const char *name) { + return *name == '~' && strchr(nfm_dir_chars, name[1]); } -static bool is_rel_or_absolute_filename(const char *name) { - return strchr(dir_chars, *name) || - (*name == '.' && strchr(dir_chars, name[1])) || - (!strncmp(name, "..", 2) && strchr(dir_chars, name[2])) || - (name[0] != '\0' && name[1] == ':' && strchr(dir_chars, name[2])); +static bool nfm_is_rel_or_absolute_filename(const char *name) { + return strchr(nfm_dir_chars, *name) || + (*name == '.' && strchr(nfm_dir_chars, name[1])) || + (!strncmp(name, "..", 2) && strchr(nfm_dir_chars, name[2])) || + (name[0] != '\0' && name[1] == ':' && + strchr(nfm_dir_chars, name[2])); } static std::string build_url(PJ_CONTEXT *ctx, const char *name) { - if (!is_tilde_slash(name) && !is_rel_or_absolute_filename(name) && + if (!nfm_is_tilde_slash(name) && !nfm_is_rel_or_absolute_filename(name) && !starts_with(name, "http://") && !starts_with(name, "https://")) { std::string remote_file(proj_context_get_url_endpoint(ctx)); if (!remote_file.empty()) { diff --git a/src/pipeline.cpp b/src/pipeline.cpp index 97bd2cbb05..7cc2ea62ff 100644 --- a/src/pipeline.cpp +++ b/src/pipeline.cpp @@ -97,8 +97,6 @@ Thomas Knudsen, thokn@sdfe.dk, 2016-05-20 * ********************************************************************************/ -#define PJ_LIB_ - #include #include #include diff --git a/src/proj_internal.h b/src/proj_internal.h index f2a9a9a98b..fb558ee6a9 100644 --- a/src/proj_internal.h +++ b/src/proj_internal.h @@ -838,7 +838,7 @@ struct pj_ctx { static pj_ctx createDefault(); }; -#ifdef PJ_LIB_ +#ifndef DO_NOT_DEFINE_PROJ_HEAD #define PROJ_HEAD(name, desc) static const char des_##name[] = desc #define OPERATION(name, NEED_ELLPS) \ @@ -865,14 +865,14 @@ struct pj_ctx { PJ *pj_projection_specific_setup_##name(PJ *P) /* In ISO19000 lingo, an operation is either a conversion or a transformation */ -#define CONVERSION(name, need_ellps) OPERATION(name, need_ellps) -#define TRANSFORMATION(name, need_ellps) OPERATION(name, need_ellps) +#define PJ_CONVERSION(name, need_ellps) OPERATION(name, need_ellps) +#define PJ_TRANSFORMATION(name, need_ellps) OPERATION(name, need_ellps) /* In PROJ.4 a projection is a conversion taking angular input and giving scaled * linear output */ -#define PROJECTION(name) CONVERSION(name, 1) +#define PJ_PROJECTION(name) PJ_CONVERSION(name, 1) -#endif /* def PJ_LIB_ */ +#endif /* DO_NOT_DEFINE_PROJ_HEAD */ /* procedure prototypes */ double PROJ_DLL dmstor(const char *, char **); diff --git a/src/proj_mdist.cpp b/src/proj_mdist.cpp index fca9bf8bf9..b35d37d21c 100644 --- a/src/proj_mdist.cpp +++ b/src/proj_mdist.cpp @@ -27,7 +27,6 @@ ** and inverse on unit ellipsoid. ** Precision commensurate with double precision. */ -#define PJ_LIB_ #include #include diff --git a/src/projections/adams.cpp b/src/projections/adams.cpp index 5ae71c95dd..cdef83ec46 100644 --- a/src/projections/adams.cpp +++ b/src/projections/adams.cpp @@ -35,8 +35,6 @@ * https://en.wikipedia.org/wiki/Peirce_quincuncial_projection */ -#define PJ_LIB_ - #include #include @@ -70,7 +68,7 @@ enum peirce_shape { PEIRCE_Q_VERTICAL, }; -struct pj_opaque { +struct pj_adams_data { projection_type mode; peirce_shape pqshape; double scrollx = 0.0; @@ -113,8 +111,8 @@ static PJ_XY adams_forward(PJ_LP lp, PJ *P) { double a = 0., b = 0.; bool sm = false, sn = false; PJ_XY xy; - const struct pj_opaque *Q = - static_cast(P->opaque); + const struct pj_adams_data *Q = + static_cast(P->opaque); switch (Q->mode) { case GUYOU: @@ -386,9 +384,9 @@ static PJ_LP peirce_q_diamond_inverse(PJ_XY xy, PJ *P) { return pj_generic_inverse_2d(xy, P, lp, deltaXYTolerance); } -static PJ *setup(PJ *P, projection_type mode) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +static PJ *pj_adams_setup(PJ *P, projection_type mode) { + struct pj_adams_data *Q = static_cast( + calloc(1, sizeof(struct pj_adams_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); @@ -458,12 +456,15 @@ static PJ *setup(PJ *P, projection_type mode) { return P; } -PJ *PROJECTION(guyou) { return setup(P, GUYOU); } +PJ *PJ_PROJECTION(guyou) { return pj_adams_setup(P, GUYOU); } + +PJ *PJ_PROJECTION(peirce_q) { return pj_adams_setup(P, PEIRCE_Q); } -PJ *PROJECTION(peirce_q) { return setup(P, PEIRCE_Q); } +PJ *PJ_PROJECTION(adams_hemi) { return pj_adams_setup(P, ADAMS_HEMI); } -PJ *PROJECTION(adams_hemi) { return setup(P, ADAMS_HEMI); } +PJ *PJ_PROJECTION(adams_ws1) { return pj_adams_setup(P, ADAMS_WS1); } -PJ *PROJECTION(adams_ws1) { return setup(P, ADAMS_WS1); } +PJ *PJ_PROJECTION(adams_ws2) { return pj_adams_setup(P, ADAMS_WS2); } -PJ *PROJECTION(adams_ws2) { return setup(P, ADAMS_WS2); } +#undef TOL +#undef RSQRT2 diff --git a/src/projections/aea.cpp b/src/projections/aea.cpp index 528e815d98..21c46eb9f1 100644 --- a/src/projections/aea.cpp +++ b/src/projections/aea.cpp @@ -27,7 +27,6 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ -#define PJ_LIB_ #include "proj.h" #include "proj_internal.h" #include @@ -69,7 +68,7 @@ static double phi1_(double qs, double Te, double Tone_es) { } namespace { // anonymous namespace -struct pj_opaque { +struct pj_aea { double ec; double n; double c; @@ -84,20 +83,20 @@ struct pj_opaque { }; } // anonymous namespace -static PJ *destructor(PJ *P, int errlev) { /* Destructor */ +static PJ *pj_aea_destructor(PJ *P, int errlev) { /* Destructor */ if (nullptr == P) return nullptr; if (nullptr == P->opaque) return pj_default_destructor(P, errlev); - free(static_cast(P->opaque)->en); + free(static_cast(P->opaque)->en); return pj_default_destructor(P, errlev); } static PJ_XY aea_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoid/spheroid, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_aea *Q = static_cast(P->opaque); Q->rho = Q->c - (Q->ellips ? Q->n * pj_qsfn(sin(lp.phi), P->e, P->one_es) : Q->n2 * sin(lp.phi)); if (Q->rho < 0.) { @@ -113,7 +112,7 @@ static PJ_XY aea_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoid/spheroid, forward */ static PJ_LP aea_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoid/spheroid, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_aea *Q = static_cast(P->opaque); xy.y = Q->rho0 - xy.y; Q->rho = hypot(xy.x, xy.y); if (Q->rho != 0.0) { @@ -155,7 +154,7 @@ static PJ_LP aea_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoid/spheroid, inverse */ } static PJ *setup(PJ *P) { - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_aea *Q = static_cast(P->opaque); P->inv = aea_e_inverse; P->fwd = aea_e_forward; @@ -163,17 +162,17 @@ static PJ *setup(PJ *P) { if (fabs(Q->phi1) > M_HALFPI) { proj_log_error(P, _("Invalid value for lat_1: |lat_1| should be <= 90°")); - return destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); + return pj_aea_destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); } if (fabs(Q->phi2) > M_HALFPI) { proj_log_error(P, _("Invalid value for lat_2: |lat_2| should be <= 90°")); - return destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); + return pj_aea_destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); } if (fabs(Q->phi1 + Q->phi2) < EPS10) { proj_log_error(P, _("Invalid value for lat_1 and lat_2: |lat_1 + " "lat_2| should be > 0")); - return destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); + return pj_aea_destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); } double sinphi = sin(Q->phi1); Q->n = sinphi; @@ -185,7 +184,7 @@ static PJ *setup(PJ *P) { Q->en = pj_enfn(P->n); if (Q->en == nullptr) - return destructor(P, 0); + return pj_aea_destructor(P, 0); m1 = pj_msfn(sinphi, cosphi, P->es); ml1 = pj_qsfn(sinphi, P->e, P->one_es); if (secant) { /* secant cone */ @@ -196,13 +195,14 @@ static PJ *setup(PJ *P) { m2 = pj_msfn(sinphi, cosphi, P->es); ml2 = pj_qsfn(sinphi, P->e, P->one_es); if (ml2 == ml1) - return destructor(P, 0); + return pj_aea_destructor(P, 0); Q->n = (m1 * m1 - m2 * m2) / (ml2 - ml1); if (Q->n == 0) { // Not quite, but es is very close to 1... proj_log_error(P, _("Invalid value for eccentricity")); - return destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); + return pj_aea_destructor(P, + PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); } } Q->ec = 1. - .5 * P->one_es * log((1. - P->e) / (1. + P->e)) / P->e; @@ -222,28 +222,34 @@ static PJ *setup(PJ *P) { return P; } -PJ *PROJECTION(aea) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(aea) { + struct pj_aea *Q = + static_cast(calloc(1, sizeof(struct pj_aea))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; - P->destructor = destructor; + P->destructor = pj_aea_destructor; Q->phi1 = pj_param(P->ctx, P->params, "rlat_1").f; Q->phi2 = pj_param(P->ctx, P->params, "rlat_2").f; return setup(P); } -PJ *PROJECTION(leac) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(leac) { + struct pj_aea *Q = + static_cast(calloc(1, sizeof(struct pj_aea))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; - P->destructor = destructor; + P->destructor = pj_aea_destructor; Q->phi2 = pj_param(P->ctx, P->params, "rlat_1").f; Q->phi1 = pj_param(P->ctx, P->params, "bsouth").i ? -M_HALFPI : M_HALFPI; return setup(P); } + +#undef EPS10 +#undef TOL7 +#undef N_ITER +#undef EPSILON +#undef TOL diff --git a/src/projections/aeqd.cpp b/src/projections/aeqd.cpp index 783d2f9689..9bdb441d31 100644 --- a/src/projections/aeqd.cpp +++ b/src/projections/aeqd.cpp @@ -25,19 +25,18 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ -#define PJ_LIB_ #include "geodesic.h" #include "proj.h" #include "proj_internal.h" #include #include -namespace { // anonymous namespace +namespace pj_aeqd_ns { enum Mode { N_POLE = 0, S_POLE = 1, EQUIT = 2, OBLIQ = 3 }; -} // anonymous namespace +} namespace { // anonymous namespace -struct pj_opaque { +struct pj_aeqd_data { double sinph0; double cosph0; double *en; @@ -46,7 +45,7 @@ struct pj_opaque { double Mp; double He; double G; - enum Mode mode; + enum ::pj_aeqd_ns::Mode mode; struct geod_geodesic g; }; } // anonymous namespace @@ -63,13 +62,13 @@ static PJ *destructor(PJ *P, int errlev) { /* Destructor */ if (nullptr == P->opaque) return pj_default_destructor(P, errlev); - free(static_cast(P->opaque)->en); + free(static_cast(P->opaque)->en); return pj_default_destructor(P, errlev); } static PJ_XY e_guam_fwd(PJ_LP lp, PJ *P) { /* Guam elliptical */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_aeqd_data *Q = static_cast(P->opaque); double cosphi, sinphi, t; cosphi = cos(lp.phi); @@ -84,25 +83,25 @@ static PJ_XY e_guam_fwd(PJ_LP lp, PJ *P) { /* Guam elliptical */ static PJ_XY aeqd_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_aeqd_data *Q = static_cast(P->opaque); double coslam, cosphi, sinphi, rho; double azi1, azi2, s12; double lat1, lon1, lat2, lon2; coslam = cos(lp.lam); switch (Q->mode) { - case N_POLE: + case pj_aeqd_ns::N_POLE: coslam = -coslam; PROJ_FALLTHROUGH; - case S_POLE: + case pj_aeqd_ns::S_POLE: cosphi = cos(lp.phi); sinphi = sin(lp.phi); rho = fabs(Q->Mp - pj_mlfn(lp.phi, sinphi, cosphi, Q->en)); xy.x = rho * sin(lp.lam); xy.y = rho * coslam; break; - case EQUIT: - case OBLIQ: + case pj_aeqd_ns::EQUIT: + case pj_aeqd_ns::OBLIQ: if (fabs(lp.lam) < EPS10 && fabs(lp.phi - P->phi0) < EPS10) { xy.x = xy.y = 0.; break; @@ -124,9 +123,9 @@ static PJ_XY aeqd_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ static PJ_XY aeqd_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_aeqd_data *Q = static_cast(P->opaque); - if (Q->mode == EQUIT) { + if (Q->mode == pj_aeqd_ns::EQUIT) { const double cosphi = cos(lp.phi); const double sinphi = sin(lp.phi); const double coslam = cos(lp.lam); @@ -147,7 +146,7 @@ static PJ_XY aeqd_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ xy.x = xy.y * cosphi * sinlam; xy.y *= sinphi; } - } else if (Q->mode == OBLIQ) { + } else if (Q->mode == pj_aeqd_ns::OBLIQ) { const double cosphi = cos(lp.phi); const double sinphi = sin(lp.phi); const double coslam = cos(lp.lam); @@ -172,7 +171,7 @@ static PJ_XY aeqd_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ } else { double coslam = cos(lp.lam); double sinlam = sin(lp.lam); - if (Q->mode == N_POLE) { + if (Q->mode == pj_aeqd_ns::N_POLE) { lp.phi = -lp.phi; coslam = -coslam; } @@ -189,7 +188,7 @@ static PJ_XY aeqd_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP e_guam_inv(PJ_XY xy, PJ *P) { /* Guam elliptical */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_aeqd_data *Q = static_cast(P->opaque); double x2, t = 0.0; int i; @@ -206,7 +205,7 @@ static PJ_LP e_guam_inv(PJ_XY xy, PJ *P) { /* Guam elliptical */ static PJ_LP aeqd_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_aeqd_data *Q = static_cast(P->opaque); double azi1, azi2, s12, lat1, lon1, lat2, lon2; if ((s12 = hypot(xy.x, xy.y)) < EPS10) { @@ -214,7 +213,7 @@ static PJ_LP aeqd_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ lp.lam = 0.; return (lp); } - if (Q->mode == OBLIQ || Q->mode == EQUIT) { + if (Q->mode == pj_aeqd_ns::OBLIQ || Q->mode == pj_aeqd_ns::EQUIT) { lat1 = P->phi0 / DEG_TO_RAD; lon1 = 0; azi1 = atan2(xy.x, xy.y) / DEG_TO_RAD; // Clockwise from north @@ -222,16 +221,16 @@ static PJ_LP aeqd_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ lp.phi = lat2 * DEG_TO_RAD; lp.lam = lon2 * DEG_TO_RAD; } else { /* Polar */ - lp.phi = - pj_inv_mlfn(Q->mode == N_POLE ? Q->Mp - s12 : Q->Mp + s12, Q->en); - lp.lam = atan2(xy.x, Q->mode == N_POLE ? -xy.y : xy.y); + lp.phi = pj_inv_mlfn( + Q->mode == pj_aeqd_ns::N_POLE ? Q->Mp - s12 : Q->Mp + s12, Q->en); + lp.lam = atan2(xy.x, Q->mode == pj_aeqd_ns::N_POLE ? -xy.y : xy.y); } return lp; } static PJ_LP aeqd_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_aeqd_data *Q = static_cast(P->opaque); double cosc, c_rh, sinc; c_rh = hypot(xy.x, xy.y); @@ -246,10 +245,10 @@ static PJ_LP aeqd_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ lp.lam = 0.; return (lp); } - if (Q->mode == OBLIQ || Q->mode == EQUIT) { + if (Q->mode == pj_aeqd_ns::OBLIQ || Q->mode == pj_aeqd_ns::EQUIT) { sinc = sin(c_rh); cosc = cos(c_rh); - if (Q->mode == EQUIT) { + if (Q->mode == pj_aeqd_ns::EQUIT) { lp.phi = aasin(P->ctx, xy.y * sinc / c_rh); xy.x *= sinc; xy.y = cosc * c_rh; @@ -260,7 +259,7 @@ static PJ_LP aeqd_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ xy.x *= sinc * Q->cosph0; } lp.lam = xy.y == 0. ? 0. : atan2(xy.x, xy.y); - } else if (Q->mode == N_POLE) { + } else if (Q->mode == pj_aeqd_ns::N_POLE) { lp.phi = M_HALFPI - c_rh; lp.lam = atan2(xy.x, -xy.y); } else { @@ -270,9 +269,9 @@ static PJ_LP aeqd_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(aeqd) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(aeqd) { + struct pj_aeqd_data *Q = static_cast( + calloc(1, sizeof(struct pj_aeqd_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -281,15 +280,15 @@ PJ *PROJECTION(aeqd) { geod_init(&Q->g, 1, P->f); if (fabs(fabs(P->phi0) - M_HALFPI) < EPS10) { - Q->mode = P->phi0 < 0. ? S_POLE : N_POLE; + Q->mode = P->phi0 < 0. ? pj_aeqd_ns::S_POLE : pj_aeqd_ns::N_POLE; Q->sinph0 = P->phi0 < 0. ? -1. : 1.; Q->cosph0 = 0.; } else if (fabs(P->phi0) < EPS10) { - Q->mode = EQUIT; + Q->mode = pj_aeqd_ns::EQUIT; Q->sinph0 = 0.; Q->cosph0 = 1.; } else { - Q->mode = OBLIQ; + Q->mode = pj_aeqd_ns::OBLIQ; Q->sinph0 = sin(P->phi0); Q->cosph0 = cos(P->phi0); } @@ -305,14 +304,14 @@ PJ *PROJECTION(aeqd) { P->fwd = e_guam_fwd; } else { switch (Q->mode) { - case N_POLE: + case pj_aeqd_ns::N_POLE: Q->Mp = pj_mlfn(M_HALFPI, 1., 0., Q->en); break; - case S_POLE: + case pj_aeqd_ns::S_POLE: Q->Mp = pj_mlfn(-M_HALFPI, -1., 0., Q->en); break; - case EQUIT: - case OBLIQ: + case pj_aeqd_ns::EQUIT: + case pj_aeqd_ns::OBLIQ: Q->N1 = 1. / sqrt(1. - P->es * Q->sinph0 * Q->sinph0); Q->He = P->e / sqrt(P->one_es); Q->G = Q->sinph0 * Q->He; @@ -326,3 +325,6 @@ PJ *PROJECTION(aeqd) { return P; } + +#undef EPS10 +#undef TOL diff --git a/src/projections/airy.cpp b/src/projections/airy.cpp index 5996209f50..037ecafd28 100644 --- a/src/projections/airy.cpp +++ b/src/projections/airy.cpp @@ -26,7 +26,6 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ -#define PJ_LIB_ #include "proj.h" #include "proj_internal.h" #include @@ -38,7 +37,7 @@ enum Mode { N_POLE = 0, S_POLE = 1, EQUIT = 2, OBLIQ = 3 }; } // anonymous namespace namespace { // anonymous namespace -struct pj_opaque { +struct pj_airy { double p_halfpi; double sinph0; double cosph0; @@ -52,7 +51,7 @@ struct pj_opaque { static PJ_XY airy_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_airy *Q = static_cast(P->opaque); double sinlam, coslam, cosphi, sinphi, t, s, Krho, cosz; sinlam = sin(lp.lam); @@ -107,11 +106,11 @@ static PJ_XY airy_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ return xy; } -PJ *PROJECTION(airy) { +PJ *PJ_PROJECTION(airy) { double beta; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_airy *Q = + static_cast(calloc(1, sizeof(struct pj_airy))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); @@ -147,3 +146,5 @@ PJ *PROJECTION(airy) { P->es = 0.; return P; } + +#undef EPS diff --git a/src/projections/aitoff.cpp b/src/projections/aitoff.cpp index 79b3df0e89..fed9dfcc08 100644 --- a/src/projections/aitoff.cpp +++ b/src/projections/aitoff.cpp @@ -28,22 +28,20 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ -#define PJ_LIB_ - #include #include #include "proj.h" #include "proj_internal.h" -namespace { // anonymous namespace +namespace pj_aitoff_ns { enum Mode { AITOFF = 0, WINKEL_TRIPEL = 1 }; -} // anonymous namespace +} namespace { // anonymous namespace -struct pj_opaque { +struct pj_aitoff_data { double cosphi1; - enum Mode mode; + enum pj_aitoff_ns::Mode mode; }; } // anonymous namespace @@ -56,7 +54,7 @@ FORWARD(aitoff_s_forward); /* spheroid */ static PJ_XY aitoff_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_aitoff_data *Q = static_cast(P->opaque); double c, d; #if 0 @@ -74,7 +72,7 @@ static PJ_XY aitoff_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ xy.y *= d * sin(lp.phi); } else xy.x = xy.y = 0.; - if (Q->mode == WINKEL_TRIPEL) { + if (Q->mode == pj_aitoff_ns::WINKEL_TRIPEL) { xy.x = (xy.x + lp.lam * Q->cosphi1) * 0.5; xy.y = (xy.y + lp.phi) * 0.5; } @@ -105,7 +103,7 @@ static PJ_XY aitoff_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP aitoff_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_aitoff_data *Q = static_cast(P->opaque); int iter, MAXITER = 10, round = 0, MAXROUND = 20; double EPSILON = 1e-12, D, C, f1, f2, f1p, f1l, f2p, f2l, dp, dl, sl, sp, cp, cl, x, y; @@ -141,7 +139,7 @@ static PJ_LP aitoff_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ f1l = cp * cp * sl * sl / C + D * cp * cl * sp * sp; f2p = sp * sp * cl / C + D * sl * sl * cp; f2l = 0.5 * (sp * cp * sl / C - D * sp * cp * cp * sl * cl); - if (Q->mode == WINKEL_TRIPEL) { + if (Q->mode == pj_aitoff_ns::WINKEL_TRIPEL) { f1 = 0.5 * (f1 + lp.lam * Q->cosphi1); f2 = 0.5 * (f2 + lp.phi); f1p *= 0.5; @@ -167,7 +165,8 @@ static PJ_LP aitoff_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ lp.phi -= 2. * (lp.phi + M_PI_2); /* correct if symmetrical solution for Aitoff */ - if ((fabs(fabs(lp.phi) - M_PI_2) < EPSILON) && (Q->mode == AITOFF)) + if ((fabs(fabs(lp.phi) - M_PI_2) < EPSILON) && + (Q->mode == pj_aitoff_ns::AITOFF)) lp.lam = 0.; /* if pole in Aitoff, return longitude of 0 */ /* calculate x,y coordinates with solution obtained */ @@ -178,7 +177,7 @@ static PJ_LP aitoff_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ y *= D * sin(lp.phi); } else x = y = 0.; - if (Q->mode == WINKEL_TRIPEL) { + if (Q->mode == pj_aitoff_ns::WINKEL_TRIPEL) { x = (x + lp.lam * Q->cosphi1) * 0.5; y = (y + lp.phi) * 0.5; } @@ -197,32 +196,32 @@ static PJ_LP aitoff_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -static PJ *setup(PJ *P) { +static PJ *pj_aitoff_setup(PJ *P) { P->inv = aitoff_s_inverse; P->fwd = aitoff_s_forward; P->es = 0.; return P; } -PJ *PROJECTION(aitoff) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(aitoff) { + struct pj_aitoff_data *Q = static_cast( + calloc(1, sizeof(struct pj_aitoff_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; - Q->mode = AITOFF; - return setup(P); + Q->mode = pj_aitoff_ns::AITOFF; + return pj_aitoff_setup(P); } -PJ *PROJECTION(wintri) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(wintri) { + struct pj_aitoff_data *Q = static_cast( + calloc(1, sizeof(struct pj_aitoff_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; - Q->mode = WINKEL_TRIPEL; + Q->mode = pj_aitoff_ns::WINKEL_TRIPEL; if (pj_param(P->ctx, P->params, "tlat_1").i) { if ((Q->cosphi1 = cos(pj_param(P->ctx, P->params, "rlat_1").f)) == 0.) { proj_log_error( @@ -232,5 +231,5 @@ PJ *PROJECTION(wintri) { } } else /* 50d28' or acos(2/pi) */ Q->cosphi1 = 0.636619772367581343; - return setup(P); + return pj_aitoff_setup(P); } diff --git a/src/projections/august.cpp b/src/projections/august.cpp index d373979012..ccd5ada200 100644 --- a/src/projections/august.cpp +++ b/src/projections/august.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -26,7 +26,7 @@ static PJ_XY august_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ return (xy); } -PJ *PROJECTION(august) { +PJ *PJ_PROJECTION(august) { P->inv = nullptr; P->fwd = august_s_forward; P->es = 0.; diff --git a/src/projections/bacon.cpp b/src/projections/bacon.cpp index 7e054c1706..f8419f22ec 100644 --- a/src/projections/bacon.cpp +++ b/src/projections/bacon.cpp @@ -1,14 +1,15 @@ -#define HLFPI2 2.46740110027233965467 /* (pi/2)^2 */ -#define EPS 1e-10 -#define PJ_LIB_ + #include #include #include "proj.h" #include "proj_internal.h" +#define HLFPI2 2.46740110027233965467 /* (pi/2)^2 */ +#define EPS 1e-10 + namespace { // anonymous namespace -struct pj_opaque { +struct pj_bacon { int bacn; int ortl; }; @@ -20,7 +21,7 @@ PROJ_HEAD(bacon, "Bacon Globular") "\n\tMisc Sph, no inv"; static PJ_XY bacon_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_bacon *Q = static_cast(P->opaque); double ax, f; xy.y = Q->bacn ? M_HALFPI * sin(lp.phi) : lp.phi; @@ -39,9 +40,9 @@ static PJ_XY bacon_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ return (xy); } -PJ *PROJECTION(bacon) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(bacon) { + struct pj_bacon *Q = + static_cast(calloc(1, sizeof(struct pj_bacon))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -53,9 +54,9 @@ PJ *PROJECTION(bacon) { return P; } -PJ *PROJECTION(apian) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(apian) { + struct pj_bacon *Q = + static_cast(calloc(1, sizeof(struct pj_bacon))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -66,9 +67,9 @@ PJ *PROJECTION(apian) { return P; } -PJ *PROJECTION(ortel) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(ortel) { + struct pj_bacon *Q = + static_cast(calloc(1, sizeof(struct pj_bacon))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -79,3 +80,6 @@ PJ *PROJECTION(ortel) { P->fwd = bacon_s_forward; return P; } + +#undef HLFPI2 +#undef EPS diff --git a/src/projections/bertin1953.cpp b/src/projections/bertin1953.cpp index d2fca01263..832d762292 100644 --- a/src/projections/bertin1953.cpp +++ b/src/projections/bertin1953.cpp @@ -9,8 +9,6 @@ Port to PROJ by Philippe Rivière, 21 September 2018 */ -#define PJ_LIB_ - #include #include @@ -21,7 +19,7 @@ PROJ_HEAD(bertin1953, "Bertin 1953") "\n\tMisc Sph no inv."; namespace { // anonymous namespace -struct pj_opaque { +struct pj_bertin1953 { double cos_delta_phi, sin_delta_phi, cos_delta_gamma, sin_delta_gamma, deltaLambda; }; @@ -29,7 +27,7 @@ struct pj_opaque { static PJ_XY bertin1953_s_forward(PJ_LP lp, PJ *P) { PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_bertin1953 *Q = static_cast(P->opaque); double fu = 1.4, k = 12., w = 1.68, d; @@ -73,9 +71,9 @@ static PJ_XY bertin1953_s_forward(PJ_LP lp, PJ *P) { return xy; } -PJ *PROJECTION(bertin1953) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(bertin1953) { + struct pj_bertin1953 *Q = static_cast( + calloc(1, sizeof(struct pj_bertin1953))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; diff --git a/src/projections/bipc.cpp b/src/projections/bipc.cpp index 8a1416e71f..587187329a 100644 --- a/src/projections/bipc.cpp +++ b/src/projections/bipc.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -29,14 +29,14 @@ PROJ_HEAD(bipc, "Bipolar conic of western hemisphere") "\n\tConic Sph"; #define R104 1.81514242207410275904 namespace { // anonymous namespace -struct pj_opaque { +struct pj_bipc_data { int noskew; }; } // anonymous namespace static PJ_XY bipc_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_bipc_data *Q = static_cast(P->opaque); double cphi, sphi, tphi, t, al, Az, z, Av, cdlam, sdlam, r; int tag; @@ -117,7 +117,7 @@ static PJ_XY bipc_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP bipc_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_bipc_data *Q = static_cast(P->opaque); double t, r, rp, rl, al, z = 0.0, fAz, Az, s, c, Av; int neg, i; @@ -164,9 +164,9 @@ static PJ_LP bipc_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return (lp); } -PJ *PROJECTION(bipc) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(bipc) { + struct pj_bipc_data *Q = static_cast( + calloc(1, sizeof(struct pj_bipc_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -177,3 +177,23 @@ PJ *PROJECTION(bipc) { P->es = 0.; return P; } + +#undef EPS +#undef EPS10 +#undef ONEEPS +#undef NITER +#undef lamB +#undef n +#undef F +#undef Azab +#undef Azba +#undef T +#undef rhoc +#undef cAzc +#undef sAzc +#undef C45 +#undef S45 +#undef C20 +#undef S20 +#undef R110 +#undef R104 diff --git a/src/projections/boggs.cpp b/src/projections/boggs.cpp index 0a825d698f..4849da739f 100644 --- a/src/projections/boggs.cpp +++ b/src/projections/boggs.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include "proj.h" @@ -35,8 +35,14 @@ static PJ_XY boggs_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ return (xy); } -PJ *PROJECTION(boggs) { +PJ *PJ_PROJECTION(boggs) { P->es = 0.; P->fwd = boggs_s_forward; return P; } + +#undef NITER +#undef EPS +#undef FXC +#undef FXC2 +#undef FYC diff --git a/src/projections/bonne.cpp b/src/projections/bonne.cpp index 4ac4f41e2d..f5c31bb592 100644 --- a/src/projections/bonne.cpp +++ b/src/projections/bonne.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include "proj.h" #include "proj_internal.h" #include @@ -9,7 +9,7 @@ PROJ_HEAD(bonne, "Bonne (Werner lat_1=90)") #define EPS10 1e-10 namespace { // anonymous namespace -struct pj_opaque { +struct pj_bonne_data { double phi1; double cphi1; double am1; @@ -20,7 +20,7 @@ struct pj_opaque { static PJ_XY bonne_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_bonne_data *Q = static_cast(P->opaque); double rh, E, c; E = sin(lp.phi); @@ -39,7 +39,7 @@ static PJ_XY bonne_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ static PJ_XY bonne_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_bonne_data *Q = static_cast(P->opaque); double E, rh; rh = Q->cphi1 + Q->phi1 - lp.phi; @@ -54,7 +54,7 @@ static PJ_XY bonne_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP bonne_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_bonne_data *Q = static_cast(P->opaque); xy.y = Q->cphi1 - xy.y; const double rh = copysign(hypot(xy.x, xy.y), Q->phi1); @@ -79,7 +79,7 @@ static PJ_LP bonne_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ static PJ_LP bonne_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_bonne_data *Q = static_cast(P->opaque); xy.y = Q->am1 - xy.y; const double rh = copysign(hypot(xy.x, xy.y), Q->phi1); @@ -102,36 +102,36 @@ static PJ_LP bonne_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ return lp; } -static PJ *destructor(PJ *P, int errlev) { /* Destructor */ +static PJ *pj_bonne_destructor(PJ *P, int errlev) { /* Destructor */ if (nullptr == P) return nullptr; if (nullptr == P->opaque) return pj_default_destructor(P, errlev); - free(static_cast(P->opaque)->en); + free(static_cast(P->opaque)->en); return pj_default_destructor(P, errlev); } -PJ *PROJECTION(bonne) { +PJ *PJ_PROJECTION(bonne) { double c; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_bonne_data *Q = static_cast( + calloc(1, sizeof(struct pj_bonne_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; - P->destructor = destructor; + P->destructor = pj_bonne_destructor; Q->phi1 = pj_param(P->ctx, P->params, "rlat_1").f; if (fabs(Q->phi1) < EPS10) { proj_log_error(P, _("Invalid value for lat_1: |lat_1| should be > 0")); - return destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); + return pj_bonne_destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); } if (P->es != 0.0) { Q->en = pj_enfn(P->n); if (nullptr == Q->en) - return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); + return pj_bonne_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); Q->am1 = sin(Q->phi1); c = cos(Q->phi1); Q->m1 = pj_mlfn(Q->phi1, Q->am1, c, Q->en); @@ -148,3 +148,5 @@ PJ *PROJECTION(bonne) { } return P; } + +#undef EPS10 diff --git a/src/projections/calcofi.cpp b/src/projections/calcofi.cpp index b37b49b72c..e645265049 100644 --- a/src/projections/calcofi.cpp +++ b/src/projections/calcofi.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -130,7 +130,7 @@ static PJ_LP calcofi_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(calcofi) { +PJ *PJ_PROJECTION(calcofi) { P->opaque = nullptr; /* if the user has specified +lon_0 or +k0 for some reason, diff --git a/src/projections/cass.cpp b/src/projections/cass.cpp index 257b55a6f5..59682fc407 100644 --- a/src/projections/cass.cpp +++ b/src/projections/cass.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -91,7 +91,7 @@ static PJ_LP cass_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -static PJ *destructor(PJ *P, int errlev) { /* Destructor */ +static PJ *pj_cass_destructor(PJ *P, int errlev) { /* Destructor */ if (nullptr == P) return nullptr; @@ -102,7 +102,7 @@ static PJ *destructor(PJ *P, int errlev) { /* Destructor */ return pj_default_destructor(P, errlev); } -PJ *PROJECTION(cass) { +PJ *PJ_PROJECTION(cass) { /* Spheroidal? */ if (0 == P->es) { @@ -117,7 +117,7 @@ PJ *PROJECTION(cass) { P->opaque = Q; if (nullptr == P->opaque) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); - P->destructor = destructor; + P->destructor = pj_cass_destructor; Q->en = pj_enfn(P->n); if (nullptr == Q->en) @@ -131,3 +131,9 @@ PJ *PROJECTION(cass) { return P; } + +#undef C1 +#undef C2 +#undef C3 +#undef C4 +#undef C5 diff --git a/src/projections/cc.cpp b/src/projections/cc.cpp index 518d45e310..0c73534063 100644 --- a/src/projections/cc.cpp +++ b/src/projections/cc.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -27,7 +27,7 @@ static PJ_LP cc_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(cc) { +PJ *PJ_PROJECTION(cc) { P->es = 0.; P->inv = cc_s_inverse; diff --git a/src/projections/ccon.cpp b/src/projections/ccon.cpp index 4fba56d323..468570a2d2 100644 --- a/src/projections/ccon.cpp +++ b/src/projections/ccon.cpp @@ -20,7 +20,6 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ -#define PJ_LIB_ #include "proj.h" #include "proj_internal.h" #include @@ -29,7 +28,7 @@ #define EPS10 1e-10 namespace { // anonymous namespace -struct pj_opaque { +struct pj_ccon_data { double phi1; double ctgphi1; double sinphi1; @@ -43,7 +42,7 @@ PROJ_HEAD(ccon, "Central Conic") static PJ_XY ccon_forward(PJ_LP lp, PJ *P) { PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_ccon_data *Q = static_cast(P->opaque); double r; r = Q->ctgphi1 - tan(lp.phi - Q->phi1); @@ -55,7 +54,7 @@ static PJ_XY ccon_forward(PJ_LP lp, PJ *P) { static PJ_LP ccon_inverse(PJ_XY xy, PJ *P) { PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_ccon_data *Q = static_cast(P->opaque); xy.y = Q->ctgphi1 - xy.y; lp.phi = Q->phi1 - atan(hypot(xy.x, xy.y) - Q->ctgphi1); @@ -64,33 +63,33 @@ static PJ_LP ccon_inverse(PJ_XY xy, PJ *P) { return lp; } -static PJ *destructor(PJ *P, int errlev) { +static PJ *pj_ccon_destructor(PJ *P, int errlev) { if (nullptr == P) return nullptr; if (nullptr == P->opaque) return pj_default_destructor(P, errlev); - free(static_cast(P->opaque)->en); + free(static_cast(P->opaque)->en); return pj_default_destructor(P, errlev); } -PJ *PROJECTION(ccon) { +PJ *PJ_PROJECTION(ccon) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_ccon_data *Q = static_cast( + calloc(1, sizeof(struct pj_ccon_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; - P->destructor = destructor; + P->destructor = pj_ccon_destructor; Q->phi1 = pj_param(P->ctx, P->params, "rlat_1").f; if (fabs(Q->phi1) < EPS10) { proj_log_error(P, _("Invalid value for lat_1: |lat_1| should be > 0")); - return destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); + return pj_ccon_destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); } if (!(Q->en = pj_enfn(P->n))) - return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); + return pj_ccon_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); Q->sinphi1 = sin(Q->phi1); Q->cosphi1 = cos(Q->phi1); @@ -101,3 +100,5 @@ PJ *PROJECTION(ccon) { return P; } + +#undef EPS10 diff --git a/src/projections/cea.cpp b/src/projections/cea.cpp index f5b95119c3..7ce832f876 100644 --- a/src/projections/cea.cpp +++ b/src/projections/cea.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -7,7 +7,7 @@ #include "proj_internal.h" namespace { // anonymous namespace -struct pj_opaque { +struct pj_cea_data { double qp; double *apa; }; @@ -33,8 +33,8 @@ static PJ_XY cea_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP cea_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ PJ_LP lp = {0.0, 0.0}; lp.phi = pj_authlat(asin(2. * xy.y * P->k0 / - static_cast(P->opaque)->qp), - static_cast(P->opaque)->apa); + static_cast(P->opaque)->qp), + static_cast(P->opaque)->apa); lp.lam = xy.x / P->k0; return lp; } @@ -57,25 +57,25 @@ static PJ_LP cea_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return (lp); } -static PJ *destructor(PJ *P, int errlev) { /* Destructor */ +static PJ *pj_cea_destructor(PJ *P, int errlev) { /* Destructor */ if (nullptr == P) return nullptr; if (nullptr == P->opaque) return pj_default_destructor(P, errlev); - free(static_cast(P->opaque)->apa); + free(static_cast(P->opaque)->apa); return pj_default_destructor(P, errlev); } -PJ *PROJECTION(cea) { +PJ *PJ_PROJECTION(cea) { double t = 0.0; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_cea_data *Q = static_cast( + calloc(1, sizeof(struct pj_cea_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; - P->destructor = destructor; + P->destructor = pj_cea_destructor; if (pj_param(P->ctx, P->params, "tlat_ts").i) { t = pj_param(P->ctx, P->params, "rlat_ts").f; @@ -105,3 +105,5 @@ PJ *PROJECTION(cea) { return P; } + +#undef EPS diff --git a/src/projections/chamb.cpp b/src/projections/chamb.cpp index 15934c0dc7..27b5ff8698 100644 --- a/src/projections/chamb.cpp +++ b/src/projections/chamb.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -10,7 +10,7 @@ typedef struct { double r, Az; } VECT; namespace { // anonymous namespace -struct pj_opaque { +struct pj_chamb { struct { /* control point data */ double phi, lam; double cosphi, sinphi; @@ -58,7 +58,7 @@ static double lc(PJ_CONTEXT *ctx, double b, double c, double a) { static PJ_XY chamb_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_chamb *Q = static_cast(P->opaque); double sinphi, cosphi, a; VECT v[3]; int i, j; @@ -100,11 +100,11 @@ static PJ_XY chamb_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ return xy; } -PJ *PROJECTION(chamb) { +PJ *PJ_PROJECTION(chamb) { int i, j; char line[10]; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_chamb *Q = + static_cast(calloc(1, sizeof(struct pj_chamb))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -149,3 +149,6 @@ PJ *PROJECTION(chamb) { return P; } + +#undef THIRD +#undef TOL diff --git a/src/projections/col_urban.cpp b/src/projections/col_urban.cpp index a680059bbd..693147ae2c 100644 --- a/src/projections/col_urban.cpp +++ b/src/projections/col_urban.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -14,7 +14,7 @@ PROJ_HEAD(col_urban, "Colombia Urban") namespace { // anonymous namespace -struct pj_opaque { +struct pj_col_urban { double h0; // height of projection origin, divided by semi-major axis (a) double rho0; // adimensional value, contrary to Guidance note 7.2 double A; @@ -26,7 +26,7 @@ struct pj_opaque { static PJ_XY col_urban_forward(PJ_LP lp, PJ *P) { PJ_XY xy; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_col_urban *Q = static_cast(P->opaque); const double cosphi = cos(lp.phi); const double sinphi = sin(lp.phi); @@ -45,7 +45,7 @@ static PJ_XY col_urban_forward(PJ_LP lp, PJ *P) { static PJ_LP col_urban_inverse(PJ_XY xy, PJ *P) { PJ_LP lp; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_col_urban *Q = static_cast(P->opaque); lp.phi = P->phi0 + xy.y / Q->D - Q->B * (xy.x / Q->C) * (xy.x / Q->C); const double sinphi = sin(lp.phi); @@ -55,9 +55,9 @@ static PJ_LP col_urban_inverse(PJ_XY xy, PJ *P) { return lp; } -PJ *PROJECTION(col_urban) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(col_urban) { + struct pj_col_urban *Q = static_cast( + calloc(1, sizeof(struct pj_col_urban))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; diff --git a/src/projections/collg.cpp b/src/projections/collg.cpp index 169d1ca23c..47fe620395 100644 --- a/src/projections/collg.cpp +++ b/src/projections/collg.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -44,10 +44,14 @@ static PJ_LP collg_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return (lp); } -PJ *PROJECTION(collg) { +PJ *PJ_PROJECTION(collg) { P->es = 0.0; P->inv = collg_s_inverse; P->fwd = collg_s_forward; return P; } + +#undef FXC +#undef FYC +#undef ONEEPS diff --git a/src/projections/comill.cpp b/src/projections/comill.cpp index 9fbd8a26d6..9dd7e5893e 100644 --- a/src/projections/comill.cpp +++ b/src/projections/comill.cpp @@ -6,8 +6,6 @@ Sciences, Oregon State University. Port to PROJ.4 by Bojan Savric, 4 April 2016 */ -#define PJ_LIB_ - #include #include "proj.h" @@ -75,7 +73,7 @@ static PJ_LP comill_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(comill) { +PJ *PJ_PROJECTION(comill) { P->es = 0; P->inv = comill_s_inverse; @@ -83,3 +81,13 @@ PJ *PROJECTION(comill) { return P; } + +#undef K1 +#undef K2 +#undef K3 +#undef C1 +#undef C2 +#undef C3 +#undef EPS +#undef MAX_Y +#undef MAX_ITER diff --git a/src/projections/crast.cpp b/src/projections/crast.cpp index e6359315a1..cbd9c1b976 100644 --- a/src/projections/crast.cpp +++ b/src/projections/crast.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include "proj.h" @@ -29,7 +29,7 @@ static PJ_LP crast_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(crast) { +PJ *PJ_PROJECTION(crast) { P->es = 0.0; P->inv = crast_s_inverse; P->fwd = crast_s_forward; diff --git a/src/projections/denoy.cpp b/src/projections/denoy.cpp index 20f365a0df..468145932c 100644 --- a/src/projections/denoy.cpp +++ b/src/projections/denoy.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include "proj.h" @@ -23,9 +23,15 @@ static PJ_XY denoy_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ return xy; } -PJ *PROJECTION(denoy) { +PJ *PJ_PROJECTION(denoy) { P->es = 0.0; P->fwd = denoy_s_forward; return P; } + +#undef C0 +#undef C1 +#undef C3 +#undef D1 +#undef D5 diff --git a/src/projections/eck1.cpp b/src/projections/eck1.cpp index b748e50607..7a0c1d25ff 100644 --- a/src/projections/eck1.cpp +++ b/src/projections/eck1.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include "proj.h" @@ -28,7 +28,7 @@ static PJ_LP eck1_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return (lp); } -PJ *PROJECTION(eck1) { +PJ *PJ_PROJECTION(eck1) { P->es = 0.0; P->inv = eck1_s_inverse; P->fwd = eck1_s_forward; diff --git a/src/projections/eck2.cpp b/src/projections/eck2.cpp index 916562940b..0405ffc9f8 100644 --- a/src/projections/eck2.cpp +++ b/src/projections/eck2.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -45,7 +45,7 @@ static PJ_LP eck2_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return (lp); } -PJ *PROJECTION(eck2) { +PJ *PJ_PROJECTION(eck2) { P->es = 0.; P->inv = eck2_s_inverse; P->fwd = eck2_s_forward; diff --git a/src/projections/eck3.cpp b/src/projections/eck3.cpp index 73cd4e6639..c34e06d0a8 100644 --- a/src/projections/eck3.cpp +++ b/src/projections/eck3.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -47,7 +47,7 @@ static PJ *setup(PJ *P) { return P; } -PJ *PROJECTION(eck3) { +PJ *PJ_PROJECTION(eck3) { struct pj_opaque *Q = static_cast(calloc(1, sizeof(struct pj_opaque))); if (nullptr == Q) @@ -62,7 +62,7 @@ PJ *PROJECTION(eck3) { return setup(P); } -PJ *PROJECTION(kav7) { +PJ *PJ_PROJECTION(kav7) { struct pj_opaque *Q = static_cast(calloc(1, sizeof(struct pj_opaque))); if (nullptr == Q) @@ -80,7 +80,7 @@ PJ *PROJECTION(kav7) { return setup(P); } -PJ *PROJECTION(wag6) { +PJ *PJ_PROJECTION(wag6) { struct pj_opaque *Q = static_cast(calloc(1, sizeof(struct pj_opaque))); if (nullptr == Q) @@ -95,7 +95,7 @@ PJ *PROJECTION(wag6) { return setup(P); } -PJ *PROJECTION(putp1) { +PJ *PJ_PROJECTION(putp1) { struct pj_opaque *Q = static_cast(calloc(1, sizeof(struct pj_opaque))); if (nullptr == Q) diff --git a/src/projections/eck4.cpp b/src/projections/eck4.cpp index 6bef543dbc..bae48e0ff7 100644 --- a/src/projections/eck4.cpp +++ b/src/projections/eck4.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -82,7 +82,7 @@ static PJ_LP eck4_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(eck4) { +PJ *PJ_PROJECTION(eck4) { P->es = 0.0; P->inv = eck4_s_inverse; P->fwd = eck4_s_forward; diff --git a/src/projections/eck5.cpp b/src/projections/eck5.cpp index 226956874a..76bba00f62 100644 --- a/src/projections/eck5.cpp +++ b/src/projections/eck5.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -30,7 +30,7 @@ static PJ_LP eck5_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(eck5) { +PJ *PJ_PROJECTION(eck5) { P->es = 0.0; P->inv = eck5_s_inverse; P->fwd = eck5_s_forward; diff --git a/src/projections/eqc.cpp b/src/projections/eqc.cpp index 8b5d9e189c..c5564521dc 100644 --- a/src/projections/eqc.cpp +++ b/src/projections/eqc.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -7,7 +7,7 @@ #include "proj_internal.h" namespace { // anonymous namespace -struct pj_opaque { +struct pj_eqc_data { double rc; }; } // anonymous namespace @@ -17,7 +17,7 @@ PROJ_HEAD(eqc, "Equidistant Cylindrical (Plate Carree)") static PJ_XY eqc_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_eqc_data *Q = static_cast(P->opaque); xy.x = Q->rc * lp.lam; xy.y = lp.phi - P->phi0; @@ -27,7 +27,7 @@ static PJ_XY eqc_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP eqc_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_eqc_data *Q = static_cast(P->opaque); lp.lam = xy.x / Q->rc; lp.phi = xy.y + P->phi0; @@ -35,9 +35,9 @@ static PJ_LP eqc_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(eqc) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(eqc) { + struct pj_eqc_data *Q = static_cast( + calloc(1, sizeof(struct pj_eqc_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; diff --git a/src/projections/eqdc.cpp b/src/projections/eqdc.cpp index 1cac4fb2f6..7774bf0fb5 100644 --- a/src/projections/eqdc.cpp +++ b/src/projections/eqdc.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -8,7 +8,7 @@ #include namespace { // anonymous namespace -struct pj_opaque { +struct pj_eqdc_data { double phi1; double phi2; double n; @@ -26,7 +26,7 @@ PROJ_HEAD(eqdc, "Equidistant Conic") static PJ_XY eqdc_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_eqdc_data *Q = static_cast(P->opaque); Q->rho = Q->c - @@ -40,7 +40,7 @@ static PJ_XY eqdc_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ static PJ_LP eqdc_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_eqdc_data *Q = static_cast(P->opaque); if ((Q->rho = hypot(xy.x, xy.y = Q->rho0 - xy.y)) != 0.0) { if (Q->n < 0.) { @@ -59,27 +59,27 @@ static PJ_LP eqdc_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ return lp; } -static PJ *destructor(PJ *P, int errlev) { /* Destructor */ +static PJ *pj_eqdc_destructor(PJ *P, int errlev) { /* Destructor */ if (nullptr == P) return nullptr; if (nullptr == P->opaque) return pj_default_destructor(P, errlev); - free(static_cast(P->opaque)->en); + free(static_cast(P->opaque)->en); return pj_default_destructor(P, errlev); } -PJ *PROJECTION(eqdc) { +PJ *PJ_PROJECTION(eqdc) { double cosphi, sinphi; int secant; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_eqdc_data *Q = static_cast( + calloc(1, sizeof(struct pj_eqdc_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; - P->destructor = destructor; + P->destructor = pj_eqdc_destructor; Q->phi1 = pj_param(P->ctx, P->params, "rlat_1").f; Q->phi2 = pj_param(P->ctx, P->params, "rlat_2").f; @@ -87,22 +87,22 @@ PJ *PROJECTION(eqdc) { if (fabs(Q->phi1) > M_HALFPI) { proj_log_error(P, _("Invalid value for lat_1: |lat_1| should be <= 90°")); - return destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); + return pj_eqdc_destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); } if (fabs(Q->phi2) > M_HALFPI) { proj_log_error(P, _("Invalid value for lat_2: |lat_2| should be <= 90°")); - return destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); + return pj_eqdc_destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); } if (fabs(Q->phi1 + Q->phi2) < EPS10) { proj_log_error(P, _("Invalid value for lat_1 and lat_2: |lat_1 + " "lat_2| should be > 0")); - return destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); + return pj_eqdc_destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); } if (!(Q->en = pj_enfn(P->n))) - return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); + return pj_eqdc_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); sinphi = sin(Q->phi1); Q->n = sinphi; @@ -120,13 +120,15 @@ PJ *PROJECTION(eqdc) { const double ml2 = pj_mlfn(Q->phi2, sinphi, cosphi, Q->en); if (ml1 == ml2) { proj_log_error(P, _("Eccentricity too close to 1")); - return destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); + return pj_eqdc_destructor( + P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); } Q->n = (m1 - pj_msfn(sinphi, cosphi, P->es)) / (ml2 - ml1); if (Q->n == 0) { // Not quite, but es is very close to 1... proj_log_error(P, _("Invalid value for eccentricity")); - return destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); + return pj_eqdc_destructor( + P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); } } Q->c = ml1 + m1 / Q->n; @@ -137,7 +139,7 @@ PJ *PROJECTION(eqdc) { if (Q->n == 0) { proj_log_error(P, _("Invalid value for lat_1 and lat_2: lat_1 + " "lat_2 should be > 0")); - return destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); + return pj_eqdc_destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); } Q->c = Q->phi1 + cos(Q->phi1) / Q->n; Q->rho0 = Q->c - P->phi0; @@ -148,3 +150,5 @@ PJ *PROJECTION(eqdc) { return P; } + +#undef EPS10 diff --git a/src/projections/eqearth.cpp b/src/projections/eqearth.cpp index d78da37a66..ed2502f7ac 100644 --- a/src/projections/eqearth.cpp +++ b/src/projections/eqearth.cpp @@ -11,7 +11,6 @@ DOI: 10.1080/13658816.2018.1504949 Port to PROJ by Juernjakob Dugge, 16 August 2018 Added ellipsoidal equations by Bojan Savric, 22 August 2018 */ -#define PJ_LIB_ #include #include @@ -33,7 +32,7 @@ PROJ_HEAD(eqearth, "Equal Earth") "\n\tPCyl, Sph&Ell"; #define MAX_ITER 12 namespace { // anonymous namespace -struct pj_opaque { +struct pj_eqearth { double qp; double rqda; double *apa; @@ -43,7 +42,7 @@ struct pj_opaque { static PJ_XY eqearth_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal/spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_eqearth *Q = static_cast(P->opaque); double sbeta; double psi, psi2, psi6; @@ -78,7 +77,7 @@ static PJ_XY eqearth_e_forward(PJ_LP lp, static PJ_LP eqearth_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal/spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_eqearth *Q = static_cast(P->opaque); double yc, y2, y6; int i; @@ -141,13 +140,13 @@ static PJ *destructor(PJ *P, int errlev) { /* Destructor */ if (nullptr == P->opaque) return pj_default_destructor(P, errlev); - free(static_cast(P->opaque)->apa); + free(static_cast(P->opaque)->apa); return pj_default_destructor(P, errlev); } -PJ *PROJECTION(eqearth) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(eqearth) { + struct pj_eqearth *Q = + static_cast(calloc(1, sizeof(struct pj_eqearth))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -167,3 +166,13 @@ PJ *PROJECTION(eqearth) { return P; } + +#undef A1 +#undef A2 +#undef A3 +#undef A4 +#undef M + +#undef MAX_Y +#undef EPS +#undef MAX_ITER diff --git a/src/projections/fahey.cpp b/src/projections/fahey.cpp index 7cb05191c7..3557a165d2 100644 --- a/src/projections/fahey.cpp +++ b/src/projections/fahey.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -30,7 +30,7 @@ static PJ_LP fahey_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(fahey) { +PJ *PJ_PROJECTION(fahey) { P->es = 0.; P->inv = fahey_s_inverse; P->fwd = fahey_s_forward; diff --git a/src/projections/fouc_s.cpp b/src/projections/fouc_s.cpp index f84e3f05c1..36235bf115 100644 --- a/src/projections/fouc_s.cpp +++ b/src/projections/fouc_s.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -12,14 +12,14 @@ PROJ_HEAD(fouc_s, "Foucaut Sinusoidal") "\n\tPCyl, Sph"; #define LOOP_TOL 1e-7 namespace { // anonymous namespace -struct pj_opaque { +struct pj_fouc_s_data { double n, n1; }; } // anonymous namespace static PJ_XY fouc_s_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_fouc_s_data *Q = static_cast(P->opaque); double t; t = cos(lp.phi); @@ -30,7 +30,7 @@ static PJ_XY fouc_s_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP fouc_s_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_fouc_s_data *Q = static_cast(P->opaque); int i; if (Q->n != 0.0) { @@ -51,9 +51,9 @@ static PJ_LP fouc_s_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(fouc_s) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(fouc_s) { + struct pj_fouc_s_data *Q = static_cast( + calloc(1, sizeof(struct pj_fouc_s_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -71,3 +71,6 @@ PJ *PROJECTION(fouc_s) { P->fwd = fouc_s_s_forward; return P; } + +#undef MAX_ITER +#undef LOOP_TOL diff --git a/src/projections/gall.cpp b/src/projections/gall.cpp index 2a957a1067..53ac74daa6 100644 --- a/src/projections/gall.cpp +++ b/src/projections/gall.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -32,7 +32,7 @@ static PJ_LP gall_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(gall) { +PJ *PJ_PROJECTION(gall) { P->es = 0.0; P->inv = gall_s_inverse; diff --git a/src/projections/geos.cpp b/src/projections/geos.cpp index 30d70be1c0..0f1ae46990 100644 --- a/src/projections/geos.cpp +++ b/src/projections/geos.cpp @@ -27,7 +27,6 @@ ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#define PJ_LIB_ #include #include #include @@ -37,7 +36,7 @@ #include namespace { // anonymous namespace -struct pj_opaque { +struct pj_geos_data { double h; double radius_p; double radius_p2; @@ -53,7 +52,7 @@ PROJ_HEAD(geos, "Geostationary Satellite View") "\n\tAzi, Sph&Ell\n\th="; static PJ_XY geos_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_geos_data *Q = static_cast(P->opaque); double Vx, Vy, Vz, tmp; /* Calculation of the three components of the vector from satellite to @@ -81,7 +80,7 @@ static PJ_XY geos_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_XY geos_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_geos_data *Q = static_cast(P->opaque); double r, Vx, Vy, Vz, tmp; /* Calculation of geocentric latitude. */ @@ -116,7 +115,7 @@ static PJ_XY geos_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ static PJ_LP geos_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_geos_data *Q = static_cast(P->opaque); double Vx, Vy, Vz, a, b, k; /* Setting three components of vector from satellite to position.*/ @@ -153,7 +152,7 @@ static PJ_LP geos_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ static PJ_LP geos_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_geos_data *Q = static_cast(P->opaque); double Vx, Vy, Vz, a, b, k; /* Setting three components of vector from satellite to position.*/ @@ -191,10 +190,10 @@ static PJ_LP geos_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ return lp; } -PJ *PROJECTION(geos) { +PJ *PJ_PROJECTION(geos) { char *sweep_axis; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_geos_data *Q = static_cast( + calloc(1, sizeof(struct pj_geos_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; diff --git a/src/projections/gins8.cpp b/src/projections/gins8.cpp index 6e44d52cd2..4a3c8c0b66 100644 --- a/src/projections/gins8.cpp +++ b/src/projections/gins8.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include "proj.h" #include "proj_internal.h" @@ -22,7 +22,7 @@ static PJ_XY gins8_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ return xy; } -PJ *PROJECTION(gins8) { +PJ *PJ_PROJECTION(gins8) { P->es = 0.0; P->inv = nullptr; P->fwd = gins8_s_forward; diff --git a/src/projections/gn_sinu.cpp b/src/projections/gn_sinu.cpp index 3bb9ab4c68..1615c6a54b 100644 --- a/src/projections/gn_sinu.cpp +++ b/src/projections/gn_sinu.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -16,7 +16,7 @@ PROJ_HEAD(mbtfps, "McBryde-Thomas Flat-Polar Sinusoidal") "\n\tPCyl, Sph"; #define LOOP_TOL 1e-7 namespace { // anonymous namespace -struct pj_opaque { +struct pj_gn_sinu_data { double *en; double m, n, C_x, C_y; }; @@ -27,8 +27,8 @@ static PJ_XY gn_sinu_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ const double s = sin(lp.phi); const double c = cos(lp.phi); - xy.y = - pj_mlfn(lp.phi, s, c, static_cast(P->opaque)->en); + xy.y = pj_mlfn(lp.phi, s, c, + static_cast(P->opaque)->en); xy.x = lp.lam * c / sqrt(1. - P->es * s * s); return xy; } @@ -37,7 +37,8 @@ static PJ_LP gn_sinu_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ PJ_LP lp = {0.0, 0.0}; double s; - lp.phi = pj_inv_mlfn(xy.y, static_cast(P->opaque)->en); + lp.phi = + pj_inv_mlfn(xy.y, static_cast(P->opaque)->en); s = fabs(lp.phi); if (s < M_HALFPI) { s = sin(lp.phi); @@ -53,7 +54,8 @@ static PJ_LP gn_sinu_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ static PJ_XY gn_sinu_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_gn_sinu_data *Q = + static_cast(P->opaque); if (Q->m == 0.0) lp.phi = Q->n != 1. ? aasin(P->ctx, Q->n * sin(lp.phi)) : lp.phi; @@ -81,7 +83,8 @@ static PJ_XY gn_sinu_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP gn_sinu_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_gn_sinu_data *Q = + static_cast(P->opaque); xy.y /= Q->C_y; lp.phi = (Q->m != 0.0) @@ -91,20 +94,21 @@ static PJ_LP gn_sinu_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -static PJ *destructor(PJ *P, int errlev) { /* Destructor */ +static PJ *pj_gn_sinu_destructor(PJ *P, int errlev) { /* Destructor */ if (nullptr == P) return nullptr; if (nullptr == P->opaque) return pj_default_destructor(P, errlev); - free(static_cast(P->opaque)->en); + free(static_cast(P->opaque)->en); return pj_default_destructor(P, errlev); } /* for spheres, only */ -static void setup(PJ *P) { - struct pj_opaque *Q = static_cast(P->opaque); +static void pj_gn_sinu_setup(PJ *P) { + struct pj_gn_sinu_data *Q = + static_cast(P->opaque); P->es = 0; P->inv = gn_sinu_s_inverse; P->fwd = gn_sinu_s_forward; @@ -113,13 +117,13 @@ static void setup(PJ *P) { Q->C_x = Q->C_y / (Q->m + 1.); } -PJ *PROJECTION(sinu) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(sinu) { + struct pj_gn_sinu_data *Q = static_cast( + calloc(1, sizeof(struct pj_gn_sinu_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; - P->destructor = destructor; + P->destructor = pj_gn_sinu_destructor; if (!(Q->en = pj_enfn(P->n))) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); @@ -130,48 +134,48 @@ PJ *PROJECTION(sinu) { } else { Q->n = 1.; Q->m = 0.; - setup(P); + pj_gn_sinu_setup(P); } return P; } -PJ *PROJECTION(eck6) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(eck6) { + struct pj_gn_sinu_data *Q = static_cast( + calloc(1, sizeof(struct pj_gn_sinu_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; - P->destructor = destructor; + P->destructor = pj_gn_sinu_destructor; Q->m = 1.; Q->n = 2.570796326794896619231321691; - setup(P); + pj_gn_sinu_setup(P); return P; } -PJ *PROJECTION(mbtfps) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(mbtfps) { + struct pj_gn_sinu_data *Q = static_cast( + calloc(1, sizeof(struct pj_gn_sinu_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; - P->destructor = destructor; + P->destructor = pj_gn_sinu_destructor; Q->m = 0.5; Q->n = 1.785398163397448309615660845; - setup(P); + pj_gn_sinu_setup(P); return P; } -PJ *PROJECTION(gn_sinu) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(gn_sinu) { + struct pj_gn_sinu_data *Q = static_cast( + calloc(1, sizeof(struct pj_gn_sinu_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; - P->destructor = destructor; + P->destructor = pj_gn_sinu_destructor; if (!pj_param(P->ctx, P->params, "tn").i) { proj_log_error(P, _("Missing parameter n.")); @@ -193,7 +197,7 @@ PJ *PROJECTION(gn_sinu) { return pj_default_destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); } - setup(P); + pj_gn_sinu_setup(P); return P; } diff --git a/src/projections/gnom.cpp b/src/projections/gnom.cpp index b6498af1b7..490ed0abc1 100644 --- a/src/projections/gnom.cpp +++ b/src/projections/gnom.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -12,22 +12,22 @@ PROJ_HEAD(gnom, "Gnomonic") "\n\tAzi, Sph"; #define EPS10 1.e-10 -namespace { // anonymous namespace +namespace pj_gnom_ns { enum Mode { N_POLE = 0, S_POLE = 1, EQUIT = 2, OBLIQ = 3 }; -} // anonymous namespace +} namespace { // anonymous namespace -struct pj_opaque { +struct pj_gnom_data { double sinph0; double cosph0; - enum Mode mode; + enum pj_gnom_ns::Mode mode; struct geod_geodesic g; }; } // anonymous namespace static PJ_XY gnom_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_gnom_data *Q = static_cast(P->opaque); double coslam, cosphi, sinphi; sinphi = sin(lp.phi); @@ -35,16 +35,16 @@ static PJ_XY gnom_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ coslam = cos(lp.lam); switch (Q->mode) { - case EQUIT: + case pj_gnom_ns::EQUIT: xy.y = cosphi * coslam; break; - case OBLIQ: + case pj_gnom_ns::OBLIQ: xy.y = Q->sinph0 * sinphi + Q->cosph0 * cosphi * coslam; break; - case S_POLE: + case pj_gnom_ns::S_POLE: xy.y = -sinphi; break; - case N_POLE: + case pj_gnom_ns::N_POLE: xy.y = sinphi; break; } @@ -56,16 +56,16 @@ static PJ_XY gnom_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ xy.x = (xy.y = 1. / xy.y) * cosphi * sin(lp.lam); switch (Q->mode) { - case EQUIT: + case pj_gnom_ns::EQUIT: xy.y *= sinphi; break; - case OBLIQ: + case pj_gnom_ns::OBLIQ: xy.y *= Q->cosph0 * sinphi - Q->sinph0 * cosphi * coslam; break; - case N_POLE: + case pj_gnom_ns::N_POLE: coslam = -coslam; PROJ_FALLTHROUGH; - case S_POLE: + case pj_gnom_ns::S_POLE: xy.y *= cosphi * coslam; break; } @@ -74,7 +74,7 @@ static PJ_XY gnom_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP gnom_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_gnom_data *Q = static_cast(P->opaque); double rh, cosz, sinz; rh = hypot(xy.x, xy.y); @@ -86,7 +86,7 @@ static PJ_LP gnom_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ lp.lam = 0.; } else { switch (Q->mode) { - case OBLIQ: + case pj_gnom_ns::OBLIQ: lp.phi = cosz * Q->sinph0 + xy.y * sinz * Q->cosph0 / rh; if (fabs(lp.phi) >= 1.) lp.phi = lp.phi > 0. ? M_HALFPI : -M_HALFPI; @@ -95,7 +95,7 @@ static PJ_LP gnom_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ xy.y = (cosz - Q->sinph0 * sin(lp.phi)) * rh; xy.x *= sinz * Q->cosph0; break; - case EQUIT: + case pj_gnom_ns::EQUIT: lp.phi = xy.y * sinz / rh; if (fabs(lp.phi) >= 1.) lp.phi = lp.phi > 0. ? M_HALFPI : -M_HALFPI; @@ -104,10 +104,10 @@ static PJ_LP gnom_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ xy.y = cosz * rh; xy.x *= sinz; break; - case S_POLE: + case pj_gnom_ns::S_POLE: lp.phi -= M_HALFPI; break; - case N_POLE: + case pj_gnom_ns::N_POLE: lp.phi = M_HALFPI - lp.phi; xy.y = -xy.y; break; @@ -119,7 +119,7 @@ static PJ_LP gnom_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ static PJ_XY gnom_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_gnom_data *Q = static_cast(P->opaque); double lat0 = P->phi0 / DEG_TO_RAD, lon0 = 0, lat1 = lp.phi / DEG_TO_RAD, lon1 = lp.lam / DEG_TO_RAD, azi0, m, M; @@ -143,7 +143,7 @@ static PJ_LP gnom_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ static const double eps_ = 0.01 * sqrt(DBL_EPSILON); PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_gnom_data *Q = static_cast(P->opaque); double lat0 = P->phi0 / DEG_TO_RAD, lon0 = 0, azi0 = atan2(xy.x, xy.y) / DEG_TO_RAD, // Clockwise from north @@ -182,20 +182,20 @@ static PJ_LP gnom_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ return lp; } -PJ *PROJECTION(gnom) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(gnom) { + struct pj_gnom_data *Q = static_cast( + calloc(1, sizeof(struct pj_gnom_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; if (P->es == 0) { if (fabs(fabs(P->phi0) - M_HALFPI) < EPS10) { - Q->mode = P->phi0 < 0. ? S_POLE : N_POLE; + Q->mode = P->phi0 < 0. ? pj_gnom_ns::S_POLE : pj_gnom_ns::N_POLE; } else if (fabs(P->phi0) < EPS10) { - Q->mode = EQUIT; + Q->mode = pj_gnom_ns::EQUIT; } else { - Q->mode = OBLIQ; + Q->mode = pj_gnom_ns::OBLIQ; Q->sinph0 = sin(P->phi0); Q->cosph0 = cos(P->phi0); } diff --git a/src/projections/goode.cpp b/src/projections/goode.cpp index dbe4d0c6c0..a9cc76ef69 100644 --- a/src/projections/goode.cpp +++ b/src/projections/goode.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -14,7 +14,7 @@ PROJ_HEAD(goode, "Goode Homolosine") "\n\tPCyl, Sph"; C_NAMESPACE PJ *pj_sinu(PJ *), *pj_moll(PJ *); namespace { // anonymous namespace -struct pj_opaque { +struct pj_goode_data { PJ *sinu; PJ *moll; }; @@ -22,7 +22,7 @@ struct pj_opaque { static PJ_XY goode_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_goode_data *Q = static_cast(P->opaque); if (fabs(lp.phi) <= PHI_LIM) xy = Q->sinu->fwd(lp, Q->sinu); @@ -35,7 +35,7 @@ static PJ_XY goode_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP goode_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_goode_data *Q = static_cast(P->opaque); if (fabs(xy.y) <= PHI_LIM) lp = Q->sinu->inv(xy, Q->sinu); @@ -46,39 +46,42 @@ static PJ_LP goode_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -static PJ *destructor(PJ *P, int errlev) { /* Destructor */ +static PJ *goode_destructor(PJ *P, int errlev) { /* Destructor */ if (nullptr == P) return nullptr; if (nullptr == P->opaque) return pj_default_destructor(P, errlev); - proj_destroy(static_cast(P->opaque)->sinu); - proj_destroy(static_cast(P->opaque)->moll); + proj_destroy(static_cast(P->opaque)->sinu); + proj_destroy(static_cast(P->opaque)->moll); return pj_default_destructor(P, errlev); } -PJ *PROJECTION(goode) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(goode) { + struct pj_goode_data *Q = static_cast( + calloc(1, sizeof(struct pj_goode_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; - P->destructor = destructor; + P->destructor = goode_destructor; P->es = 0.; Q->sinu = pj_sinu(nullptr); Q->moll = pj_moll(nullptr); if (Q->sinu == nullptr || Q->moll == nullptr) - return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); + return goode_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); Q->sinu->es = 0.; Q->sinu->ctx = P->ctx; Q->moll->ctx = P->ctx; Q->sinu = pj_sinu(Q->sinu); Q->moll = pj_moll(Q->moll); if (Q->sinu == nullptr || Q->moll == nullptr) - return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); + return goode_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->fwd = goode_s_forward; P->inv = goode_s_inverse; return P; } + +#undef Y_COR +#undef PHI_LIM diff --git a/src/projections/gstmerc.cpp b/src/projections/gstmerc.cpp index 648afc8bf8..da3f3fa5a8 100644 --- a/src/projections/gstmerc.cpp +++ b/src/projections/gstmerc.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -11,7 +11,7 @@ PROJ_HEAD(gstmerc, "\n\tCyl, Sph&Ell\n\tlat_0= lon_0= k_0="; namespace { // anonymous namespace -struct pj_opaque { +struct pj_gstmerc_data { double lamc; double phic; double c; @@ -24,7 +24,8 @@ struct pj_opaque { static PJ_XY gstmerc_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_gstmerc_data *Q = + static_cast(P->opaque); double L, Ls, sinLs1, Ls1; L = Q->n1 * lp.lam; @@ -39,7 +40,8 @@ static PJ_XY gstmerc_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP gstmerc_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_gstmerc_data *Q = + static_cast(P->opaque); double L, LC, sinC; L = atan(sinh((xy.x * P->a - Q->XS) / Q->n2) / @@ -53,9 +55,9 @@ static PJ_LP gstmerc_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(gstmerc) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(gstmerc) { + struct pj_gstmerc_data *Q = static_cast( + calloc(1, sizeof(struct pj_gstmerc_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; diff --git a/src/projections/hammer.cpp b/src/projections/hammer.cpp index 95893a110b..140db9ccfb 100644 --- a/src/projections/hammer.cpp +++ b/src/projections/hammer.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -12,7 +12,7 @@ PROJ_HEAD(hammer, "Hammer & Eckert-Greifendorff") #define EPS 1.0e-10 namespace { // anonymous namespace -struct pj_opaque { +struct pq_hammer { double w; double m, rm; }; @@ -20,7 +20,7 @@ struct pj_opaque { static PJ_XY hammer_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pq_hammer *Q = static_cast(P->opaque); double cosphi, d; cosphi = cos(lp.phi); @@ -38,7 +38,7 @@ static PJ_XY hammer_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP hammer_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pq_hammer *Q = static_cast(P->opaque); double z; z = sqrt(1. - 0.25 * Q->w * Q->w * xy.x * xy.x - 0.25 * xy.y * xy.y); @@ -53,9 +53,9 @@ static PJ_LP hammer_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(hammer) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(hammer) { + struct pq_hammer *Q = + static_cast(calloc(1, sizeof(struct pq_hammer))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -88,3 +88,5 @@ PJ *PROJECTION(hammer) { return P; } + +#undef EPS diff --git a/src/projections/hatano.cpp b/src/projections/hatano.cpp index 56b3f3d3c7..e9aa0cc892 100644 --- a/src/projections/hatano.cpp +++ b/src/projections/hatano.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -72,10 +72,24 @@ static PJ_LP hatano_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return (lp); } -PJ *PROJECTION(hatano) { +PJ *PJ_PROJECTION(hatano) { P->es = 0.; P->inv = hatano_s_inverse; P->fwd = hatano_s_forward; return P; } + +#undef NITER +#undef EPS +#undef ONETOL +#undef CN +#undef CSz +#undef RCN +#undef RCS +#undef FYCN +#undef FYCS +#undef RYCN +#undef RYCS +#undef FXC +#undef RXC diff --git a/src/projections/healpix.cpp b/src/projections/healpix.cpp index ca18ae6555..74d83799e6 100644 --- a/src/projections/healpix.cpp +++ b/src/projections/healpix.cpp @@ -29,7 +29,6 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. *****************************************************************************/ -#define PJ_LIB_ #include #include @@ -67,7 +66,7 @@ PROJ_HEAD(rhealpix, "rHEALPix") "\n\tSph&Ell\n\tnorth_square= south_square="; #define EPS 1e-15 namespace { // anonymous namespace -struct pj_opaque { +struct pj_healpix_data { int north_square; int south_square; double rot_xy; @@ -229,7 +228,8 @@ static int in_image(double x, double y, int proj, int north_square, * P contains the relevant ellipsoid parameters. **/ static double auth_lat(PJ *P, double alpha, int inverse) { - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_healpix_data *Q = + static_cast(P->opaque); if (inverse == 0) { /* Authalic latitude. */ double q = pj_qsfn(sin(alpha), P->e, 1.0 - P->es); @@ -500,18 +500,21 @@ static PJ_XY combine_caps(double x, double y, int north_square, static PJ_XY s_healpix_forward(PJ_LP lp, PJ *P) { /* sphere */ (void)P; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_healpix_data *Q = + static_cast(P->opaque); return rotate(healpix_sphere(lp), -Q->rot_xy); } static PJ_XY e_healpix_forward(PJ_LP lp, PJ *P) { /* ellipsoid */ lp.phi = auth_lat(P, lp.phi, 0); - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_healpix_data *Q = + static_cast(P->opaque); return rotate(healpix_sphere(lp), -Q->rot_xy); } static PJ_LP s_healpix_inverse(PJ_XY xy, PJ *P) { /* sphere */ - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_healpix_data *Q = + static_cast(P->opaque); xy = rotate(xy, Q->rot_xy); /* Check whether (x, y) lies in the HEALPix image */ @@ -528,7 +531,8 @@ static PJ_LP s_healpix_inverse(PJ_XY xy, PJ *P) { /* sphere */ static PJ_LP e_healpix_inverse(PJ_XY xy, PJ *P) { /* ellipsoid */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_healpix_data *Q = + static_cast(P->opaque); xy = rotate(xy, Q->rot_xy); /* Check whether (x, y) lies in the HEALPix image. */ @@ -545,14 +549,16 @@ static PJ_LP e_healpix_inverse(PJ_XY xy, PJ *P) { /* ellipsoid */ } static PJ_XY s_rhealpix_forward(PJ_LP lp, PJ *P) { /* sphere */ - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_healpix_data *Q = + static_cast(P->opaque); PJ_XY xy = healpix_sphere(lp); return combine_caps(xy.x, xy.y, Q->north_square, Q->south_square, 0); } static PJ_XY e_rhealpix_forward(PJ_LP lp, PJ *P) { /* ellipsoid */ - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_healpix_data *Q = + static_cast(P->opaque); PJ_XY xy; lp.phi = auth_lat(P, lp.phi, 0); xy = healpix_sphere(lp); @@ -560,7 +566,8 @@ static PJ_XY e_rhealpix_forward(PJ_LP lp, PJ *P) { /* ellipsoid */ } static PJ_LP s_rhealpix_inverse(PJ_XY xy, PJ *P) { /* sphere */ - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_healpix_data *Q = + static_cast(P->opaque); /* Check whether (x, y) lies in the rHEALPix image. */ if (in_image(xy.x, xy.y, 1, Q->north_square, Q->south_square) == 0) { @@ -576,7 +583,8 @@ static PJ_LP s_rhealpix_inverse(PJ_XY xy, PJ *P) { /* sphere */ } static PJ_LP e_rhealpix_inverse(PJ_XY xy, PJ *P) { /* ellipsoid */ - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_healpix_data *Q = + static_cast(P->opaque); PJ_LP lp = {0.0, 0.0}; /* Check whether (x, y) lies in the rHEALPix image. */ @@ -593,24 +601,24 @@ static PJ_LP e_rhealpix_inverse(PJ_XY xy, PJ *P) { /* ellipsoid */ return lp; } -static PJ *destructor(PJ *P, int errlev) { /* Destructor */ +static PJ *pj_healpix_data_destructor(PJ *P, int errlev) { /* Destructor */ if (nullptr == P) return nullptr; if (nullptr == P->opaque) return pj_default_destructor(P, errlev); - free(static_cast(P->opaque)->apa); + free(static_cast(P->opaque)->apa); return pj_default_destructor(P, errlev); } -PJ *PROJECTION(healpix) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(healpix) { + struct pj_healpix_data *Q = static_cast( + calloc(1, sizeof(struct pj_healpix_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; - P->destructor = destructor; + P->destructor = pj_healpix_data_destructor; double angle = pj_param(P->ctx, P->params, "drot_xy").f; Q->rot_xy = PJ_TORAD(angle); @@ -618,7 +626,7 @@ PJ *PROJECTION(healpix) { if (P->es != 0.0) { Q->apa = pj_authset(P->es); /* For auth_lat(). */ if (nullptr == Q->apa) - return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); + return pj_healpix_data_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); Q->qp = pj_qsfn(1.0, P->e, P->one_es); /* For auth_lat(). */ P->a = P->a * sqrt(0.5 * Q->qp); /* Set P->a to authalic radius. */ pj_calc_ellipsoid_params( @@ -633,13 +641,13 @@ PJ *PROJECTION(healpix) { return P; } -PJ *PROJECTION(rhealpix) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(rhealpix) { + struct pj_healpix_data *Q = static_cast( + calloc(1, sizeof(struct pj_healpix_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; - P->destructor = destructor; + P->destructor = pj_healpix_data_destructor; Q->north_square = pj_param(P->ctx, P->params, "inorth_square").i; Q->south_square = pj_param(P->ctx, P->params, "isouth_square").i; @@ -649,18 +657,20 @@ PJ *PROJECTION(rhealpix) { proj_log_error( P, _("Invalid value for north_square: it should be in [0,3] range.")); - return destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); + return pj_healpix_data_destructor( + P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); } if (Q->south_square < 0 || Q->south_square > 3) { proj_log_error( P, _("Invalid value for south_square: it should be in [0,3] range.")); - return destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); + return pj_healpix_data_destructor( + P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); } if (P->es != 0.0) { Q->apa = pj_authset(P->es); /* For auth_lat(). */ if (nullptr == Q->apa) - return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); + return pj_healpix_data_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); Q->qp = pj_qsfn(1.0, P->e, P->one_es); /* For auth_lat(). */ P->a = P->a * sqrt(0.5 * Q->qp); /* Set P->a to authalic radius. */ P->ra = 1.0 / P->a; @@ -673,3 +683,10 @@ PJ *PROJECTION(rhealpix) { return P; } + +#undef R1 +#undef R2 +#undef R3 +#undef IDENT +#undef ROT +#undef EPS diff --git a/src/projections/igh.cpp b/src/projections/igh.cpp index a0a38d00f8..1f321ec0bd 100644 --- a/src/projections/igh.cpp +++ b/src/projections/igh.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -13,7 +13,7 @@ This projection is a compilation of 12 separate sub-projections. Sinusoidal projections are found near the equator and Mollweide projections are found at higher latitudes. The transition between the two occurs at 40 degrees latitude and is represented by the -constant `phi_boundary`. +constant `igh_phi_boundary`. Each sub-projection is assigned an integer label numbered 1 through 12. Most of this code contains logic to assign @@ -32,41 +32,43 @@ Transition from sinusoidal to Mollweide projection Latitude (phi): 40deg 44' 11.8" */ -static const double phi_boundary = (40 + 44 / 60. + 11.8 / 3600.) * DEG_TO_RAD; - -static const double d10 = 10 * DEG_TO_RAD; -static const double d20 = 20 * DEG_TO_RAD; -static const double d30 = 30 * DEG_TO_RAD; -static const double d40 = 40 * DEG_TO_RAD; -static const double d50 = 50 * DEG_TO_RAD; -static const double d60 = 60 * DEG_TO_RAD; -static const double d80 = 80 * DEG_TO_RAD; -static const double d90 = 90 * DEG_TO_RAD; -static const double d100 = 100 * DEG_TO_RAD; -static const double d140 = 140 * DEG_TO_RAD; -static const double d160 = 160 * DEG_TO_RAD; -static const double d180 = 180 * DEG_TO_RAD; - -static const double EPSLN = - 1.e-10; /* allow a little 'slack' on zone edge positions */ +constexpr double igh_phi_boundary = (40 + 44 / 60. + 11.8 / 3600.) * DEG_TO_RAD; -namespace { // anonymous namespace -struct pj_opaque { +namespace pj_igh_ns { +struct pj_igh_data { struct PJconsts *pj[12]; double dy0; }; -} // anonymous namespace + +constexpr double d10 = 10 * DEG_TO_RAD; +constexpr double d20 = 20 * DEG_TO_RAD; +constexpr double d30 = 30 * DEG_TO_RAD; +constexpr double d40 = 40 * DEG_TO_RAD; +constexpr double d50 = 50 * DEG_TO_RAD; +constexpr double d60 = 60 * DEG_TO_RAD; +constexpr double d80 = 80 * DEG_TO_RAD; +constexpr double d90 = 90 * DEG_TO_RAD; +constexpr double d100 = 100 * DEG_TO_RAD; +constexpr double d140 = 140 * DEG_TO_RAD; +constexpr double d160 = 160 * DEG_TO_RAD; +constexpr double d180 = 180 * DEG_TO_RAD; + +constexpr double EPSLN = + 1.e-10; /* allow a little 'slack' on zone edge positions */ + +} // namespace pj_igh_ns static PJ_XY igh_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ + using namespace pj_igh_ns; PJ_XY xy; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_igh_data *Q = static_cast(P->opaque); int z; - if (lp.phi >= phi_boundary) { /* 1|2 */ + if (lp.phi >= igh_phi_boundary) { /* 1|2 */ z = (lp.lam <= -d40 ? 1 : 2); } else if (lp.phi >= 0) { /* 3|4 */ z = (lp.lam <= -d40 ? 3 : 4); - } else if (lp.phi >= -phi_boundary) { /* 5|6|7|8 */ + } else if (lp.phi >= -igh_phi_boundary) { /* 5|6|7|8 */ if (lp.lam <= -d100) z = 5; /* 5 */ else if (lp.lam <= -d20) @@ -95,19 +97,20 @@ static PJ_XY igh_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ } static PJ_LP igh_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ + using namespace pj_igh_ns; PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_igh_data *Q = static_cast(P->opaque); const double y90 = Q->dy0 + sqrt(2.0); /* lt=90 corresponds to y=y0+sqrt(2) */ int z = 0; if (xy.y > y90 + EPSLN || xy.y < -y90 + EPSLN) /* 0 */ z = 0; - else if (xy.y >= phi_boundary) /* 1|2 */ + else if (xy.y >= igh_phi_boundary) /* 1|2 */ z = (xy.x <= -d40 ? 1 : 2); else if (xy.y >= 0) /* 3|4 */ z = (xy.x <= -d40 ? 3 : 4); - else if (xy.y >= -phi_boundary) { /* 5|6|7|8 */ + else if (xy.y >= -igh_phi_boundary) { /* 5|6|7|8 */ if (xy.x <= -d100) z = 5; /* 5 */ else if (xy.x <= -d20) @@ -190,7 +193,8 @@ static PJ_LP igh_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -static PJ *destructor(PJ *P, int errlev) { +static PJ *pj_igh_data_destructor(PJ *P, int errlev) { + using namespace pj_igh_ns; int i; if (nullptr == P) return nullptr; @@ -198,7 +202,7 @@ static PJ *destructor(PJ *P, int errlev) { if (nullptr == P->opaque) return pj_default_destructor(P, errlev); - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_igh_data *Q = static_cast(P->opaque); for (i = 0; i < 12; ++i) { if (Q->pj[i]) @@ -228,8 +232,9 @@ static PJ *destructor(PJ *P, int errlev) { -180 -100 -20 80 180 */ -static bool setup_zone(PJ *P, struct pj_opaque *Q, int n, PJ *(*proj_ptr)(PJ *), - double x_0, double y_0, double lon_0) { +static bool pj_igh_setup_zone(PJ *P, struct pj_igh_ns::pj_igh_data *Q, int n, + PJ *(*proj_ptr)(PJ *), double x_0, double y_0, + double lon_0) { if (!(Q->pj[n - 1] = proj_ptr(nullptr))) return false; if (!(Q->pj[n - 1] = proj_ptr(Q->pj[n - 1]))) @@ -241,28 +246,30 @@ static bool setup_zone(PJ *P, struct pj_opaque *Q, int n, PJ *(*proj_ptr)(PJ *), return true; } -PJ *PROJECTION(igh) { +PJ *PJ_PROJECTION(igh) { + using namespace pj_igh_ns; + PJ_XY xy1, xy3; - PJ_LP lp = {0, phi_boundary}; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + PJ_LP lp = {0, igh_phi_boundary}; + struct pj_igh_data *Q = static_cast( + calloc(1, sizeof(struct pj_igh_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; /* sinusoidal zones */ - if (!setup_zone(P, Q, 3, pj_sinu, -d100, 0, -d100) || - !setup_zone(P, Q, 4, pj_sinu, d30, 0, d30) || - !setup_zone(P, Q, 5, pj_sinu, -d160, 0, -d160) || - !setup_zone(P, Q, 6, pj_sinu, -d60, 0, -d60) || - !setup_zone(P, Q, 7, pj_sinu, d20, 0, d20) || - !setup_zone(P, Q, 8, pj_sinu, d140, 0, d140)) { - return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); + if (!pj_igh_setup_zone(P, Q, 3, pj_sinu, -d100, 0, -d100) || + !pj_igh_setup_zone(P, Q, 4, pj_sinu, d30, 0, d30) || + !pj_igh_setup_zone(P, Q, 5, pj_sinu, -d160, 0, -d160) || + !pj_igh_setup_zone(P, Q, 6, pj_sinu, -d60, 0, -d60) || + !pj_igh_setup_zone(P, Q, 7, pj_sinu, d20, 0, d20) || + !pj_igh_setup_zone(P, Q, 8, pj_sinu, d140, 0, d140)) { + return pj_igh_data_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); } /* mollweide zones */ - if (!setup_zone(P, Q, 1, pj_moll, -d100, 0, -d100)) { - return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); + if (!pj_igh_setup_zone(P, Q, 1, pj_moll, -d100, 0, -d100)) { + return pj_igh_data_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); } /* y0 ? */ @@ -274,17 +281,17 @@ PJ *PROJECTION(igh) { Q->pj[0]->y0 = Q->dy0; /* mollweide zones (cont'd) */ - if (!setup_zone(P, Q, 2, pj_moll, d30, Q->dy0, d30) || - !setup_zone(P, Q, 9, pj_moll, -d160, -Q->dy0, -d160) || - !setup_zone(P, Q, 10, pj_moll, -d60, -Q->dy0, -d60) || - !setup_zone(P, Q, 11, pj_moll, d20, -Q->dy0, d20) || - !setup_zone(P, Q, 12, pj_moll, d140, -Q->dy0, d140)) { - return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); + if (!pj_igh_setup_zone(P, Q, 2, pj_moll, d30, Q->dy0, d30) || + !pj_igh_setup_zone(P, Q, 9, pj_moll, -d160, -Q->dy0, -d160) || + !pj_igh_setup_zone(P, Q, 10, pj_moll, -d60, -Q->dy0, -d60) || + !pj_igh_setup_zone(P, Q, 11, pj_moll, d20, -Q->dy0, d20) || + !pj_igh_setup_zone(P, Q, 12, pj_moll, d140, -Q->dy0, d140)) { + return pj_igh_data_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); } P->inv = igh_s_inverse; P->fwd = igh_s_forward; - P->destructor = destructor; + P->destructor = pj_igh_data_destructor; P->es = 0.; return P; diff --git a/src/projections/igh_o.cpp b/src/projections/igh_o.cpp index 1e5ae3cce4..f7d37fc287 100644 --- a/src/projections/igh_o.cpp +++ b/src/projections/igh_o.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -14,7 +14,7 @@ projection that emphasizes ocean areas. The projection is a compilation of 12 separate sub-projections. Sinusoidal projections are found near the equator and Mollweide projections are found at higher latitudes. The transition between the two occurs at 40 degrees -latitude and is represented by `phi_boundary`. +latitude and is represented by `igh_o_phi_boundary`. Each sub-projection is assigned an integer label numbered 1 through 12. Most of this code contains logic to assign @@ -33,31 +33,33 @@ Transition from sinusoidal to Mollweide projection Latitude (phi): 40deg 44' 11.8" */ -static const double phi_boundary = (40 + 44 / 60. + 11.8 / 3600.) * DEG_TO_RAD; - -static const double d10 = 10 * DEG_TO_RAD; -static const double d20 = 20 * DEG_TO_RAD; -static const double d40 = 40 * DEG_TO_RAD; -static const double d50 = 50 * DEG_TO_RAD; -static const double d60 = 60 * DEG_TO_RAD; -static const double d90 = 90 * DEG_TO_RAD; -static const double d100 = 100 * DEG_TO_RAD; -static const double d110 = 110 * DEG_TO_RAD; -static const double d140 = 140 * DEG_TO_RAD; -static const double d150 = 150 * DEG_TO_RAD; -static const double d160 = 160 * DEG_TO_RAD; -static const double d130 = 130 * DEG_TO_RAD; -static const double d180 = 180 * DEG_TO_RAD; - -static const double EPSLN = - 1.e-10; /* allow a little 'slack' on zone edge positions */ +constexpr double igh_o_phi_boundary = + (40 + 44 / 60. + 11.8 / 3600.) * DEG_TO_RAD; -namespace { // anonymous namespace -struct pj_opaque { +namespace pj_igh_o_ns { +struct pj_igh_o_data { struct PJconsts *pj[12]; double dy0; }; -} // anonymous namespace + +constexpr double d10 = 10 * DEG_TO_RAD; +constexpr double d20 = 20 * DEG_TO_RAD; +constexpr double d40 = 40 * DEG_TO_RAD; +constexpr double d50 = 50 * DEG_TO_RAD; +constexpr double d60 = 60 * DEG_TO_RAD; +constexpr double d90 = 90 * DEG_TO_RAD; +constexpr double d100 = 100 * DEG_TO_RAD; +constexpr double d110 = 110 * DEG_TO_RAD; +constexpr double d140 = 140 * DEG_TO_RAD; +constexpr double d150 = 150 * DEG_TO_RAD; +constexpr double d160 = 160 * DEG_TO_RAD; +constexpr double d130 = 130 * DEG_TO_RAD; +constexpr double d180 = 180 * DEG_TO_RAD; + +constexpr double EPSLN = + 1.e-10; /* allow a little 'slack' on zone edge positions */ + +} // namespace pj_igh_o_ns /* Assign an integer index representing each of the 12 @@ -66,11 +68,13 @@ longitude (lam) ranges. */ static PJ_XY igh_o_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ + using namespace pj_igh_o_ns; + PJ_XY xy; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_igh_o_data *Q = static_cast(P->opaque); int z; - if (lp.phi >= phi_boundary) { + if (lp.phi >= igh_o_phi_boundary) { if (lp.lam <= -d90) z = 1; else if (lp.lam >= d60) @@ -84,7 +88,7 @@ static PJ_XY igh_o_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ z = 6; else z = 5; - } else if (lp.phi >= -phi_boundary) { + } else if (lp.phi >= -igh_o_phi_boundary) { if (lp.lam <= -d60) z = 7; else if (lp.lam >= d90) @@ -109,15 +113,17 @@ static PJ_XY igh_o_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ } static PJ_LP igh_o_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ + using namespace pj_igh_o_ns; + PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_igh_o_data *Q = static_cast(P->opaque); const double y90 = Q->dy0 + sqrt(2.0); /* lt=90 corresponds to y=y0+sqrt(2) */ int z = 0; if (xy.y > y90 + EPSLN || xy.y < -y90 + EPSLN) /* 0 */ z = 0; - else if (xy.y >= phi_boundary) + else if (xy.y >= igh_o_phi_boundary) if (xy.x <= -d90) z = 1; else if (xy.x >= d60) @@ -131,7 +137,7 @@ static PJ_LP igh_o_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ z = 6; else z = 5; - else if (xy.y >= -phi_boundary) { + else if (xy.y >= -igh_o_phi_boundary) { if (xy.x <= -d60) z = 7; else if (xy.x >= d90) @@ -211,7 +217,9 @@ static PJ_LP igh_o_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -static PJ *destructor(PJ *P, int errlev) { +static PJ *pj_igh_o_destructor(PJ *P, int errlev) { + using namespace pj_igh_o_ns; + int i; if (nullptr == P) return nullptr; @@ -219,7 +227,7 @@ static PJ *destructor(PJ *P, int errlev) { if (nullptr == P->opaque) return pj_default_destructor(P, errlev); - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_igh_o_data *Q = static_cast(P->opaque); for (i = 0; i < 12; ++i) { if (Q->pj[i]) @@ -249,8 +257,9 @@ static PJ *destructor(PJ *P, int errlev) { -180 -60 90 180 */ -static bool setup_zone(PJ *P, struct pj_opaque *Q, int n, PJ *(*proj_ptr)(PJ *), - double x_0, double y_0, double lon_0) { +static bool pj_igh_o_setup_zone(PJ *P, struct pj_igh_o_ns::pj_igh_o_data *Q, + int n, PJ *(*proj_ptr)(PJ *), double x_0, + double y_0, double lon_0) { if (!(Q->pj[n - 1] = proj_ptr(nullptr))) return false; if (!(Q->pj[n - 1] = proj_ptr(Q->pj[n - 1]))) @@ -262,28 +271,30 @@ static bool setup_zone(PJ *P, struct pj_opaque *Q, int n, PJ *(*proj_ptr)(PJ *), return true; } -PJ *PROJECTION(igh_o) { +PJ *PJ_PROJECTION(igh_o) { + using namespace pj_igh_o_ns; + PJ_XY xy1, xy4; - PJ_LP lp = {0, phi_boundary}; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + PJ_LP lp = {0, igh_o_phi_boundary}; + struct pj_igh_o_data *Q = static_cast( + calloc(1, sizeof(struct pj_igh_o_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; /* sinusoidal zones */ - if (!setup_zone(P, Q, 4, pj_sinu, -d140, 0, -d140) || - !setup_zone(P, Q, 5, pj_sinu, -d10, 0, -d10) || - !setup_zone(P, Q, 6, pj_sinu, d130, 0, d130) || - !setup_zone(P, Q, 7, pj_sinu, -d110, 0, -d110) || - !setup_zone(P, Q, 8, pj_sinu, d20, 0, d20) || - !setup_zone(P, Q, 9, pj_sinu, d150, 0, d150)) { - return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); + if (!pj_igh_o_setup_zone(P, Q, 4, pj_sinu, -d140, 0, -d140) || + !pj_igh_o_setup_zone(P, Q, 5, pj_sinu, -d10, 0, -d10) || + !pj_igh_o_setup_zone(P, Q, 6, pj_sinu, d130, 0, d130) || + !pj_igh_o_setup_zone(P, Q, 7, pj_sinu, -d110, 0, -d110) || + !pj_igh_o_setup_zone(P, Q, 8, pj_sinu, d20, 0, d20) || + !pj_igh_o_setup_zone(P, Q, 9, pj_sinu, d150, 0, d150)) { + return pj_igh_o_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); } /* mollweide zones */ - if (!setup_zone(P, Q, 1, pj_moll, -d140, 0, -d140)) { - return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); + if (!pj_igh_o_setup_zone(P, Q, 1, pj_moll, -d140, 0, -d140)) { + return pj_igh_o_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); } /* y0 ? */ @@ -295,17 +306,17 @@ PJ *PROJECTION(igh_o) { Q->pj[0]->y0 = Q->dy0; /* mollweide zones (cont'd) */ - if (!setup_zone(P, Q, 2, pj_moll, -d10, Q->dy0, -d10) || - !setup_zone(P, Q, 3, pj_moll, d130, Q->dy0, d130) || - !setup_zone(P, Q, 10, pj_moll, -d110, -Q->dy0, -d110) || - !setup_zone(P, Q, 11, pj_moll, d20, -Q->dy0, d20) || - !setup_zone(P, Q, 12, pj_moll, d150, -Q->dy0, d150)) { - return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); + if (!pj_igh_o_setup_zone(P, Q, 2, pj_moll, -d10, Q->dy0, -d10) || + !pj_igh_o_setup_zone(P, Q, 3, pj_moll, d130, Q->dy0, d130) || + !pj_igh_o_setup_zone(P, Q, 10, pj_moll, -d110, -Q->dy0, -d110) || + !pj_igh_o_setup_zone(P, Q, 11, pj_moll, d20, -Q->dy0, d20) || + !pj_igh_o_setup_zone(P, Q, 12, pj_moll, d150, -Q->dy0, d150)) { + return pj_igh_o_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); } P->inv = igh_o_s_inverse; P->fwd = igh_o_s_forward; - P->destructor = destructor; + P->destructor = pj_igh_o_destructor; P->es = 0.; return P; diff --git a/src/projections/imoll.cpp b/src/projections/imoll.cpp index 17c898c53f..3a1e89fb55 100644 --- a/src/projections/imoll.cpp +++ b/src/projections/imoll.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -27,24 +27,25 @@ J. Paul Goode (1919) STUDIES IN PROJECTIONS: ADAPTING THE C_NAMESPACE PJ *pj_moll(PJ *); -static const double d20 = 20 * DEG_TO_RAD; -static const double d30 = 30 * DEG_TO_RAD; -static const double d40 = 40 * DEG_TO_RAD; -static const double d60 = 60 * DEG_TO_RAD; -static const double d80 = 80 * DEG_TO_RAD; -static const double d100 = 100 * DEG_TO_RAD; -static const double d140 = 140 * DEG_TO_RAD; -static const double d160 = 160 * DEG_TO_RAD; -static const double d180 = 180 * DEG_TO_RAD; - -static const double EPSLN = - 1.e-10; /* allow a little 'slack' on zone edge positions */ - -namespace { // anonymous namespace -struct pj_opaque { +namespace pj_imoll_ns { +struct pj_imoll_data { struct PJconsts *pj[6]; }; -} // anonymous namespace + +constexpr double d20 = 20 * DEG_TO_RAD; +constexpr double d30 = 30 * DEG_TO_RAD; +constexpr double d40 = 40 * DEG_TO_RAD; +constexpr double d60 = 60 * DEG_TO_RAD; +constexpr double d80 = 80 * DEG_TO_RAD; +constexpr double d100 = 100 * DEG_TO_RAD; +constexpr double d140 = 140 * DEG_TO_RAD; +constexpr double d160 = 160 * DEG_TO_RAD; +constexpr double d180 = 180 * DEG_TO_RAD; + +constexpr double EPSLN = + 1.e-10; /* allow a little 'slack' on zone edge positions */ + +} // namespace pj_imoll_ns /* Assign an integer index representing each of the 6 @@ -53,8 +54,10 @@ longitude (lam) ranges. */ static PJ_XY imoll_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ + using namespace pj_imoll_ns; + PJ_XY xy; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_imoll_data *Q = static_cast(P->opaque); int z; if (lp.phi >= 0) { /* 1|2 */ @@ -79,8 +82,10 @@ static PJ_XY imoll_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ } static PJ_LP imoll_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ + using namespace pj_imoll_ns; + PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_imoll_data *Q = static_cast(P->opaque); const double y90 = sqrt(2.0); /* lt=90 corresponds to y=sqrt(2) */ int z = 0; @@ -144,7 +149,9 @@ static PJ_LP imoll_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -static PJ *destructor(PJ *P, int errlev) { +static PJ *pj_imoll_destructor(PJ *P, int errlev) { + using namespace pj_imoll_ns; + int i; if (nullptr == P) return nullptr; @@ -152,7 +159,7 @@ static PJ *destructor(PJ *P, int errlev) { if (nullptr == P->opaque) return pj_default_destructor(P, errlev); - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_imoll_data *Q = static_cast(P->opaque); for (i = 0; i < 6; ++i) { if (Q->pj[i]) @@ -182,8 +189,9 @@ static PJ *destructor(PJ *P, int errlev) { -180 -100 -20 80 180 */ -static bool setup_zone(PJ *P, struct pj_opaque *Q, int n, PJ *(*proj_ptr)(PJ *), - double x_0, double y_0, double lon_0) { +static bool setup_zone(PJ *P, struct pj_imoll_ns::pj_imoll_data *Q, int n, + PJ *(*proj_ptr)(PJ *), double x_0, double y_0, + double lon_0) { if (!(Q->pj[n - 1] = proj_ptr(nullptr))) return false; if (!(Q->pj[n - 1] = proj_ptr(Q->pj[n - 1]))) @@ -195,8 +203,9 @@ static bool setup_zone(PJ *P, struct pj_opaque *Q, int n, PJ *(*proj_ptr)(PJ *), return true; } -static double compute_zone_offset(struct pj_opaque *Q, int zone1, int zone2, - double lam, double phi1, double phi2) { +static double compute_zone_offset(struct pj_imoll_ns::pj_imoll_data *Q, + int zone1, int zone2, double lam, double phi1, + double phi2) { PJ_LP lp1, lp2; PJ_XY xy1, xy2; @@ -209,9 +218,11 @@ static double compute_zone_offset(struct pj_opaque *Q, int zone1, int zone2, return (xy2.x + Q->pj[zone2 - 1]->x0) - (xy1.x + Q->pj[zone1 - 1]->x0); } -PJ *PROJECTION(imoll) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(imoll) { + using namespace pj_imoll_ns; + + struct pj_imoll_data *Q = static_cast( + calloc(1, sizeof(struct pj_imoll_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -223,7 +234,7 @@ PJ *PROJECTION(imoll) { !setup_zone(P, Q, 4, pj_moll, -d60, 0, -d60) || !setup_zone(P, Q, 5, pj_moll, d20, 0, d20) || !setup_zone(P, Q, 6, pj_moll, d140, 0, d140)) { - return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); + return pj_imoll_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); } /* Adjust zones */ @@ -249,7 +260,7 @@ PJ *PROJECTION(imoll) { P->inv = imoll_s_inverse; P->fwd = imoll_s_forward; - P->destructor = destructor; + P->destructor = pj_imoll_destructor; P->es = 0.; return P; diff --git a/src/projections/imoll_o.cpp b/src/projections/imoll_o.cpp index f6ddb07723..5b9d27f7dc 100644 --- a/src/projections/imoll_o.cpp +++ b/src/projections/imoll_o.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -29,25 +29,26 @@ J. Paul Goode (1919) STUDIES IN PROJECTIONS: ADAPTING THE C_NAMESPACE PJ *pj_moll(PJ *); +namespace pj_imoll_o_ns { +struct pj_imoll_o_data { + struct PJconsts *pj[6]; +}; + /* SIMPLIFY THIS */ -static const double d10 = 10 * DEG_TO_RAD; -static const double d20 = 20 * DEG_TO_RAD; -static const double d60 = 60 * DEG_TO_RAD; -static const double d90 = 90 * DEG_TO_RAD; -static const double d110 = 110 * DEG_TO_RAD; -static const double d130 = 130 * DEG_TO_RAD; -static const double d140 = 140 * DEG_TO_RAD; -static const double d150 = 150 * DEG_TO_RAD; -static const double d180 = 180 * DEG_TO_RAD; - -static const double EPSLN = +constexpr double d10 = 10 * DEG_TO_RAD; +constexpr double d20 = 20 * DEG_TO_RAD; +constexpr double d60 = 60 * DEG_TO_RAD; +constexpr double d90 = 90 * DEG_TO_RAD; +constexpr double d110 = 110 * DEG_TO_RAD; +constexpr double d130 = 130 * DEG_TO_RAD; +constexpr double d140 = 140 * DEG_TO_RAD; +constexpr double d150 = 150 * DEG_TO_RAD; +constexpr double d180 = 180 * DEG_TO_RAD; + +constexpr double EPSLN = 1.e-10; /* allow a little 'slack' on zone edge positions */ -namespace { // anonymous namespace -struct pj_opaque { - struct PJconsts *pj[6]; -}; -} // anonymous namespace +} // namespace pj_imoll_o_ns /* Assign an integer index representing each of the 6 @@ -56,8 +57,11 @@ longitude (lam) ranges. */ static PJ_XY imoll_o_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ + using namespace pj_imoll_o_ns; + PJ_XY xy; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_imoll_o_data *Q = + static_cast(P->opaque); int z; if (lp.phi >= 0) { /* 1|2|3 */ @@ -85,8 +89,11 @@ static PJ_XY imoll_o_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ } static PJ_LP imoll_o_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ + using namespace pj_imoll_o_ns; + PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_imoll_o_data *Q = + static_cast(P->opaque); const double y90 = sqrt(2.0); /* lt=90 corresponds to y=sqrt(2) */ int z = 0; @@ -153,7 +160,9 @@ static PJ_LP imoll_o_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -static PJ *destructor(PJ *P, int errlev) { +static PJ *pj_imoll_o_destructor(PJ *P, int errlev) { + using namespace pj_imoll_o_ns; + int i; if (nullptr == P) return nullptr; @@ -161,7 +170,8 @@ static PJ *destructor(PJ *P, int errlev) { if (nullptr == P->opaque) return pj_default_destructor(P, errlev); - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_imoll_o_data *Q = + static_cast(P->opaque); for (i = 0; i < 6; ++i) { if (Q->pj[i]) @@ -191,8 +201,10 @@ static PJ *destructor(PJ *P, int errlev) { -180 -60 90 180 */ -static bool setup_zone(PJ *P, struct pj_opaque *Q, int n, PJ *(*proj_ptr)(PJ *), - double x_0, double y_0, double lon_0) { +static bool pj_imoll_o_setup_zone(PJ *P, + struct pj_imoll_o_ns::pj_imoll_o_data *Q, + int n, PJ *(*proj_ptr)(PJ *), double x_0, + double y_0, double lon_0) { if (!(Q->pj[n - 1] = proj_ptr(nullptr))) return false; if (!(Q->pj[n - 1] = proj_ptr(Q->pj[n - 1]))) @@ -204,8 +216,10 @@ static bool setup_zone(PJ *P, struct pj_opaque *Q, int n, PJ *(*proj_ptr)(PJ *), return true; } -static double compute_zone_offset(struct pj_opaque *Q, int zone1, int zone2, - double lam, double phi1, double phi2) { +static double +pj_imoll_o_compute_zone_offset(struct pj_imoll_o_ns::pj_imoll_o_data *Q, + int zone1, int zone2, double lam, double phi1, + double phi2) { PJ_LP lp1, lp2; PJ_XY xy1, xy2; @@ -218,46 +232,50 @@ static double compute_zone_offset(struct pj_opaque *Q, int zone1, int zone2, return (xy2.x + Q->pj[zone2 - 1]->x0) - (xy1.x + Q->pj[zone1 - 1]->x0); } -PJ *PROJECTION(imoll_o) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(imoll_o) { + using namespace pj_imoll_o_ns; + + struct pj_imoll_o_data *Q = static_cast( + calloc(1, sizeof(struct pj_imoll_o_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; /* Setup zones */ - if (!setup_zone(P, Q, 1, pj_moll, -d140, 0, -d140) || - !setup_zone(P, Q, 2, pj_moll, -d10, 0, -d10) || - !setup_zone(P, Q, 3, pj_moll, d130, 0, d130) || - !setup_zone(P, Q, 4, pj_moll, -d110, 0, -d110) || - !setup_zone(P, Q, 5, pj_moll, d20, 0, d20) || - !setup_zone(P, Q, 6, pj_moll, d150, 0, d150)) { - return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); + if (!pj_imoll_o_setup_zone(P, Q, 1, pj_moll, -d140, 0, -d140) || + !pj_imoll_o_setup_zone(P, Q, 2, pj_moll, -d10, 0, -d10) || + !pj_imoll_o_setup_zone(P, Q, 3, pj_moll, d130, 0, d130) || + !pj_imoll_o_setup_zone(P, Q, 4, pj_moll, -d110, 0, -d110) || + !pj_imoll_o_setup_zone(P, Q, 5, pj_moll, d20, 0, d20) || + !pj_imoll_o_setup_zone(P, Q, 6, pj_moll, d150, 0, d150)) { + return pj_imoll_o_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); } /* Adjust zones */ /* Match 2 (center) to 1 (west) */ Q->pj[1]->x0 += - compute_zone_offset(Q, 2, 1, -d90, 0.0 + EPSLN, 0.0 + EPSLN); + pj_imoll_o_compute_zone_offset(Q, 2, 1, -d90, 0.0 + EPSLN, 0.0 + EPSLN); /* Match 3 (east) to 2 (center) */ - Q->pj[2]->x0 += compute_zone_offset(Q, 3, 2, d60, 0.0 + EPSLN, 0.0 + EPSLN); + Q->pj[2]->x0 += + pj_imoll_o_compute_zone_offset(Q, 3, 2, d60, 0.0 + EPSLN, 0.0 + EPSLN); /* Match 4 (south) to 1 (north) */ - Q->pj[3]->x0 += - compute_zone_offset(Q, 4, 1, -d180, 0.0 - EPSLN, 0.0 + EPSLN); + Q->pj[3]->x0 += pj_imoll_o_compute_zone_offset(Q, 4, 1, -d180, 0.0 - EPSLN, + 0.0 + EPSLN); /* Match 5 (south) to 2 (north) */ Q->pj[4]->x0 += - compute_zone_offset(Q, 5, 2, -d60, 0.0 - EPSLN, 0.0 + EPSLN); + pj_imoll_o_compute_zone_offset(Q, 5, 2, -d60, 0.0 - EPSLN, 0.0 + EPSLN); /* Match 6 (south) to 3 (north) */ - Q->pj[5]->x0 += compute_zone_offset(Q, 6, 3, d90, 0.0 - EPSLN, 0.0 + EPSLN); + Q->pj[5]->x0 += + pj_imoll_o_compute_zone_offset(Q, 6, 3, d90, 0.0 - EPSLN, 0.0 + EPSLN); P->inv = imoll_o_s_inverse; P->fwd = imoll_o_s_forward; - P->destructor = destructor; + P->destructor = pj_imoll_o_destructor; P->es = 0.; return P; diff --git a/src/projections/imw_p.cpp b/src/projections/imw_p.cpp index 4ba108036d..5ad93a9d63 100644 --- a/src/projections/imw_p.cpp +++ b/src/projections/imw_p.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -21,7 +21,7 @@ enum Mode { } // anonymous namespace namespace { // anonymous namespace -struct pj_opaque { +struct pj_imw_p_data { double P, Pp, Q, Qp, R_1, R_2, sphi_1, sphi_2, C2; double phi_1, phi_2, lam_1; double *en; @@ -30,7 +30,7 @@ struct pj_opaque { } // anonymous namespace static int phi12(PJ *P, double *del, double *sig) { - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_imw_p_data *Q = static_cast(P->opaque); int err = 0; if (!pj_param(P->ctx, P->params, "tlat_1").i) { @@ -57,7 +57,7 @@ static int phi12(PJ *P, double *del, double *sig) { } static PJ_XY loc_for(PJ_LP lp, PJ *P, double *yc) { - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_imw_p_data *Q = static_cast(P->opaque); PJ_XY xy; if (lp.phi == 0.0) { @@ -113,7 +113,7 @@ static PJ_XY imw_p_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ static PJ_LP imw_p_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_imw_p_data *Q = static_cast(P->opaque); PJ_XY t; double yc = 0.0; int i = 0; @@ -151,29 +151,29 @@ static void xy(PJ *P, double phi, double *x, double *y, double *sp, double *R) { *sp = sin(phi); *R = 1. / (tan(phi) * sqrt(1. - P->es * *sp * *sp)); - F = static_cast(P->opaque)->lam_1 * *sp; + F = static_cast(P->opaque)->lam_1 * *sp; *y = *R * (1 - cos(F)); *x = *R * sin(F); } -static PJ *destructor(PJ *P, int errlev) { +static PJ *pj_imw_p_destructor(PJ *P, int errlev) { if (nullptr == P) return nullptr; if (nullptr == P->opaque) return pj_default_destructor(P, errlev); - if (static_cast(P->opaque)->en) - free(static_cast(P->opaque)->en); + if (static_cast(P->opaque)->en) + free(static_cast(P->opaque)->en); return pj_default_destructor(P, errlev); } -PJ *PROJECTION(imw_p) { +PJ *PJ_PROJECTION(imw_p) { double del, sig, s, t, x1, x2, T2, y1, m1, m2, y2; int err; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_imw_p_data *Q = static_cast( + calloc(1, sizeof(struct pj_imw_p_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -181,7 +181,7 @@ PJ *PROJECTION(imw_p) { if (!(Q->en = pj_enfn(P->n))) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); if ((err = phi12(P, &del, &sig)) != 0) { - return destructor(P, err); + return pj_imw_p_destructor(P, err); } if (Q->phi_2 < Q->phi_1) { /* make sure P->phi_1 most southerly */ del = Q->phi_1; @@ -229,7 +229,10 @@ PJ *PROJECTION(imw_p) { P->fwd = imw_p_e_forward; P->inv = imw_p_e_inverse; - P->destructor = destructor; + P->destructor = pj_imw_p_destructor; return P; } + +#undef TOL +#undef EPS diff --git a/src/projections/isea.cpp b/src/projections/isea.cpp index f547e7fb2f..8ff5009edc 100644 --- a/src/projections/isea.cpp +++ b/src/projections/isea.cpp @@ -12,7 +12,6 @@ #include -#define PJ_LIB_ #include "proj.h" #include "proj_internal.h" #include @@ -985,14 +984,14 @@ static struct isea_pt isea_forward(struct isea_dgg *g, struct isea_geo *in) { PROJ_HEAD(isea, "Icosahedral Snyder Equal Area") "\n\tSph"; namespace { // anonymous namespace -struct pj_opaque { +struct pj_isea_data { struct isea_dgg dgg; }; } // anonymous namespace static PJ_XY isea_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_isea_data *Q = static_cast(P->opaque); struct isea_pt out; struct isea_geo in; @@ -1012,10 +1011,10 @@ static PJ_XY isea_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ return xy; } -PJ *PROJECTION(isea) { +PJ *PJ_PROJECTION(isea) { char *opt; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_isea_data *Q = static_cast( + calloc(1, sizeof(struct pj_isea_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -1092,3 +1091,19 @@ PJ *PROJECTION(isea) { return P; } + +#undef DEG36 +#undef DEG72 +#undef DEG90 +#undef DEG108 +#undef DEG120 +#undef DEG144 +#undef DEG180 +#undef ISEA_SCALE +#undef V_LAT +#undef E_RAD +#undef F_RAD +#undef TABLE_G +#undef TABLE_H +#undef ISEA_STD_LAT +#undef ISEA_STD_LONG diff --git a/src/projections/krovak.cpp b/src/projections/krovak.cpp index 775db4548b..ef5cf65c9d 100644 --- a/src/projections/krovak.cpp +++ b/src/projections/krovak.cpp @@ -75,8 +75,6 @@ * *****************************************************************************/ -#define PJ_LIB_ - #include #include @@ -93,7 +91,7 @@ PROJ_HEAD(krovak, "Krovak") "\n\tPCyl, Ell"; #define MAX_ITER 100 namespace { // anonymous namespace -struct pj_opaque { +struct pj_krovak_data { double alpha; double k; double n; @@ -104,7 +102,7 @@ struct pj_opaque { } // anonymous namespace static PJ_XY krovak_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_krovak_data *Q = static_cast(P->opaque); PJ_XY xy = {0.0, 0.0}; double gfi, u, deltav, s, d, eps, rho; @@ -139,7 +137,7 @@ static PJ_XY krovak_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ } static PJ_LP krovak_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_krovak_data *Q = static_cast(P->opaque); PJ_LP lp = {0.0, 0.0}; double u, deltav, s, d, eps, rho, fi1, xy0; @@ -191,10 +189,10 @@ static PJ_LP krovak_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ return lp; } -PJ *PROJECTION(krovak) { +PJ *PJ_PROJECTION(krovak) { double u0, n0, g; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_krovak_data *Q = static_cast( + calloc(1, sizeof(struct pj_krovak_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -245,3 +243,8 @@ PJ *PROJECTION(krovak) { return P; } + +#undef EPS +#undef UQ +#undef S0 +#undef MAX_ITER diff --git a/src/projections/labrd.cpp b/src/projections/labrd.cpp index 1b1eadda80..9353e0acb1 100644 --- a/src/projections/labrd.cpp +++ b/src/projections/labrd.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -100,7 +100,7 @@ static PJ_LP labrd_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ return lp; } -PJ *PROJECTION(labrd) { +PJ *PJ_PROJECTION(labrd) { double Az, sinp, R, N, t; struct pj_opaque *Q = static_cast(calloc(1, sizeof(struct pj_opaque))); diff --git a/src/projections/laea.cpp b/src/projections/laea.cpp index 976ffa02ce..1c773c4711 100644 --- a/src/projections/laea.cpp +++ b/src/projections/laea.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include "proj.h" #include "proj_internal.h" #include @@ -6,12 +6,12 @@ PROJ_HEAD(laea, "Lambert Azimuthal Equal Area") "\n\tAzi, Sph&Ell"; -namespace { // anonymous namespace +namespace pj_laea_ns { enum Mode { N_POLE = 0, S_POLE = 1, EQUIT = 2, OBLIQ = 3 }; -} // anonymous namespace +} namespace { // anonymous namespace -struct pj_opaque { +struct pj_laea_data { double sinb1; double cosb1; double xmf; @@ -21,7 +21,7 @@ struct pj_opaque { double dd; double rq; double *apa; - enum Mode mode; + enum pj_laea_ns::Mode mode; }; } // anonymous namespace @@ -29,7 +29,7 @@ struct pj_opaque { static PJ_XY laea_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_laea_data *Q = static_cast(P->opaque); double coslam, sinlam, sinphi, q, sinb = 0.0, cosb = 0.0, b = 0.0; coslam = cos(lp.lam); @@ -37,24 +37,24 @@ static PJ_XY laea_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ sinphi = sin(lp.phi); q = pj_qsfn(sinphi, P->e, P->one_es); - if (Q->mode == OBLIQ || Q->mode == EQUIT) { + if (Q->mode == pj_laea_ns::OBLIQ || Q->mode == pj_laea_ns::EQUIT) { sinb = q / Q->qp; const double cosb2 = 1. - sinb * sinb; cosb = cosb2 > 0 ? sqrt(cosb2) : 0; } switch (Q->mode) { - case OBLIQ: + case pj_laea_ns::OBLIQ: b = 1. + Q->sinb1 * sinb + Q->cosb1 * cosb * coslam; break; - case EQUIT: + case pj_laea_ns::EQUIT: b = 1. + cosb * coslam; break; - case N_POLE: + case pj_laea_ns::N_POLE: b = M_HALFPI + lp.phi; q = Q->qp - q; break; - case S_POLE: + case pj_laea_ns::S_POLE: b = lp.phi - M_HALFPI; q = Q->qp + q; break; @@ -65,23 +65,23 @@ static PJ_XY laea_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ } switch (Q->mode) { - case OBLIQ: + case pj_laea_ns::OBLIQ: b = sqrt(2. / b); xy.y = Q->ymf * b * (Q->cosb1 * sinb - Q->sinb1 * cosb * coslam); goto eqcon; break; - case EQUIT: + case pj_laea_ns::EQUIT: b = sqrt(2. / (1. + cosb * coslam)); xy.y = b * sinb * Q->ymf; eqcon: xy.x = Q->xmf * b * cosb * sinlam; break; - case N_POLE: - case S_POLE: + case pj_laea_ns::N_POLE: + case pj_laea_ns::S_POLE: if (q >= 1e-15) { b = sqrt(q); xy.x = b * sinlam; - xy.y = coslam * (Q->mode == S_POLE ? b : -b); + xy.y = coslam * (Q->mode == pj_laea_ns::S_POLE ? b : -b); } else xy.x = xy.y = 0.; break; @@ -91,17 +91,17 @@ static PJ_XY laea_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ static PJ_XY laea_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_laea_data *Q = static_cast(P->opaque); double coslam, cosphi, sinphi; sinphi = sin(lp.phi); cosphi = cos(lp.phi); coslam = cos(lp.lam); switch (Q->mode) { - case EQUIT: + case pj_laea_ns::EQUIT: xy.y = 1. + cosphi * coslam; goto oblcon; - case OBLIQ: + case pj_laea_ns::OBLIQ: xy.y = 1. + Q->sinb1 * sinphi + Q->cosb1 * cosphi * coslam; oblcon: if (xy.y <= EPS10) { @@ -110,20 +110,20 @@ static PJ_XY laea_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ } xy.y = sqrt(2. / xy.y); xy.x = xy.y * cosphi * sin(lp.lam); - xy.y *= Q->mode == EQUIT + xy.y *= Q->mode == pj_laea_ns::EQUIT ? sinphi : Q->cosb1 * sinphi - Q->sinb1 * cosphi * coslam; break; - case N_POLE: + case pj_laea_ns::N_POLE: coslam = -coslam; PROJ_FALLTHROUGH; - case S_POLE: + case pj_laea_ns::S_POLE: if (fabs(lp.phi + P->phi0) < EPS10) { proj_errno_set(P, PROJ_ERR_COORD_TRANSFM_OUTSIDE_PROJECTION_DOMAIN); return xy; } xy.y = M_FORTPI - lp.phi * .5; - xy.y = 2. * (Q->mode == S_POLE ? cos(xy.y) : sin(xy.y)); + xy.y = 2. * (Q->mode == pj_laea_ns::S_POLE ? cos(xy.y) : sin(xy.y)); xy.x = xy.y * sin(lp.lam); xy.y *= coslam; break; @@ -133,12 +133,12 @@ static PJ_XY laea_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP laea_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_laea_data *Q = static_cast(P->opaque); double cCe, sCe, q, rho, ab = 0.0; switch (Q->mode) { - case EQUIT: - case OBLIQ: { + case pj_laea_ns::EQUIT: + case pj_laea_ns::OBLIQ: { xy.x /= Q->dd; xy.y *= Q->dd; rho = hypot(xy.x, xy.y); @@ -156,7 +156,7 @@ static PJ_LP laea_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ cCe = cos(sCe); sCe = sin(sCe); xy.x *= sCe; - if (Q->mode == OBLIQ) { + if (Q->mode == pj_laea_ns::OBLIQ) { ab = cCe * Q->sinb1 + xy.y * sCe * Q->cosb1 / rho; xy.y = rho * Q->cosb1 * cCe - xy.y * Q->sinb1 * sCe; } else { @@ -165,10 +165,10 @@ static PJ_LP laea_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ } break; } - case N_POLE: + case pj_laea_ns::N_POLE: xy.y = -xy.y; PROJ_FALLTHROUGH; - case S_POLE: + case pj_laea_ns::S_POLE: q = (xy.x * xy.x + xy.y * xy.y); if (q == 0.0) { lp.lam = 0.; @@ -176,7 +176,7 @@ static PJ_LP laea_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ return (lp); } ab = 1. - q / Q->qp; - if (Q->mode == S_POLE) + if (Q->mode == pj_laea_ns::S_POLE) ab = -ab; break; } @@ -187,7 +187,7 @@ static PJ_LP laea_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ static PJ_LP laea_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_laea_data *Q = static_cast(P->opaque); double cosz = 0.0, rh, sinz = 0.0; rh = hypot(xy.x, xy.y); @@ -196,70 +196,71 @@ static PJ_LP laea_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } lp.phi = 2. * asin(lp.phi); - if (Q->mode == OBLIQ || Q->mode == EQUIT) { + if (Q->mode == pj_laea_ns::OBLIQ || Q->mode == pj_laea_ns::EQUIT) { sinz = sin(lp.phi); cosz = cos(lp.phi); } switch (Q->mode) { - case EQUIT: + case pj_laea_ns::EQUIT: lp.phi = fabs(rh) <= EPS10 ? 0. : asin(xy.y * sinz / rh); xy.x *= sinz; xy.y = cosz * rh; break; - case OBLIQ: + case pj_laea_ns::OBLIQ: lp.phi = fabs(rh) <= EPS10 ? P->phi0 : asin(cosz * Q->sinb1 + xy.y * sinz * Q->cosb1 / rh); xy.x *= sinz * Q->cosb1; xy.y = (cosz - sin(lp.phi) * Q->sinb1) * rh; break; - case N_POLE: + case pj_laea_ns::N_POLE: xy.y = -xy.y; lp.phi = M_HALFPI - lp.phi; break; - case S_POLE: + case pj_laea_ns::S_POLE: lp.phi -= M_HALFPI; break; } - lp.lam = (xy.y == 0. && (Q->mode == EQUIT || Q->mode == OBLIQ)) + lp.lam = (xy.y == 0. && + (Q->mode == pj_laea_ns::EQUIT || Q->mode == pj_laea_ns::OBLIQ)) ? 0. : atan2(xy.x, xy.y); return (lp); } -static PJ *destructor(PJ *P, int errlev) { +static PJ *pj_laea_destructor(PJ *P, int errlev) { if (nullptr == P) return nullptr; if (nullptr == P->opaque) return pj_default_destructor(P, errlev); - free(static_cast(P->opaque)->apa); + free(static_cast(P->opaque)->apa); return pj_default_destructor(P, errlev); } -PJ *PROJECTION(laea) { +PJ *PJ_PROJECTION(laea) { double t; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_laea_data *Q = static_cast( + calloc(1, sizeof(struct pj_laea_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; - P->destructor = destructor; + P->destructor = pj_laea_destructor; t = fabs(P->phi0); if (t > M_HALFPI + EPS10) { proj_log_error(P, _("Invalid value for lat_0: |lat_0| should be <= 90°")); - return destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); + return pj_laea_destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); } if (fabs(t - M_HALFPI) < EPS10) - Q->mode = P->phi0 < 0. ? S_POLE : N_POLE; + Q->mode = P->phi0 < 0. ? pj_laea_ns::S_POLE : pj_laea_ns::N_POLE; else if (fabs(t) < EPS10) - Q->mode = EQUIT; + Q->mode = pj_laea_ns::EQUIT; else - Q->mode = OBLIQ; + Q->mode = pj_laea_ns::OBLIQ; if (P->es != 0.0) { double sinphi; @@ -268,18 +269,18 @@ PJ *PROJECTION(laea) { Q->mmf = .5 / (1. - P->es); Q->apa = pj_authset(P->es); if (nullptr == Q->apa) - return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); + return pj_laea_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); switch (Q->mode) { - case N_POLE: - case S_POLE: + case pj_laea_ns::N_POLE: + case pj_laea_ns::S_POLE: Q->dd = 1.; break; - case EQUIT: + case pj_laea_ns::EQUIT: Q->dd = 1. / (Q->rq = sqrt(.5 * Q->qp)); Q->xmf = 1.; Q->ymf = .5 * Q->qp; break; - case OBLIQ: + case pj_laea_ns::OBLIQ: Q->rq = sqrt(.5 * Q->qp); sinphi = sin(P->phi0); Q->sinb1 = pj_qsfn(sinphi, P->e, P->one_es) / Q->qp; @@ -293,7 +294,7 @@ PJ *PROJECTION(laea) { P->inv = laea_e_inverse; P->fwd = laea_e_forward; } else { - if (Q->mode == OBLIQ) { + if (Q->mode == pj_laea_ns::OBLIQ) { Q->sinb1 = sin(P->phi0); Q->cosb1 = cos(P->phi0); } diff --git a/src/projections/lagrng.cpp b/src/projections/lagrng.cpp index 6f42fe0da6..34760db2a1 100644 --- a/src/projections/lagrng.cpp +++ b/src/projections/lagrng.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -10,7 +10,7 @@ PROJ_HEAD(lagrng, "Lagrange") "\n\tMisc Sph\n\tW="; #define TOL 1e-10 namespace { // anonymous namespace -struct pj_opaque { +struct pj_lagrng { double a1; double a2; double hrw; @@ -22,7 +22,7 @@ struct pj_opaque { static PJ_XY lagrng_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_lagrng *Q = static_cast(P->opaque); double v, c; const double sin_phi = sin(lp.phi); @@ -45,7 +45,7 @@ static PJ_XY lagrng_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP lagrng_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_lagrng *Q = static_cast(P->opaque); double c, x2, y2p, y2m; if (fabs(fabs(xy.y) - 2.) < TOL) { @@ -68,10 +68,10 @@ static PJ_LP lagrng_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(lagrng) { +PJ *PJ_PROJECTION(lagrng) { double sin_phi1; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_lagrng *Q = + static_cast(calloc(1, sizeof(struct pj_lagrng))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; diff --git a/src/projections/larr.cpp b/src/projections/larr.cpp index 2d57706c5b..4d3de103e0 100644 --- a/src/projections/larr.cpp +++ b/src/projections/larr.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -18,7 +18,7 @@ static PJ_XY larr_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ return xy; } -PJ *PROJECTION(larr) { +PJ *PJ_PROJECTION(larr) { P->es = 0; P->fwd = larr_s_forward; diff --git a/src/projections/lask.cpp b/src/projections/lask.cpp index bbae27b0fe..c90259684d 100644 --- a/src/projections/lask.cpp +++ b/src/projections/lask.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include "proj.h" #include "proj_internal.h" @@ -29,7 +29,7 @@ static PJ_XY lask_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ return xy; } -PJ *PROJECTION(lask) { +PJ *PJ_PROJECTION(lask) { P->fwd = lask_s_forward; P->es = 0.; diff --git a/src/projections/latlong.cpp b/src/projections/latlong.cpp index fc8618d87b..e4d8ef313d 100644 --- a/src/projections/latlong.cpp +++ b/src/projections/latlong.cpp @@ -28,7 +28,7 @@ *****************************************************************************/ /* very loosely based upon DMA code by Bradford W. Drew */ -#define PJ_LIB_ + #include "proj_internal.h" PROJ_HEAD(lonlat, "Lat/long (Geodetic)") "\n\t"; @@ -89,10 +89,10 @@ static PJ *latlong_setup(PJ *P) { return P; } -PJ *PROJECTION(latlong) { return latlong_setup(P); } +PJ *PJ_PROJECTION(latlong) { return latlong_setup(P); } -PJ *PROJECTION(longlat) { return latlong_setup(P); } +PJ *PJ_PROJECTION(longlat) { return latlong_setup(P); } -PJ *PROJECTION(latlon) { return latlong_setup(P); } +PJ *PJ_PROJECTION(latlon) { return latlong_setup(P); } -PJ *PROJECTION(lonlat) { return latlong_setup(P); } +PJ *PJ_PROJECTION(lonlat) { return latlong_setup(P); } diff --git a/src/projections/lcc.cpp b/src/projections/lcc.cpp index f3f0f92736..e0309ee7c0 100644 --- a/src/projections/lcc.cpp +++ b/src/projections/lcc.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include "proj.h" #include "proj_internal.h" #include @@ -10,7 +10,7 @@ PROJ_HEAD(lcc, "Lambert Conformal Conic") #define EPS10 1.e-10 namespace { // anonymous namespace -struct pj_opaque { +struct pj_lcc_data { double phi1; double phi2; double n; @@ -21,7 +21,7 @@ struct pj_opaque { static PJ_XY lcc_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ PJ_XY xy = {0., 0.}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_lcc_data *Q = static_cast(P->opaque); double rho; if (fabs(fabs(lp.phi) - M_HALFPI) < EPS10) { @@ -43,7 +43,7 @@ static PJ_XY lcc_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ static PJ_LP lcc_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ PJ_LP lp = {0., 0.}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_lcc_data *Q = static_cast(P->opaque); double rho; xy.x /= P->k0; @@ -75,11 +75,11 @@ static PJ_LP lcc_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ return lp; } -PJ *PROJECTION(lcc) { +PJ *PJ_PROJECTION(lcc) { double cosphi, sinphi; int secant; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_lcc_data *Q = static_cast( + calloc(1, sizeof(struct pj_lcc_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); @@ -169,3 +169,5 @@ PJ *PROJECTION(lcc) { return P; } + +#undef EPS10 diff --git a/src/projections/lcca.cpp b/src/projections/lcca.cpp index 8c4d89db1f..d13391a150 100644 --- a/src/projections/lcca.cpp +++ b/src/projections/lcca.cpp @@ -45,8 +45,6 @@ *****************************************************************************/ -#define PJ_LIB_ - #include #include @@ -60,7 +58,7 @@ PROJ_HEAD(lcca, "Lambert Conformal Conic Alternative") #define DEL_TOL 1e-12 namespace { // anonymous namespace -struct pj_opaque { +struct pj_lcca_data { double *en; double r0, l, M0; double C; @@ -79,7 +77,7 @@ static double fSp(double S, double C) { /* deriv of fs */ static PJ_XY lcca_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_lcca_data *Q = static_cast(P->opaque); double S, r, dr; S = pj_mlfn(lp.phi, sin(lp.phi), cos(lp.phi), Q->en) - Q->M0; @@ -93,7 +91,7 @@ static PJ_XY lcca_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ static PJ_LP lcca_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_lcca_data *Q = static_cast(P->opaque); double theta, dr, S, dif; int i; @@ -117,21 +115,21 @@ static PJ_LP lcca_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ return lp; } -static PJ *destructor(PJ *P, int errlev) { +static PJ *pj_lcca_destructor(PJ *P, int errlev) { if (nullptr == P) return nullptr; if (nullptr == P->opaque) return pj_default_destructor(P, errlev); - free(static_cast(P->opaque)->en); + free(static_cast(P->opaque)->en); return pj_default_destructor(P, errlev); } -PJ *PROJECTION(lcca) { +PJ *PJ_PROJECTION(lcca) { double s2p0, N0, R0, tan0; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_lcca_data *Q = static_cast( + calloc(1, sizeof(struct pj_lcca_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -143,7 +141,7 @@ PJ *PROJECTION(lcca) { if (P->phi0 == 0.) { proj_log_error( P, _("Invalid value for lat_0: it should be different from 0.")); - return destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); + return pj_lcca_destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); } Q->l = sin(P->phi0); Q->M0 = pj_mlfn(P->phi0, Q->l, cos(P->phi0), Q->en); @@ -157,7 +155,10 @@ PJ *PROJECTION(lcca) { P->inv = lcca_e_inverse; P->fwd = lcca_e_forward; - P->destructor = destructor; + P->destructor = pj_lcca_destructor; return P; } + +#undef MAX_ITER +#undef DEL_TOL diff --git a/src/projections/loxim.cpp b/src/projections/loxim.cpp index 1d7fbd8f6e..12020e02f3 100644 --- a/src/projections/loxim.cpp +++ b/src/projections/loxim.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -11,7 +11,7 @@ PROJ_HEAD(loxim, "Loximuthal") "\n\tPCyl Sph"; #define EPS 1e-8 namespace { // anonymous namespace -struct pj_opaque { +struct pj_loxim_data { double phi1; double cosphi1; double tanphi1; @@ -20,7 +20,7 @@ struct pj_opaque { static PJ_XY loxim_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_loxim_data *Q = static_cast(P->opaque); xy.y = lp.phi - Q->phi1; if (fabs(xy.y) < EPS) @@ -37,7 +37,7 @@ static PJ_XY loxim_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP loxim_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_loxim_data *Q = static_cast(P->opaque); lp.phi = xy.y + Q->phi1; if (fabs(xy.y) < EPS) { @@ -52,9 +52,9 @@ static PJ_LP loxim_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(loxim) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(loxim) { + struct pj_loxim_data *Q = static_cast( + calloc(1, sizeof(struct pj_loxim_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -75,3 +75,5 @@ PJ *PROJECTION(loxim) { return P; } + +#undef EPS diff --git a/src/projections/mbt_fps.cpp b/src/projections/mbt_fps.cpp index 6584ba6457..0c0becfedc 100644 --- a/src/projections/mbt_fps.cpp +++ b/src/projections/mbt_fps.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -45,7 +45,7 @@ static PJ_LP mbt_fps_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return (lp); } -PJ *PROJECTION(mbt_fps) { +PJ *PJ_PROJECTION(mbt_fps) { P->es = 0; P->inv = mbt_fps_s_inverse; @@ -53,3 +53,12 @@ PJ *PROJECTION(mbt_fps) { return P; } + +#undef MAX_ITER +#undef LOOP_TOL +#undef C1 +#undef C2 +#undef C3 +#undef C_x +#undef C_y +#undef C1_2 diff --git a/src/projections/mbtfpp.cpp b/src/projections/mbtfpp.cpp index 79c366b246..036aada3dc 100644 --- a/src/projections/mbtfpp.cpp +++ b/src/projections/mbtfpp.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -54,7 +54,7 @@ static PJ_LP mbtfpp_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(mbtfpp) { +PJ *PJ_PROJECTION(mbtfpp) { P->es = 0.; P->inv = mbtfpp_s_inverse; @@ -62,3 +62,10 @@ PJ *PROJECTION(mbtfpp) { return P; } + +#undef CSy +#undef FXC +#undef FYC +#undef C23 +#undef C13 +#undef ONEEPS diff --git a/src/projections/mbtfpq.cpp b/src/projections/mbtfpq.cpp index 0189a8a32b..13c744b091 100644 --- a/src/projections/mbtfpq.cpp +++ b/src/projections/mbtfpq.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -67,7 +67,7 @@ static PJ_LP mbtfpq_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(mbtfpq) { +PJ *PJ_PROJECTION(mbtfpq) { P->es = 0.; P->inv = mbtfpq_s_inverse; @@ -75,3 +75,13 @@ PJ *PROJECTION(mbtfpq) { return P; } + +#undef NITER +#undef EPS +#undef ONETOL +#undef C +#undef RC +#undef FYC +#undef RYC +#undef FXC +#undef RXC diff --git a/src/projections/merc.cpp b/src/projections/merc.cpp index da4f6e993c..86a6dc95e0 100644 --- a/src/projections/merc.cpp +++ b/src/projections/merc.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -42,7 +42,7 @@ static PJ_LP merc_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(merc) { +PJ *PJ_PROJECTION(merc) { double phits = 0.0; int is_phits; @@ -73,7 +73,7 @@ PJ *PROJECTION(merc) { return P; } -PJ *PROJECTION(webmerc) { +PJ *PJ_PROJECTION(webmerc) { /* Overriding k_0 with fixed parameter */ P->k0 = 1.0; diff --git a/src/projections/mill.cpp b/src/projections/mill.cpp index 91dbf8d931..f302e076db 100644 --- a/src/projections/mill.cpp +++ b/src/projections/mill.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -27,7 +27,7 @@ static PJ_LP mill_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return (lp); } -PJ *PROJECTION(mill) { +PJ *PJ_PROJECTION(mill) { P->es = 0.; P->inv = mill_s_inverse; P->fwd = mill_s_forward; diff --git a/src/projections/mod_ster.cpp b/src/projections/mod_ster.cpp index 27d6df60d2..fda392317b 100644 --- a/src/projections/mod_ster.cpp +++ b/src/projections/mod_ster.cpp @@ -1,5 +1,5 @@ /* based upon Snyder and Linck, USGS-NMD */ -#define PJ_LIB_ + #include "proj.h" #include "proj_internal.h" #include @@ -14,7 +14,7 @@ PROJ_HEAD(gs50, "Modified Stereographic of 50 U.S.") "\n\tAzi(mod)"; #define EPSLN 1e-12 namespace { // anonymous namespace -struct pj_opaque { +struct pj_mod_ster_data { const COMPLEX *zcoeff; double cchio, schio; int n; @@ -23,7 +23,8 @@ struct pj_opaque { static PJ_XY mod_ster_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_mod_ster_data *Q = + static_cast(P->opaque); double sinlon, coslon, esphi, chi, schi, cchi, s; COMPLEX p; @@ -52,7 +53,8 @@ static PJ_XY mod_ster_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ static PJ_LP mod_ster_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_mod_ster_data *Q = + static_cast(P->opaque); int nn; COMPLEX p, fxy, fpxy, dp; double den, rh = 0.0, z, sinz = 0.0, cosz = 0.0, chi, phi = 0.0, esphi; @@ -106,8 +108,9 @@ static PJ_LP mod_ster_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ return lp; } -static PJ *setup(PJ *P) { /* general initialization */ - struct pj_opaque *Q = static_cast(P->opaque); +static PJ *mod_ster_setup(PJ *P) { /* general initialization */ + struct pj_mod_ster_data *Q = + static_cast(P->opaque); double esphi, chio; if (P->es != 0.0) { @@ -126,11 +129,11 @@ static PJ *setup(PJ *P) { /* general initialization */ } /* Miller Oblated Stereographic */ -PJ *PROJECTION(mil_os) { +PJ *PJ_PROJECTION(mil_os) { static const COMPLEX AB[] = {{0.924500, 0.}, {0., 0.}, {0.019430, 0.}}; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_mod_ster_data *Q = static_cast( + calloc(1, sizeof(struct pj_mod_ster_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -141,16 +144,16 @@ PJ *PROJECTION(mil_os) { Q->zcoeff = AB; P->es = 0.; - return setup(P); + return mod_ster_setup(P); } /* Lee Oblated Stereographic */ -PJ *PROJECTION(lee_os) { +PJ *PJ_PROJECTION(lee_os) { static const COMPLEX AB[] = { {0.721316, 0.}, {0., 0.}, {-0.0088162, -0.00617325}}; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_mod_ster_data *Q = static_cast( + calloc(1, sizeof(struct pj_mod_ster_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -161,16 +164,16 @@ PJ *PROJECTION(lee_os) { Q->zcoeff = AB; P->es = 0.; - return setup(P); + return mod_ster_setup(P); } -PJ *PROJECTION(gs48) { +PJ *PJ_PROJECTION(gs48) { static const COMPLEX /* 48 United States */ AB[] = { {0.98879, 0.}, {0., 0.}, {-0.050909, 0.}, {0., 0.}, {0.075528, 0.}}; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_mod_ster_data *Q = static_cast( + calloc(1, sizeof(struct pj_mod_ster_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -182,10 +185,10 @@ PJ *PROJECTION(gs48) { P->es = 0.; P->a = 6370997.; - return setup(P); + return mod_ster_setup(P); } -PJ *PROJECTION(alsk) { +PJ *PJ_PROJECTION(alsk) { static const COMPLEX ABe[] = { /* Alaska ellipsoid */ {.9945303, 0.}, {.0052083, -.0027404}, {.0072721, .0048181}, @@ -197,8 +200,8 @@ PJ *PROJECTION(alsk) { {.0074606, .0048125}, {-.0153783, -.1968253}, {.0636871, -.1408027}, {.3660976, -.2937382}}; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_mod_ster_data *Q = static_cast( + calloc(1, sizeof(struct pj_mod_ster_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -215,10 +218,10 @@ PJ *PROJECTION(alsk) { P->a = 6370997.; } - return setup(P); + return mod_ster_setup(P); } -PJ *PROJECTION(gs50) { +PJ *PJ_PROJECTION(gs50) { static const COMPLEX ABe[] = { /* GS50 ellipsoid */ {.9827497, 0.}, {.0210669, .0053804}, {-.1031415, -.0571664}, @@ -233,8 +236,8 @@ PJ *PROJECTION(gs50) { {.0007388, -.1435792}, {.0075848, -.1334108}, {-.0216473, .0776645}, {-.0225161, .0853673}}; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_mod_ster_data *Q = static_cast( + calloc(1, sizeof(struct pj_mod_ster_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -251,5 +254,7 @@ PJ *PROJECTION(gs50) { P->a = 6370997.; } - return setup(P); + return mod_ster_setup(P); } + +#undef EPSLN diff --git a/src/projections/moll.cpp b/src/projections/moll.cpp index a18a6e2758..b7f7f97655 100644 --- a/src/projections/moll.cpp +++ b/src/projections/moll.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -14,14 +14,14 @@ PROJ_HEAD(wag5, "Wagner V") "\n\tPCyl, Sph"; #define LOOP_TOL 1e-7 namespace { // anonymous namespace -struct pj_opaque { +struct pj_moll_data { double C_x, C_y, C_p; }; } // anonymous namespace static PJ_XY moll_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_moll_data *Q = static_cast(P->opaque); int i; const double k = Q->C_p * sin(lp.phi); @@ -42,7 +42,7 @@ static PJ_XY moll_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP moll_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_moll_data *Q = static_cast(P->opaque); lp.phi = aasin(P->ctx, xy.y / Q->C_y); lp.lam = xy.x / (Q->C_x * cos(lp.phi)); if (fabs(lp.lam) < M_PI) { @@ -55,7 +55,7 @@ static PJ_LP moll_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ } static PJ *setup(PJ *P, double p) { - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_moll_data *Q = static_cast(P->opaque); double r, sp, p2 = p + p; P->es = 0; @@ -71,9 +71,9 @@ static PJ *setup(PJ *P, double p) { return P; } -PJ *PROJECTION(moll) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(moll) { + struct pj_moll_data *Q = static_cast( + calloc(1, sizeof(struct pj_moll_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -81,9 +81,9 @@ PJ *PROJECTION(moll) { return setup(P, M_HALFPI); } -PJ *PROJECTION(wag4) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(wag4) { + struct pj_moll_data *Q = static_cast( + calloc(1, sizeof(struct pj_moll_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -91,9 +91,9 @@ PJ *PROJECTION(wag4) { return setup(P, M_PI / 3.); } -PJ *PROJECTION(wag5) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(wag5) { + struct pj_moll_data *Q = static_cast( + calloc(1, sizeof(struct pj_moll_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -108,3 +108,6 @@ PJ *PROJECTION(wag5) { return P; } + +#undef MAX_ITER +#undef LOOP_TOL diff --git a/src/projections/natearth.cpp b/src/projections/natearth.cpp index d98186d048..a14cc0670c 100644 --- a/src/projections/natearth.cpp +++ b/src/projections/natearth.cpp @@ -12,7 +12,6 @@ where they meet the horizontal pole line. This improvement is by intention and designed in collaboration with Tom Patterson. Port to PROJ.4 by Bernhard Jenny, 6 June 2011 */ -#define PJ_LIB_ #include @@ -93,10 +92,28 @@ static PJ_LP natearth_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(natearth) { +PJ *PJ_PROJECTION(natearth) { P->es = 0; P->inv = natearth_s_inverse; P->fwd = natearth_s_forward; return P; } + +#undef A0 +#undef A1 +#undef A2 +#undef A3 +#undef A4 +#undef A5 +#undef B0 +#undef B1 +#undef B2 +#undef B3 +#undef C0 +#undef C1 +#undef C2 +#undef C3 +#undef EPS +#undef MAX_Y +#undef MAX_ITER diff --git a/src/projections/natearth2.cpp b/src/projections/natearth2.cpp index 82510d83df..f983ecd60b 100644 --- a/src/projections/natearth2.cpp +++ b/src/projections/natearth2.cpp @@ -5,7 +5,6 @@ developed by Bojan Savric and Bernhard Jenny, College of Earth, Ocean, and Atmospheric Sciences, Oregon State University. Port to PROJ.4 by Bojan Savric, 4 April 2016 */ -#define PJ_LIB_ #include @@ -90,10 +89,28 @@ static PJ_LP natearth2_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(natearth2) { +PJ *PJ_PROJECTION(natearth2) { P->es = 0; P->inv = natearth2_s_inverse; P->fwd = natearth2_s_forward; return P; } + +#undef A0 +#undef A1 +#undef A2 +#undef A3 +#undef A4 +#undef A5 +#undef B0 +#undef B1 +#undef B2 +#undef B3 +#undef C0 +#undef C1 +#undef C2 +#undef C3 +#undef EPS +#undef MAX_Y +#undef MAX_ITER diff --git a/src/projections/nell.cpp b/src/projections/nell.cpp index ca5712fbae..ba983c5063 100644 --- a/src/projections/nell.cpp +++ b/src/projections/nell.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -38,7 +38,7 @@ static PJ_LP nell_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(nell) { +PJ *PJ_PROJECTION(nell) { P->es = 0; P->inv = nell_s_inverse; @@ -46,3 +46,6 @@ PJ *PROJECTION(nell) { return P; } + +#undef MAX_ITER +#undef LOOP_TOL diff --git a/src/projections/nell_h.cpp b/src/projections/nell_h.cpp index 7959213554..ab86131461 100644 --- a/src/projections/nell_h.cpp +++ b/src/projections/nell_h.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -42,10 +42,13 @@ static PJ_LP nell_h_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(nell_h) { +PJ *PJ_PROJECTION(nell_h) { P->es = 0.; P->inv = nell_h_s_inverse; P->fwd = nell_h_s_forward; return P; } + +#undef NITER +#undef EPS diff --git a/src/projections/nicol.cpp b/src/projections/nicol.cpp index 667e1a766e..93e2458873 100644 --- a/src/projections/nicol.cpp +++ b/src/projections/nicol.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -44,7 +44,7 @@ static PJ_XY nicol_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ return (xy); } -PJ *PROJECTION(nicol) { +PJ *PJ_PROJECTION(nicol) { P->es = 0.; P->fwd = nicol_s_forward; diff --git a/src/projections/nsper.cpp b/src/projections/nsper.cpp index 4023bae2c6..e8732eb99f 100644 --- a/src/projections/nsper.cpp +++ b/src/projections/nsper.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include "proj.h" #include "proj_internal.h" #include @@ -9,12 +9,12 @@ * of topocentric origin for the projection plan. */ -namespace { // anonymous namespace +namespace pj_nsper_ns { enum Mode { N_POLE = 0, S_POLE = 1, EQUIT = 2, OBLIQ = 3 }; -} // anonymous namespace +} namespace { // anonymous namespace -struct pj_opaque { +struct pj_nsper_data { double height; double sinph0; double cosph0; @@ -27,7 +27,7 @@ struct pj_opaque { double sg; double sw; double cw; - enum Mode mode; + enum pj_nsper_ns::Mode mode; int tilt; }; } // anonymous namespace @@ -39,23 +39,23 @@ PROJ_HEAD(tpers, "Tilted perspective") "\n\tAzi, Sph\n\ttilt= azi= h="; static PJ_XY nsper_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_nsper_data *Q = static_cast(P->opaque); double coslam, cosphi, sinphi; sinphi = sin(lp.phi); cosphi = cos(lp.phi); coslam = cos(lp.lam); switch (Q->mode) { - case OBLIQ: + case pj_nsper_ns::OBLIQ: xy.y = Q->sinph0 * sinphi + Q->cosph0 * cosphi * coslam; break; - case EQUIT: + case pj_nsper_ns::EQUIT: xy.y = cosphi * coslam; break; - case S_POLE: + case pj_nsper_ns::S_POLE: xy.y = -sinphi; break; - case N_POLE: + case pj_nsper_ns::N_POLE: xy.y = sinphi; break; } @@ -66,16 +66,16 @@ static PJ_XY nsper_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ xy.y = Q->pn1 / (Q->p - xy.y); xy.x = xy.y * cosphi * sin(lp.lam); switch (Q->mode) { - case OBLIQ: + case pj_nsper_ns::OBLIQ: xy.y *= (Q->cosph0 * sinphi - Q->sinph0 * cosphi * coslam); break; - case EQUIT: + case pj_nsper_ns::EQUIT: xy.y *= sinphi; break; - case N_POLE: + case pj_nsper_ns::N_POLE: coslam = -coslam; PROJ_FALLTHROUGH; - case S_POLE: + case pj_nsper_ns::S_POLE: xy.y *= cosphi * coslam; break; } @@ -92,7 +92,7 @@ static PJ_XY nsper_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP nsper_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_nsper_data *Q = static_cast(P->opaque); double rh; if (Q->tilt) { @@ -118,21 +118,21 @@ static PJ_LP nsper_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ sinz = (Q->p - sqrt(sinz)) / (Q->pn1 / rh + rh / Q->pn1); cosz = sqrt(1. - sinz * sinz); switch (Q->mode) { - case OBLIQ: + case pj_nsper_ns::OBLIQ: lp.phi = asin(cosz * Q->sinph0 + xy.y * sinz * Q->cosph0 / rh); xy.y = (cosz - Q->sinph0 * sin(lp.phi)) * rh; xy.x *= sinz * Q->cosph0; break; - case EQUIT: + case pj_nsper_ns::EQUIT: lp.phi = asin(xy.y * sinz / rh); xy.y = cosz * rh; xy.x *= sinz; break; - case N_POLE: + case pj_nsper_ns::N_POLE: lp.phi = asin(cosz); xy.y = -xy.y; break; - case S_POLE: + case pj_nsper_ns::S_POLE: lp.phi = -asin(cosz); break; } @@ -141,17 +141,17 @@ static PJ_LP nsper_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -static PJ *setup(PJ *P) { - struct pj_opaque *Q = static_cast(P->opaque); +static PJ *nsper_setup(PJ *P) { + struct pj_nsper_data *Q = static_cast(P->opaque); Q->height = pj_param(P->ctx, P->params, "dh").f; if (fabs(fabs(P->phi0) - M_HALFPI) < EPS10) - Q->mode = P->phi0 < 0. ? S_POLE : N_POLE; + Q->mode = P->phi0 < 0. ? pj_nsper_ns::S_POLE : pj_nsper_ns::N_POLE; else if (fabs(P->phi0) < EPS10) - Q->mode = EQUIT; + Q->mode = pj_nsper_ns::EQUIT; else { - Q->mode = OBLIQ; + Q->mode = pj_nsper_ns::OBLIQ; Q->sinph0 = sin(P->phi0); Q->cosph0 = cos(P->phi0); } @@ -171,23 +171,23 @@ static PJ *setup(PJ *P) { return P; } -PJ *PROJECTION(nsper) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(nsper) { + struct pj_nsper_data *Q = static_cast( + calloc(1, sizeof(struct pj_nsper_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; Q->tilt = 0; - return setup(P); + return nsper_setup(P); } -PJ *PROJECTION(tpers) { +PJ *PJ_PROJECTION(tpers) { double omega, gamma; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_nsper_data *Q = static_cast( + calloc(1, sizeof(struct pj_nsper_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -200,5 +200,7 @@ PJ *PROJECTION(tpers) { Q->cw = cos(omega); Q->sw = sin(omega); - return setup(P); + return nsper_setup(P); } + +#undef EPS10 diff --git a/src/projections/nzmg.cpp b/src/projections/nzmg.cpp index 0772a529dc..c4ea5a8030 100644 --- a/src/projections/nzmg.cpp +++ b/src/projections/nzmg.cpp @@ -25,7 +25,6 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. *****************************************************************************/ -#define PJ_LIB_ #include @@ -43,14 +42,6 @@ static const COMPLEX bf[] = { {-.001541739, 0.041058560}, {-.10162907, 0.01727609}, {-.26623489, -0.36249218}, {-.6870983, -1.1651967}}; -static const double tphi[] = {1.5627014243, .5185406398, -.03333098, - -.1052906, -.0368594, .007317, - .01220, .00394, -.0013}; - -static const double tpsi[] = {.6399175073, -.1358797613, .063294409, -.02526853, - .0117879, -.0055161, .0026906, -.001333, - .00067, -.00034}; - #define Nbf 5 #define Ntpsi 9 #define Ntphi 8 @@ -61,6 +52,10 @@ static PJ_XY nzmg_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ const double *C; int i; + static const double tpsi[] = { + .6399175073, -.1358797613, .063294409, -.02526853, .0117879, + -.0055161, .0026906, -.001333, .00067, -.00034}; + lp.phi = (lp.phi - P->phi0) * RAD_TO_SEC5; i = Ntpsi; C = tpsi + i; @@ -84,6 +79,10 @@ static PJ_LP nzmg_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ double den; const double *C; + static const double tphi[] = {1.5627014243, .5185406398, -.03333098, + -.1052906, -.0368594, .007317, + .01220, .00394, -.0013}; + p.r = xy.y; p.i = xy.x; for (nn = 20; nn; --nn) { @@ -113,7 +112,7 @@ static PJ_LP nzmg_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ return lp; } -PJ *PROJECTION(nzmg) { +PJ *PJ_PROJECTION(nzmg) { /* force to International major axis */ P->ra = 1. / (P->a = 6378388.0); P->lam0 = DEG_TO_RAD * 173.; @@ -126,3 +125,10 @@ PJ *PROJECTION(nzmg) { return P; } + +#undef EPSLN +#undef SEC5_TO_RAD +#undef RAD_TO_SEC5 +#undef Nbf +#undef Ntpsi +#undef Ntphi diff --git a/src/projections/ob_tran.cpp b/src/projections/ob_tran.cpp index 8df0cabffb..131c538907 100644 --- a/src/projections/ob_tran.cpp +++ b/src/projections/ob_tran.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include #include @@ -8,7 +8,7 @@ #include "proj_internal.h" namespace { // anonymous namespace -struct pj_opaque { +struct pj_ob_tran_data { struct PJconsts *link; double lamp; double cphip, sphip; @@ -25,7 +25,8 @@ PROJ_HEAD(ob_tran, "General Oblique Transformation") #define TOL 1e-10 static PJ_XY o_forward(PJ_LP lp, PJ *P) { /* spheroid */ - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_ob_tran_data *Q = + static_cast(P->opaque); double coslam, sinphi, cosphi; coslam = cos(lp.lam); @@ -42,7 +43,8 @@ static PJ_XY o_forward(PJ_LP lp, PJ *P) { /* spheroid */ } static PJ_XY t_forward(PJ_LP lp, PJ *P) { /* spheroid */ - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_ob_tran_data *Q = + static_cast(P->opaque); double cosphi, coslam; cosphi = cos(lp.phi); @@ -55,7 +57,8 @@ static PJ_XY t_forward(PJ_LP lp, PJ *P) { /* spheroid */ static PJ_LP o_inverse(PJ_XY xy, PJ *P) { /* spheroid */ - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_ob_tran_data *Q = + static_cast(P->opaque); double coslam, sinphi, cosphi; PJ_LP lp = Q->link->inv(xy, Q->link); @@ -75,7 +78,8 @@ static PJ_LP o_inverse(PJ_XY xy, PJ *P) { /* spheroid */ static PJ_LP t_inverse(PJ_XY xy, PJ *P) { /* spheroid */ - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_ob_tran_data *Q = + static_cast(P->opaque); double cosphi, t; PJ_LP lp = Q->link->inv(xy, Q->link); @@ -94,9 +98,9 @@ static PJ *destructor(PJ *P, int errlev) { if (nullptr == P->opaque) return pj_default_destructor(P, errlev); - if (static_cast(P->opaque)->link) - static_cast(P->opaque)->link->destructor( - static_cast(P->opaque)->link, errlev); + if (static_cast(P->opaque)->link) + static_cast(P->opaque)->link->destructor( + static_cast(P->opaque)->link, errlev); return pj_default_destructor(P, errlev); } @@ -168,13 +172,13 @@ static ARGS ob_tran_target_params(paralist *params) { return args; } -PJ *PROJECTION(ob_tran) { +PJ *PJ_PROJECTION(ob_tran) { double phip; ARGS args; PJ *R; /* projection to rotate */ - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_ob_tran_data *Q = static_cast( + calloc(1, sizeof(struct pj_ob_tran_data))); if (nullptr == Q) return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); @@ -291,3 +295,5 @@ PJ *PROJECTION(ob_tran) { return P; } + +#undef TOL diff --git a/src/projections/ocea.cpp b/src/projections/ocea.cpp index 30b40db2b8..ca657f0af4 100644 --- a/src/projections/ocea.cpp +++ b/src/projections/ocea.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -11,7 +11,7 @@ PROJ_HEAD(ocea, "Oblique Cylindrical Equal Area") "lonc= alpha= or\n\tlat_1= lat_2= lon_1= lon_2="; namespace { // anonymous namespace -struct pj_opaque { +struct pj_ocea { double rok; double rtk; double sinphi; @@ -21,7 +21,7 @@ struct pj_opaque { static PJ_XY ocea_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_ocea *Q = static_cast(P->opaque); double t; xy.y = sin(lp.lam); t = cos(lp.lam); @@ -35,7 +35,7 @@ static PJ_XY ocea_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP ocea_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_ocea *Q = static_cast(P->opaque); xy.y /= Q->rok; xy.x /= Q->rtk; @@ -46,11 +46,11 @@ static PJ_LP ocea_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(ocea) { +PJ *PJ_PROJECTION(ocea) { double phi_1, phi_2, lam_1, lam_2, lonz, alpha; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_ocea *Q = + static_cast(calloc(1, sizeof(struct pj_ocea))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; diff --git a/src/projections/oea.cpp b/src/projections/oea.cpp index 592c42fadb..1e5083bc33 100644 --- a/src/projections/oea.cpp +++ b/src/projections/oea.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include "proj.h" #include "proj_internal.h" #include @@ -7,7 +7,7 @@ PROJ_HEAD(oea, "Oblated Equal Area") "\n\tMisc Sph\n\tn= m= theta="; namespace { // anonymous namespace -struct pj_opaque { +struct pj_oea { double theta; double m, n; double two_r_m, two_r_n, rm, rn, hm, hn; @@ -17,7 +17,7 @@ struct pj_opaque { static PJ_XY oea_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_oea *Q = static_cast(P->opaque); const double cp = cos(lp.phi); const double sp = sin(lp.phi); @@ -36,7 +36,7 @@ static PJ_XY oea_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP oea_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_oea *Q = static_cast(P->opaque); const double N = Q->hn * aasin(P->ctx, xy.y * Q->rn); const double M = @@ -54,9 +54,9 @@ static PJ_LP oea_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(oea) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(oea) { + struct pj_oea *Q = + static_cast(calloc(1, sizeof(struct pj_oea))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; diff --git a/src/projections/omerc.cpp b/src/projections/omerc.cpp index ab5f08cef5..0f883d4ed8 100644 --- a/src/projections/omerc.cpp +++ b/src/projections/omerc.cpp @@ -21,7 +21,6 @@ ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#define PJ_LIB_ #include #include @@ -34,7 +33,7 @@ PROJ_HEAD(omerc, "Oblique Mercator") "alpha= [gamma=] [no_off] lonc= or\n\t lon_1= lat_1= lon_2= lat_2="; namespace { // anonymous namespace -struct pj_opaque { +struct pj_omerc_data { double A, B, E, AB, ArB, BrA, rB, singam, cosgam, sinrot, cosrot; double v_pole_n, v_pole_s, u_0; int no_rot; @@ -46,7 +45,7 @@ struct pj_opaque { static PJ_XY omerc_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_omerc_data *Q = static_cast(P->opaque); double u, v; if (fabs(fabs(lp.phi) - M_HALFPI) > EPS) { @@ -84,7 +83,7 @@ static PJ_XY omerc_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ static PJ_LP omerc_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_omerc_data *Q = static_cast(P->opaque); double u, v, Qp, Sp, Tp, Vp, Up; if (Q->no_rot) { @@ -119,14 +118,14 @@ static PJ_LP omerc_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ return lp; } -PJ *PROJECTION(omerc) { +PJ *PJ_PROJECTION(omerc) { double con, com, cosph0, D, F, H, L, sinph0, p, J, gamma = 0, gamma0, lamc = 0, lam1 = 0, lam2 = 0, phi1 = 0, phi2 = 0, alpha_c = 0; int alp, gam, no_off = 0; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_omerc_data *Q = static_cast( + calloc(1, sizeof(struct pj_omerc_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -298,3 +297,6 @@ PJ *PROJECTION(omerc) { return P; } + +#undef TOL +#undef EPS diff --git a/src/projections/ortho.cpp b/src/projections/ortho.cpp index 54e005008b..e90cb92c5a 100644 --- a/src/projections/ortho.cpp +++ b/src/projections/ortho.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include "proj.h" #include "proj_internal.h" #include @@ -6,18 +6,18 @@ PROJ_HEAD(ortho, "Orthographic") "\n\tAzi, Sph&Ell"; -namespace { // anonymous namespace +namespace pj_ortho_ns { enum Mode { N_POLE = 0, S_POLE = 1, EQUIT = 2, OBLIQ = 3 }; -} // anonymous namespace +} namespace { // anonymous namespace -struct pj_opaque { +struct pj_ortho_data { double sinph0; double cosph0; double nu0; double y_shift; double y_scale; - enum Mode mode; + enum pj_ortho_ns::Mode mode; }; } // anonymous namespace @@ -33,7 +33,7 @@ static PJ_XY forward_error(PJ *P, PJ_LP lp, PJ_XY xy) { static PJ_XY ortho_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_ortho_data *Q = static_cast(P->opaque); double coslam, cosphi, sinphi; xy.x = HUGE_VAL; @@ -42,12 +42,12 @@ static PJ_XY ortho_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ cosphi = cos(lp.phi); coslam = cos(lp.lam); switch (Q->mode) { - case EQUIT: + case pj_ortho_ns::EQUIT: if (cosphi * coslam < -EPS10) return forward_error(P, lp, xy); xy.y = sin(lp.phi); break; - case OBLIQ: + case pj_ortho_ns::OBLIQ: sinphi = sin(lp.phi); // Is the point visible from the projection plane ? @@ -62,10 +62,10 @@ static PJ_XY ortho_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ return forward_error(P, lp, xy); xy.y = Q->cosph0 * sinphi - Q->sinph0 * cosphi * coslam; break; - case N_POLE: + case pj_ortho_ns::N_POLE: coslam = -coslam; PROJ_FALLTHROUGH; - case S_POLE: + case pj_ortho_ns::S_POLE: if (fabs(lp.phi - P->phi0) - EPS10 > M_HALFPI) return forward_error(P, lp, xy); xy.y = cosphi * coslam; @@ -77,7 +77,7 @@ static PJ_XY ortho_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP ortho_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_ortho_data *Q = static_cast(P->opaque); double sinc; lp.lam = HUGE_VAL; @@ -98,19 +98,19 @@ static PJ_LP ortho_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ lp.lam = 0.0; } else { switch (Q->mode) { - case N_POLE: + case pj_ortho_ns::N_POLE: xy.y = -xy.y; lp.phi = acos(sinc); break; - case S_POLE: + case pj_ortho_ns::S_POLE: lp.phi = -acos(sinc); break; - case EQUIT: + case pj_ortho_ns::EQUIT: lp.phi = xy.y * sinc / rh; xy.x *= sinc; xy.y = cosc * rh; goto sinchk; - case OBLIQ: + case pj_ortho_ns::OBLIQ: lp.phi = cosc * Q->sinph0 + xy.y * sinc * Q->cosph0 / rh; xy.y = (cosc - Q->sinph0 * lp.phi) * rh; xy.x *= sinc * Q->cosph0; @@ -121,7 +121,8 @@ static PJ_LP ortho_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ lp.phi = asin(lp.phi); break; } - lp.lam = (xy.y == 0. && (Q->mode == OBLIQ || Q->mode == EQUIT)) + lp.lam = (xy.y == 0. && (Q->mode == pj_ortho_ns::OBLIQ || + Q->mode == pj_ortho_ns::EQUIT)) ? (xy.x == 0. ? 0. : xy.x < 0. ? -M_HALFPI : M_HALFPI) @@ -132,7 +133,7 @@ static PJ_LP ortho_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ static PJ_XY ortho_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ PJ_XY xy; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_ortho_data *Q = static_cast(P->opaque); // From EPSG guidance note 7.2, March 2020, §3.3.5 Orthographic const double cosphi = cos(lp.phi); @@ -158,11 +159,11 @@ static PJ_XY ortho_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ static PJ_LP ortho_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ PJ_LP lp; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_ortho_data *Q = static_cast(P->opaque); const auto SQ = [](double x) { return x * x; }; - if (Q->mode == N_POLE || Q->mode == S_POLE) { + if (Q->mode == pj_ortho_ns::N_POLE || Q->mode == pj_ortho_ns::S_POLE) { // Polar case. Forward case equations can be simplified as: // xy.x = nu * cosphi * sinlam // xy.y = nu * -cosphi * coslam * sign(phi0) @@ -183,13 +184,13 @@ static PJ_LP ortho_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ lp.phi = 0; } else { lp.phi = acos(sqrt(rh2 * P->one_es / (1 - P->es * rh2))) * - (Q->mode == N_POLE ? 1 : -1); + (Q->mode == pj_ortho_ns::N_POLE ? 1 : -1); } - lp.lam = atan2(xy.x, xy.y * (Q->mode == N_POLE ? -1 : 1)); + lp.lam = atan2(xy.x, xy.y * (Q->mode == pj_ortho_ns::N_POLE ? -1 : 1)); return lp; } - if (Q->mode == EQUIT) { + if (Q->mode == pj_ortho_ns::EQUIT) { // Equatorial case. Forward case equations can be simplified as: // xy.x = nu * cosphi * sinlam // xy.y = nu * sinphi * (1 - P->es) @@ -282,9 +283,9 @@ static PJ_LP ortho_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ return lp; } -PJ *PROJECTION(ortho) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(ortho) { + struct pj_ortho_data *Q = static_cast( + calloc(1, sizeof(struct pj_ortho_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -292,11 +293,11 @@ PJ *PROJECTION(ortho) { Q->sinph0 = sin(P->phi0); Q->cosph0 = cos(P->phi0); if (fabs(fabs(P->phi0) - M_HALFPI) <= EPS10) - Q->mode = P->phi0 < 0. ? S_POLE : N_POLE; + Q->mode = P->phi0 < 0. ? pj_ortho_ns::S_POLE : pj_ortho_ns::N_POLE; else if (fabs(P->phi0) > EPS10) { - Q->mode = OBLIQ; + Q->mode = pj_ortho_ns::OBLIQ; } else - Q->mode = EQUIT; + Q->mode = pj_ortho_ns::EQUIT; if (P->es == 0) { P->inv = ortho_s_inverse; P->fwd = ortho_s_forward; @@ -310,3 +311,5 @@ PJ *PROJECTION(ortho) { return P; } + +#undef EPS10 diff --git a/src/projections/patterson.cpp b/src/projections/patterson.cpp index 172becf38d..97468d916a 100644 --- a/src/projections/patterson.cpp +++ b/src/projections/patterson.cpp @@ -39,8 +39,6 @@ * Port to PROJ.4 by Micah Cochran, 26 March 2016 */ -#define PJ_LIB_ - #include #include "proj.h" @@ -110,10 +108,22 @@ static PJ_LP patterson_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(patterson) { +PJ *PJ_PROJECTION(patterson) { P->es = 0.; P->inv = patterson_s_inverse; P->fwd = patterson_s_forward; return P; } + +#undef K1 +#undef K2 +#undef K3 +#undef K4 +#undef C1 +#undef C2 +#undef C3 +#undef C4 +#undef EPS11 +#undef MAX_Y +#undef MAX_ITER diff --git a/src/projections/poly.cpp b/src/projections/poly.cpp index 3c0c626df4..3a36c92760 100644 --- a/src/projections/poly.cpp +++ b/src/projections/poly.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -10,7 +10,7 @@ PROJ_HEAD(poly, "Polyconic (American)") "\n\tConic, Sph&Ell"; namespace { // anonymous namespace -struct pj_opaque { +struct pj_poly_data { double ml0; double *en; }; @@ -24,7 +24,7 @@ struct pj_opaque { static PJ_XY poly_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_poly_data *Q = static_cast(P->opaque); double ms, sp, cp; if (fabs(lp.phi) <= TOL) { @@ -45,7 +45,7 @@ static PJ_XY poly_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ static PJ_XY poly_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_poly_data *Q = static_cast(P->opaque); if (fabs(lp.phi) <= TOL) { xy.x = lp.lam; @@ -62,7 +62,7 @@ static PJ_XY poly_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP poly_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_poly_data *Q = static_cast(P->opaque); xy.y += Q->ml0; if (fabs(xy.y) <= TOL) { @@ -138,27 +138,27 @@ static PJ_LP poly_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -static PJ *destructor(PJ *P, int errlev) { +static PJ *pj_poly_destructor(PJ *P, int errlev) { if (nullptr == P) return nullptr; if (nullptr == P->opaque) return pj_default_destructor(P, errlev); - if (static_cast(P->opaque)->en) - free(static_cast(P->opaque)->en); + if (static_cast(P->opaque)->en) + free(static_cast(P->opaque)->en); return pj_default_destructor(P, errlev); } -PJ *PROJECTION(poly) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(poly) { + struct pj_poly_data *Q = static_cast( + calloc(1, sizeof(struct pj_poly_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; - P->destructor = destructor; + P->destructor = pj_poly_destructor; if (P->es != 0.0) { if (!(Q->en = pj_enfn(P->n))) @@ -174,3 +174,9 @@ PJ *PROJECTION(poly) { return P; } + +#undef TOL +#undef CONV +#undef N_ITER +#undef I_ITER +#undef ITOL diff --git a/src/projections/putp2.cpp b/src/projections/putp2.cpp index cb64ff4200..da99774949 100644 --- a/src/projections/putp2.cpp +++ b/src/projections/putp2.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -50,10 +50,17 @@ static PJ_LP putp2_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(putp2) { +PJ *PJ_PROJECTION(putp2) { P->es = 0.; P->inv = putp2_s_inverse; P->fwd = putp2_s_forward; return P; } + +#undef C_x +#undef C_y +#undef C_p +#undef EPS +#undef NITER +#undef PI_DIV_3 diff --git a/src/projections/putp3.cpp b/src/projections/putp3.cpp index d1ecdb9fee..75066c4426 100644 --- a/src/projections/putp3.cpp +++ b/src/projections/putp3.cpp @@ -1,11 +1,11 @@ -#define PJ_LIB_ + #include #include "proj.h" #include "proj_internal.h" namespace { // anonymous namespace -struct pj_opaque { +struct pj_putp3_data { double A; }; } // anonymous namespace @@ -19,9 +19,9 @@ PROJ_HEAD(putp3p, "Putnins P3'") "\n\tPCyl, Sph"; static PJ_XY putp3_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - xy.x = - C * lp.lam * - (1. - static_cast(P->opaque)->A * lp.phi * lp.phi); + xy.x = C * lp.lam * + (1. - static_cast(P->opaque)->A * lp.phi * + lp.phi); xy.y = C * lp.phi; return xy; @@ -31,15 +31,16 @@ static PJ_LP putp3_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; lp.phi = xy.y / C; - lp.lam = xy.x / (C * (1. - static_cast(P->opaque)->A * - lp.phi * lp.phi)); + lp.lam = + xy.x / (C * (1. - static_cast(P->opaque)->A * + lp.phi * lp.phi)); return lp; } -PJ *PROJECTION(putp3) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(putp3) { + struct pj_putp3_data *Q = static_cast( + calloc(1, sizeof(struct pj_putp3_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -53,9 +54,9 @@ PJ *PROJECTION(putp3) { return P; } -PJ *PROJECTION(putp3p) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(putp3p) { + struct pj_putp3_data *Q = static_cast( + calloc(1, sizeof(struct pj_putp3_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -68,3 +69,6 @@ PJ *PROJECTION(putp3p) { return P; } + +#undef C +#undef RPISQ diff --git a/src/projections/putp4p.cpp b/src/projections/putp4p.cpp index 8783e0e831..ad1b1c03ed 100644 --- a/src/projections/putp4p.cpp +++ b/src/projections/putp4p.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -7,7 +7,7 @@ #include "proj_internal.h" namespace { // anonymous namespace -struct pj_opaque { +struct pj_putp4p_data { double C_x, C_y; }; } // anonymous namespace @@ -17,7 +17,7 @@ PROJ_HEAD(weren, "Werenskiold I") "\n\tPCyl, Sph"; static PJ_XY putp4p_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_putp4p_data *Q = static_cast(P->opaque); lp.phi = aasin(P->ctx, 0.883883476 * sin(lp.phi)); xy.x = Q->C_x * lp.lam * cos(lp.phi); @@ -30,7 +30,7 @@ static PJ_XY putp4p_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP putp4p_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_putp4p_data *Q = static_cast(P->opaque); lp.phi = aasin(P->ctx, xy.y / Q->C_y); lp.lam = xy.x * cos(lp.phi) / Q->C_x; @@ -41,9 +41,9 @@ static PJ_LP putp4p_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(putp4p) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(putp4p) { + struct pj_putp4p_data *Q = static_cast( + calloc(1, sizeof(struct pj_putp4p_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -58,9 +58,9 @@ PJ *PROJECTION(putp4p) { return P; } -PJ *PROJECTION(weren) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(weren) { + struct pj_putp4p_data *Q = static_cast( + calloc(1, sizeof(struct pj_putp4p_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; diff --git a/src/projections/putp5.cpp b/src/projections/putp5.cpp index f74f1ee54f..ea76be5f2c 100644 --- a/src/projections/putp5.cpp +++ b/src/projections/putp5.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -7,7 +7,7 @@ #include "proj_internal.h" namespace { // anonymous namespace -struct pj_opaque { +struct pj_putp5_data { double A, B; }; } // anonymous namespace @@ -20,7 +20,7 @@ PROJ_HEAD(putp5p, "Putnins P5'") "\n\tPCyl, Sph"; static PJ_XY putp5_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_putp5_data *Q = static_cast(P->opaque); xy.x = C * lp.lam * (Q->A - Q->B * sqrt(1. + D * lp.phi * lp.phi)); xy.y = C * lp.phi; @@ -30,7 +30,7 @@ static PJ_XY putp5_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP putp5_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_putp5_data *Q = static_cast(P->opaque); lp.phi = xy.y / C; lp.lam = xy.x / (C * (Q->A - Q->B * sqrt(1. + D * lp.phi * lp.phi))); @@ -38,9 +38,9 @@ static PJ_LP putp5_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(putp5) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(putp5) { + struct pj_putp5_data *Q = static_cast( + calloc(1, sizeof(struct pj_putp5_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -55,9 +55,9 @@ PJ *PROJECTION(putp5) { return P; } -PJ *PROJECTION(putp5p) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(putp5p) { + struct pj_putp5_data *Q = static_cast( + calloc(1, sizeof(struct pj_putp5_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -71,3 +71,6 @@ PJ *PROJECTION(putp5p) { return P; } + +#undef C +#undef D diff --git a/src/projections/putp6.cpp b/src/projections/putp6.cpp index 6ccffebe96..b30c0a1202 100644 --- a/src/projections/putp6.cpp +++ b/src/projections/putp6.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -7,7 +7,7 @@ #include "proj_internal.h" namespace { // anonymous namespace -struct pj_opaque { +struct pj_putp6 { double C_x, C_y, A, B, D; }; } // anonymous namespace @@ -21,7 +21,7 @@ PROJ_HEAD(putp6p, "Putnins P6'") "\n\tPCyl, Sph"; static PJ_XY putp6_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_putp6 *Q = static_cast(P->opaque); int i; const double p = Q->B * sin(lp.phi); @@ -53,7 +53,7 @@ static PJ_XY putp6_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP putp6_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_putp6 *Q = static_cast(P->opaque); double r; lp.phi = xy.y / Q->C_y; @@ -64,9 +64,9 @@ static PJ_LP putp6_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(putp6) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(putp6) { + struct pj_putp6 *Q = + static_cast(calloc(1, sizeof(struct pj_putp6))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -84,9 +84,9 @@ PJ *PROJECTION(putp6) { return P; } -PJ *PROJECTION(putp6p) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(putp6p) { + struct pj_putp6 *Q = + static_cast(calloc(1, sizeof(struct pj_putp6))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -103,3 +103,7 @@ PJ *PROJECTION(putp6p) { return P; } + +#undef EPS +#undef NITER +#undef CON_POLE diff --git a/src/projections/qsc.cpp b/src/projections/qsc.cpp index a9124feca5..34c8e5289b 100644 --- a/src/projections/qsc.cpp +++ b/src/projections/qsc.cpp @@ -34,12 +34,11 @@ * * Furthermore, the projection is originally only defined for theta angles * between (-1/4 * PI) and (+1/4 * PI) on the current cube face. This area - * of definition is named AREA_0 in the projection code below. The other - * three areas of a cube face are handled by rotation of AREA_0. + * of definition is named pj_qsc_ns::AREA_0 in the projection code below. The + * other three areas of a cube face are handled by rotation of + * pj_qsc_ns::AREA_0. */ -#define PJ_LIB_ - #include #include @@ -47,7 +46,7 @@ #include "proj_internal.h" /* The six cube faces. */ -namespace { // anonymous namespace +namespace pj_qsc_ns { enum Face { FACE_FRONT = 0, FACE_RIGHT = 1, @@ -56,11 +55,11 @@ enum Face { FACE_TOP = 4, FACE_BOTTOM = 5 }; -} // anonymous namespace +} namespace { // anonymous namespace -struct pj_opaque { - enum Face face; +struct pj_qsc_data { + enum pj_qsc_ns::Face face; double a_squared; double b; double one_minus_f; @@ -73,31 +72,31 @@ PROJ_HEAD(qsc, "Quadrilateralized Spherical Cube") "\n\tAzi, Sph"; /* The four areas on a cube face. AREA_0 is the area of definition, * the other three areas are counted counterclockwise. */ -namespace { // anonymous namespace +namespace pj_qsc_ns { enum Area { AREA_0 = 0, AREA_1 = 1, AREA_2 = 2, AREA_3 = 3 }; -} // anonymous namespace +} /* Helper function for forward projection: compute the theta angle * and determine the area number. */ static double qsc_fwd_equat_face_theta(double phi, double y, double x, - enum Area *area) { + enum pj_qsc_ns::Area *area) { double theta; if (phi < EPS10) { - *area = AREA_0; + *area = pj_qsc_ns::AREA_0; theta = 0.0; } else { theta = atan2(y, x); if (fabs(theta) <= M_FORTPI) { - *area = AREA_0; + *area = pj_qsc_ns::AREA_0; } else if (theta > M_FORTPI && theta <= M_HALFPI + M_FORTPI) { - *area = AREA_1; + *area = pj_qsc_ns::AREA_1; theta -= M_HALFPI; } else if (theta > M_HALFPI + M_FORTPI || theta <= -(M_HALFPI + M_FORTPI)) { - *area = AREA_2; + *area = pj_qsc_ns::AREA_2; theta = (theta >= 0.0 ? theta - M_PI : theta + M_PI); } else { - *area = AREA_3; + *area = pj_qsc_ns::AREA_3; theta += M_HALFPI; } } @@ -117,11 +116,11 @@ static double qsc_shift_longitude_origin(double longitude, double offset) { static PJ_XY qsc_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_qsc_data *Q = static_cast(P->opaque); double lat, longitude; double theta, phi; double t, mu; /* nu; */ - enum Area area; + enum pj_qsc_ns::Area area; /* Convert the geodetic latitude to a geocentric latitude. * This corresponds to the shift from the ellipsoid to the sphere @@ -138,37 +137,37 @@ static PJ_XY qsc_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ * directly from phi, lam. For the other faces, we must use * unit sphere cartesian coordinates as an intermediate step. */ longitude = lp.lam; - if (Q->face == FACE_TOP) { + if (Q->face == pj_qsc_ns::FACE_TOP) { phi = M_HALFPI - lat; if (longitude >= M_FORTPI && longitude <= M_HALFPI + M_FORTPI) { - area = AREA_0; + area = pj_qsc_ns::AREA_0; theta = longitude - M_HALFPI; } else if (longitude > M_HALFPI + M_FORTPI || longitude <= -(M_HALFPI + M_FORTPI)) { - area = AREA_1; + area = pj_qsc_ns::AREA_1; theta = (longitude > 0.0 ? longitude - M_PI : longitude + M_PI); } else if (longitude > -(M_HALFPI + M_FORTPI) && longitude <= -M_FORTPI) { - area = AREA_2; + area = pj_qsc_ns::AREA_2; theta = longitude + M_HALFPI; } else { - area = AREA_3; + area = pj_qsc_ns::AREA_3; theta = longitude; } - } else if (Q->face == FACE_BOTTOM) { + } else if (Q->face == pj_qsc_ns::FACE_BOTTOM) { phi = M_HALFPI + lat; if (longitude >= M_FORTPI && longitude <= M_HALFPI + M_FORTPI) { - area = AREA_0; + area = pj_qsc_ns::AREA_0; theta = -longitude + M_HALFPI; } else if (longitude < M_FORTPI && longitude >= -M_FORTPI) { - area = AREA_1; + area = pj_qsc_ns::AREA_1; theta = -longitude; } else if (longitude < -M_FORTPI && longitude >= -(M_HALFPI + M_FORTPI)) { - area = AREA_2; + area = pj_qsc_ns::AREA_2; theta = -longitude - M_HALFPI; } else { - area = AREA_3; + area = pj_qsc_ns::AREA_3; theta = (longitude > 0.0 ? -longitude + M_PI : -longitude - M_PI); } } else { @@ -176,11 +175,11 @@ static PJ_XY qsc_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ double sinlat, coslat; double sinlon, coslon; - if (Q->face == FACE_RIGHT) { + if (Q->face == pj_qsc_ns::FACE_RIGHT) { longitude = qsc_shift_longitude_origin(longitude, +M_HALFPI); - } else if (Q->face == FACE_BACK) { + } else if (Q->face == pj_qsc_ns::FACE_BACK) { longitude = qsc_shift_longitude_origin(longitude, +M_PI); - } else if (Q->face == FACE_LEFT) { + } else if (Q->face == pj_qsc_ns::FACE_LEFT) { longitude = qsc_shift_longitude_origin(longitude, -M_HALFPI); } sinlat = sin(lat); @@ -191,22 +190,22 @@ static PJ_XY qsc_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ r = coslat * sinlon; s = sinlat; - if (Q->face == FACE_FRONT) { + if (Q->face == pj_qsc_ns::FACE_FRONT) { phi = acos(q); theta = qsc_fwd_equat_face_theta(phi, s, r, &area); - } else if (Q->face == FACE_RIGHT) { + } else if (Q->face == pj_qsc_ns::FACE_RIGHT) { phi = acos(r); theta = qsc_fwd_equat_face_theta(phi, s, -q, &area); - } else if (Q->face == FACE_BACK) { + } else if (Q->face == pj_qsc_ns::FACE_BACK) { phi = acos(-q); theta = qsc_fwd_equat_face_theta(phi, s, -r, &area); - } else if (Q->face == FACE_LEFT) { + } else if (Q->face == pj_qsc_ns::FACE_LEFT) { phi = acos(-r); theta = qsc_fwd_equat_face_theta(phi, s, q, &area); } else { /* Impossible */ phi = theta = 0.0; - area = AREA_0; + area = pj_qsc_ns::AREA_0; } } @@ -220,11 +219,11 @@ static PJ_XY qsc_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ /* nu = atan(t); We don't really need nu, just t, see below. */ /* Apply the result to the real area. */ - if (area == AREA_1) { + if (area == pj_qsc_ns::AREA_1) { mu += M_HALFPI; - } else if (area == AREA_2) { + } else if (area == pj_qsc_ns::AREA_2) { mu += M_PI; - } else if (area == AREA_3) { + } else if (area == pj_qsc_ns::AREA_3) { mu += M_PI_HALFPI; } @@ -237,7 +236,7 @@ static PJ_XY qsc_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ static PJ_LP qsc_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_qsc_data *Q = static_cast(P->opaque); double mu, nu, cosmu, tannu; double tantheta, theta, cosphi, phi; double t; @@ -248,15 +247,15 @@ static PJ_LP qsc_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ nu = atan(sqrt(xy.x * xy.x + xy.y * xy.y)); mu = atan2(xy.y, xy.x); if (xy.x >= 0.0 && xy.x >= fabs(xy.y)) { - area = AREA_0; + area = pj_qsc_ns::AREA_0; } else if (xy.y >= 0.0 && xy.y >= fabs(xy.x)) { - area = AREA_1; + area = pj_qsc_ns::AREA_1; mu -= M_HALFPI; } else if (xy.x < 0.0 && -xy.x >= fabs(xy.y)) { - area = AREA_2; + area = pj_qsc_ns::AREA_2; mu = (mu < 0.0 ? mu + M_PI : mu - M_PI); } else { - area = AREA_3; + area = pj_qsc_ns::AREA_3; mu += M_HALFPI; } @@ -282,28 +281,28 @@ static PJ_LP qsc_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ * For the top and bottom face, we can compute phi and lam directly. * For the other faces, we must use unit sphere cartesian coordinates * as an intermediate step. */ - if (Q->face == FACE_TOP) { + if (Q->face == pj_qsc_ns::FACE_TOP) { phi = acos(cosphi); lp.phi = M_HALFPI - phi; - if (area == AREA_0) { + if (area == pj_qsc_ns::AREA_0) { lp.lam = theta + M_HALFPI; - } else if (area == AREA_1) { + } else if (area == pj_qsc_ns::AREA_1) { lp.lam = (theta < 0.0 ? theta + M_PI : theta - M_PI); - } else if (area == AREA_2) { + } else if (area == pj_qsc_ns::AREA_2) { lp.lam = theta - M_HALFPI; - } else /* area == AREA_3 */ { + } else /* area == pj_qsc_ns::AREA_3 */ { lp.lam = theta; } - } else if (Q->face == FACE_BOTTOM) { + } else if (Q->face == pj_qsc_ns::FACE_BOTTOM) { phi = acos(cosphi); lp.phi = phi - M_HALFPI; - if (area == AREA_0) { + if (area == pj_qsc_ns::AREA_0) { lp.lam = -theta + M_HALFPI; - } else if (area == AREA_1) { + } else if (area == pj_qsc_ns::AREA_1) { lp.lam = -theta; - } else if (area == AREA_2) { + } else if (area == pj_qsc_ns::AREA_2) { lp.lam = -theta - M_HALFPI; - } else /* area == AREA_3 */ { + } else /* area == pj_qsc_ns::AREA_3 */ { lp.lam = (theta < 0.0 ? -theta - M_PI : -theta + M_PI); } } else { @@ -323,27 +322,27 @@ static PJ_LP qsc_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ r = sqrt(1.0 - t); } /* Rotate q,r,s into the correct area. */ - if (area == AREA_1) { + if (area == pj_qsc_ns::AREA_1) { t = r; r = -s; s = t; - } else if (area == AREA_2) { + } else if (area == pj_qsc_ns::AREA_2) { r = -r; s = -s; - } else if (area == AREA_3) { + } else if (area == pj_qsc_ns::AREA_3) { t = r; r = s; s = -t; } /* Rotate q,r,s into the correct cube face. */ - if (Q->face == FACE_RIGHT) { + if (Q->face == pj_qsc_ns::FACE_RIGHT) { t = q; q = -r; r = t; - } else if (Q->face == FACE_BACK) { + } else if (Q->face == pj_qsc_ns::FACE_BACK) { q = -q; r = -r; - } else if (Q->face == FACE_LEFT) { + } else if (Q->face == pj_qsc_ns::FACE_LEFT) { t = q; q = r; r = -t; @@ -351,11 +350,11 @@ static PJ_LP qsc_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ /* Now compute phi and lam from the unit sphere coordinates. */ lp.phi = acos(-s) - M_HALFPI; lp.lam = atan2(r, q); - if (Q->face == FACE_RIGHT) { + if (Q->face == pj_qsc_ns::FACE_RIGHT) { lp.lam = qsc_shift_longitude_origin(lp.lam, -M_HALFPI); - } else if (Q->face == FACE_BACK) { + } else if (Q->face == pj_qsc_ns::FACE_BACK) { lp.lam = qsc_shift_longitude_origin(lp.lam, -M_PI); - } else if (Q->face == FACE_LEFT) { + } else if (Q->face == pj_qsc_ns::FACE_LEFT) { lp.lam = qsc_shift_longitude_origin(lp.lam, +M_HALFPI); } } @@ -376,9 +375,9 @@ static PJ_LP qsc_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ return lp; } -PJ *PROJECTION(qsc) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(qsc) { + struct pj_qsc_data *Q = static_cast( + calloc(1, sizeof(struct pj_qsc_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -387,15 +386,16 @@ PJ *PROJECTION(qsc) { P->fwd = qsc_e_forward; /* Determine the cube face from the center of projection. */ if (P->phi0 >= M_HALFPI - M_FORTPI / 2.0) { - Q->face = FACE_TOP; + Q->face = pj_qsc_ns::FACE_TOP; } else if (P->phi0 <= -(M_HALFPI - M_FORTPI / 2.0)) { - Q->face = FACE_BOTTOM; + Q->face = pj_qsc_ns::FACE_BOTTOM; } else if (fabs(P->lam0) <= M_FORTPI) { - Q->face = FACE_FRONT; + Q->face = pj_qsc_ns::FACE_FRONT; } else if (fabs(P->lam0) <= M_HALFPI + M_FORTPI) { - Q->face = (P->lam0 > 0.0 ? FACE_RIGHT : FACE_LEFT); + Q->face = + (P->lam0 > 0.0 ? pj_qsc_ns::FACE_RIGHT : pj_qsc_ns::FACE_LEFT); } else { - Q->face = FACE_BACK; + Q->face = pj_qsc_ns::FACE_BACK; } /* Fill in useful values for the ellipsoid <-> sphere shift * described in [LK12]. */ @@ -408,3 +408,5 @@ PJ *PROJECTION(qsc) { return P; } + +#undef EPS10 diff --git a/src/projections/robin.cpp b/src/projections/robin.cpp index 5f8eb81d13..88c7fbf712 100644 --- a/src/projections/robin.cpp +++ b/src/projections/robin.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include "proj.h" #include "proj_internal.h" #include @@ -153,7 +153,7 @@ static PJ_LP robin_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(robin) { +PJ *PJ_PROJECTION(robin) { P->es = 0.; P->inv = robin_s_inverse; P->fwd = robin_s_forward; diff --git a/src/projections/rouss.cpp b/src/projections/rouss.cpp index 590c022316..db925d4f23 100644 --- a/src/projections/rouss.cpp +++ b/src/projections/rouss.cpp @@ -23,7 +23,6 @@ ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#define PJ_LIB_ #include #include @@ -32,7 +31,7 @@ #include "proj_internal.h" namespace { // anonymous namespace -struct pj_opaque { +struct pj_rouss_data { double s0; double A1, A2, A3, A4, A5, A6; double B1, B2, B3, B4, B5, B6, B7, B8; @@ -45,7 +44,7 @@ PROJ_HEAD(rouss, "Roussilhe Stereographic") "\n\tAzi, Ell"; static PJ_XY rouss_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_rouss_data *Q = static_cast(P->opaque); double s, al, cp, sp, al2, s2; cp = cos(lp.phi); @@ -67,7 +66,7 @@ static PJ_XY rouss_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ static PJ_LP rouss_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_rouss_data *Q = static_cast(P->opaque); double s, al, x = xy.x / P->k0, y = xy.y / P->k0, x2, y2; x2 = x * x; @@ -86,24 +85,24 @@ static PJ_LP rouss_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ return lp; } -static PJ *destructor(PJ *P, int errlev) { +static PJ *pj_rouss_destructor(PJ *P, int errlev) { if (nullptr == P) return nullptr; if (nullptr == P->opaque) return pj_default_destructor(P, errlev); - if (static_cast(P->opaque)->en) - free(static_cast(P->opaque)->en); + if (static_cast(P->opaque)->en) + free(static_cast(P->opaque)->en); return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); } -PJ *PROJECTION(rouss) { +PJ *PJ_PROJECTION(rouss) { double N0, es2, t, t2, R_R0_2, R_R0_4; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_rouss_data *Q = static_cast( + calloc(1, sizeof(struct pj_rouss_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -153,7 +152,7 @@ PJ *PROJECTION(rouss) { P->fwd = rouss_e_forward; P->inv = rouss_e_inverse; - P->destructor = destructor; + P->destructor = pj_rouss_destructor; return P; } diff --git a/src/projections/rpoly.cpp b/src/projections/rpoly.cpp index 9d0a043c54..d7e1ed69b7 100644 --- a/src/projections/rpoly.cpp +++ b/src/projections/rpoly.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -7,7 +7,7 @@ #include "proj_internal.h" namespace { // anonymous namespace -struct pj_opaque { +struct pj_rpoly_data { double phi1; double fxa; double fxb; @@ -22,7 +22,7 @@ PROJ_HEAD(rpoly, "Rectangular Polyconic") static PJ_XY rpoly_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_rpoly_data *Q = static_cast(P->opaque); double fa; if (Q->mode) @@ -41,9 +41,9 @@ static PJ_XY rpoly_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ return xy; } -PJ *PROJECTION(rpoly) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(rpoly) { + struct pj_rpoly_data *Q = static_cast( + calloc(1, sizeof(struct pj_rpoly_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -59,3 +59,5 @@ PJ *PROJECTION(rpoly) { return P; } + +#undef EPS diff --git a/src/projections/s2.cpp b/src/projections/s2.cpp index d2633f9384..a90a4f79b7 100644 --- a/src/projections/s2.cpp +++ b/src/projections/s2.cpp @@ -47,8 +47,6 @@ * https://github.com/google/s2geometry/blob/0c4c460bdfe696da303641771f9def900b3e440f/src/s2/util/math/vector.h ****************************************************************************/ -#define PJ_LIB_ - /* enable predefined math constants M_* for MS Visual Studio */ #if defined(_MSC_VER) || defined(_WIN32) #ifndef _USE_MATH_DEFINES @@ -83,7 +81,7 @@ static std::map stringToS2ProjectionType{ {"none", NoUVtoST}}; namespace { // anonymous namespace -struct pj_opaque { +struct pj_s2 { enum Face face; double a_squared; double one_minus_f; @@ -336,7 +334,7 @@ inline bool UVtoSphereXYZ(int face, double u, double v, PJ_XYZ *xyz) { // // ============================================ static PJ_XY s2_forward(PJ_LP lp, PJ *P) { - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_s2 *Q = static_cast(P->opaque); double lat; /* Convert the geodetic latitude to a geocentric latitude. @@ -372,7 +370,7 @@ static PJ_XY s2_forward(PJ_LP lp, PJ *P) { static PJ_LP s2_inverse(PJ_XY xy, PJ *P) { PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_s2 *Q = static_cast(P->opaque); // Do the S2 projections to get from s,t to u,v to x,y,z double u = STtoUV(xy.x, Q->UVtoST); @@ -405,9 +403,9 @@ static PJ_LP s2_inverse(PJ_XY xy, PJ *P) { return lp; } -PJ *PROJECTION(s2) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(s2) { + struct pj_s2 *Q = + static_cast(calloc(1, sizeof(struct pj_s2))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; diff --git a/src/projections/sch.cpp b/src/projections/sch.cpp index 2851947ebd..8edf5d471a 100644 --- a/src/projections/sch.cpp +++ b/src/projections/sch.cpp @@ -33,8 +33,6 @@ * DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#define PJ_LIB_ - #include #include @@ -42,7 +40,7 @@ #include "proj_internal.h" namespace { // anonymous namespace -struct pj_opaque { +struct pj_sch_data { double plat; /*Peg Latitude */ double plon; /*Peg Longitude*/ double phdg; /*Peg heading */ @@ -59,7 +57,7 @@ PROJ_HEAD(sch, "Spherical Cross-track Height") "\n\tMisc\n\tplat_0= plon_0= phdg_0= [h_0=]"; static PJ_LPZ sch_inverse3d(PJ_XYZ xyz, PJ *P) { - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_sch_data *Q = static_cast(P->opaque); PJ_LPZ lpz; lpz.lam = xyz.x * (P->a / Q->rcurv); @@ -85,7 +83,7 @@ static PJ_LPZ sch_inverse3d(PJ_XYZ xyz, PJ *P) { } static PJ_XYZ sch_forward3d(PJ_LPZ lpz, PJ *P) { - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_sch_data *Q = static_cast(P->opaque); /* Convert lat long to geocentric coordinates */ PJ_XYZ xyz = Q->cart->fwd3d(lpz, Q->cart); @@ -114,11 +112,11 @@ static PJ_XYZ sch_forward3d(PJ_LPZ lpz, PJ *P) { return xyz; } -static PJ *destructor(PJ *P, int errlev) { +static PJ *pj_sch_destructor(PJ *P, int errlev) { if (nullptr == P) return nullptr; - auto Q = static_cast(P->opaque); + auto Q = static_cast(P->opaque); if (Q) { if (Q->cart) Q->cart->destructor(Q->cart, errlev); @@ -129,14 +127,14 @@ static PJ *destructor(PJ *P, int errlev) { return pj_default_destructor(P, errlev); } -static PJ *setup(PJ *P) { /* general initialization */ - struct pj_opaque *Q = static_cast(P->opaque); +static PJ *pj_sch_setup(PJ *P) { /* general initialization */ + struct pj_sch_data *Q = static_cast(P->opaque); /* Setup original geocentric system */ // Pass a dummy ellipsoid definition that will be overridden just afterwards Q->cart = proj_create(P->ctx, "+proj=cart +a=1"); if (Q->cart == nullptr) - return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); + return pj_sch_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); /* inherit ellipsoid definition from P to Q->cart */ pj_inherit_ellipsoid_def(P, Q->cart); @@ -160,7 +158,7 @@ static PJ *setup(PJ *P) { /* general initialization */ /* Set up local sphere at the given peg point */ Q->cart_sph = proj_create(P->ctx, "+proj=cart +a=1"); if (Q->cart_sph == nullptr) - return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); + return pj_sch_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); pj_calc_ellipsoid_params(Q->cart_sph, Q->rcurv, 0); /* Set up the transformation matrices */ @@ -188,13 +186,13 @@ static PJ *setup(PJ *P) { /* general initialization */ return P; } -PJ *PROJECTION(sch) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(sch) { + struct pj_sch_data *Q = static_cast( + calloc(1, sizeof(struct pj_sch_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; - P->destructor = destructor; + P->destructor = pj_sch_destructor; Q->h0 = 0.0; @@ -226,5 +224,5 @@ PJ *PROJECTION(sch) { if (pj_param(P->ctx, P->params, "th_0").i) Q->h0 = pj_param(P->ctx, P->params, "dh_0").f; - return setup(P); + return pj_sch_setup(P); } diff --git a/src/projections/sconics.cpp b/src/projections/sconics.cpp index 653b4c5023..49bac82edf 100644 --- a/src/projections/sconics.cpp +++ b/src/projections/sconics.cpp @@ -1,10 +1,10 @@ -#define PJ_LIB_ + #include "proj.h" #include "proj_internal.h" #include #include -namespace { // anonymous namespace +namespace pj_sconics_ns { enum Type { EULER = 0, MURD1 = 1, @@ -14,16 +14,16 @@ enum Type { TISSOT = 5, VITK1 = 6 }; -} // anonymous namespace +} namespace { // anonymous namespace -struct pj_opaque { +struct pj_sconics_data { double n; double rho_c; double rho_0; double sig; double c1, c2; - enum Type type; + enum pj_sconics_ns::Type type; }; } // anonymous namespace @@ -55,7 +55,7 @@ static int phi12(PJ *P, double *del) { p2 = pj_param(P->ctx, P->params, "rlat_2").f; *del = 0.5 * (p2 - p1); const double sig = 0.5 * (p2 + p1); - static_cast(P->opaque)->sig = sig; + static_cast(P->opaque)->sig = sig; err = (fabs(*del) < EPS || fabs(sig) < EPS) ? PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE : 0; @@ -70,14 +70,15 @@ static int phi12(PJ *P, double *del) { static PJ_XY sconics_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_sconics_data *Q = + static_cast(P->opaque); double rho; switch (Q->type) { - case MURD2: + case pj_sconics_ns::MURD2: rho = Q->rho_c + tan(Q->sig - lp.phi); break; - case PCONIC: + case pj_sconics_ns::PCONIC: rho = Q->c2 * (Q->c1 - tan(lp.phi - Q->sig)); break; default: @@ -94,7 +95,8 @@ static PJ_LP sconics_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, (and ellipsoidal?) inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_sconics_data *Q = + static_cast(P->opaque); double rho; xy.y = Q->rho_0 - xy.y; @@ -108,10 +110,10 @@ sconics_s_inverse(PJ_XY xy, lp.lam = atan2(xy.x, xy.y) / Q->n; switch (Q->type) { - case PCONIC: + case pj_sconics_ns::PCONIC: lp.phi = atan(Q->c1 - rho / Q->c2) + Q->sig; break; - case MURD2: + case pj_sconics_ns::MURD2: lp.phi = Q->sig - atan(rho - Q->rho_c); break; default: @@ -120,11 +122,11 @@ sconics_s_inverse(PJ_XY xy, return lp; } -static PJ *setup(PJ *P, enum Type type) { +static PJ *pj_sconics_setup(PJ *P, enum pj_sconics_ns::Type type) { double del, cs; int err; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_sconics_data *Q = static_cast( + calloc(1, sizeof(struct pj_sconics_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -136,39 +138,39 @@ static PJ *setup(PJ *P, enum Type type) { switch (Q->type) { - case TISSOT: + case pj_sconics_ns::TISSOT: Q->n = sin(Q->sig); cs = cos(del); Q->rho_c = Q->n / cs + cs / Q->n; Q->rho_0 = sqrt((Q->rho_c - 2 * sin(P->phi0)) / Q->n); break; - case MURD1: + case pj_sconics_ns::MURD1: Q->rho_c = sin(del) / (del * tan(Q->sig)) + Q->sig; Q->rho_0 = Q->rho_c - P->phi0; Q->n = sin(Q->sig); break; - case MURD2: + case pj_sconics_ns::MURD2: Q->rho_c = (cs = sqrt(cos(del))) / tan(Q->sig); Q->rho_0 = Q->rho_c + tan(Q->sig - P->phi0); Q->n = sin(Q->sig) * cs; break; - case MURD3: + case pj_sconics_ns::MURD3: Q->rho_c = del / (tan(Q->sig) * tan(del)) + Q->sig; Q->rho_0 = Q->rho_c - P->phi0; Q->n = sin(Q->sig) * sin(del) * tan(del) / (del * del); break; - case EULER: + case pj_sconics_ns::EULER: Q->n = sin(Q->sig) * sin(del) / del; del *= 0.5; Q->rho_c = del / (tan(del) * tan(Q->sig)) + Q->sig; Q->rho_0 = Q->rho_c - P->phi0; break; - case PCONIC: + case pj_sconics_ns::PCONIC: Q->n = sin(Q->sig); Q->c2 = cos(del); Q->c1 = 1. / tan(Q->sig); @@ -183,7 +185,7 @@ static PJ *setup(PJ *P, enum Type type) { Q->rho_0 = Q->c2 * (Q->c1 - tan(del)); break; - case VITK1: + case pj_sconics_ns::VITK1: cs = tan(del); Q->n = cs * sin(Q->sig) / del; Q->rho_c = del / (cs * tan(Q->sig)) + Q->sig; @@ -197,16 +199,20 @@ static PJ *setup(PJ *P, enum Type type) { return (P); } -PJ *PROJECTION(euler) { return setup(P, EULER); } +PJ *PJ_PROJECTION(euler) { return pj_sconics_setup(P, pj_sconics_ns::EULER); } + +PJ *PJ_PROJECTION(tissot) { return pj_sconics_setup(P, pj_sconics_ns::TISSOT); } -PJ *PROJECTION(tissot) { return setup(P, TISSOT); } +PJ *PJ_PROJECTION(murd1) { return pj_sconics_setup(P, pj_sconics_ns::MURD1); } -PJ *PROJECTION(murd1) { return setup(P, MURD1); } +PJ *PJ_PROJECTION(murd2) { return pj_sconics_setup(P, pj_sconics_ns::MURD2); } -PJ *PROJECTION(murd2) { return setup(P, MURD2); } +PJ *PJ_PROJECTION(murd3) { return pj_sconics_setup(P, pj_sconics_ns::MURD3); } -PJ *PROJECTION(murd3) { return setup(P, MURD3); } +PJ *PJ_PROJECTION(pconic) { return pj_sconics_setup(P, pj_sconics_ns::PCONIC); } -PJ *PROJECTION(pconic) { return setup(P, PCONIC); } +PJ *PJ_PROJECTION(vitk1) { return pj_sconics_setup(P, pj_sconics_ns::VITK1); } -PJ *PROJECTION(vitk1) { return setup(P, VITK1); } +#undef EPS10 +#undef EPS +#undef LINE2 diff --git a/src/projections/som.cpp b/src/projections/som.cpp index dcddffb9cb..cae0e313ef 100644 --- a/src/projections/som.cpp +++ b/src/projections/som.cpp @@ -43,7 +43,6 @@ * *****************************************************************************/ /* based upon Snyder and Linck, USGS-NMD */ -#define PJ_LIB_ #include #include @@ -61,7 +60,7 @@ PROJ_HEAD(lsat, "Space oblique for LANDSAT") #define TOL 1e-7 namespace { // anonymous namespace -struct pj_opaque { +struct pj_som_data { double a2, a4, b, c1, c3; double q, t, u, w, p22, sa, ca, xj, rlm, rlm2; double alf; @@ -69,7 +68,7 @@ struct pj_opaque { } // anonymous namespace static void seraz0(double lam, double mult, PJ *P) { - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_som_data *Q = static_cast(P->opaque); double sdsq, h, s, fc, sd, sq, d_1 = 0; lam *= DEG_TO_RAD; @@ -92,7 +91,7 @@ static void seraz0(double lam, double mult, PJ *P) { static PJ_XY som_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_som_data *Q = static_cast(P->opaque); int l, nn; double lamt = 0.0, xlam, sdsq, c, d, s, lamdp = 0.0, phidp, lampp, tanph; double lamtp, cl, sd, sp, sav, tanphi; @@ -155,7 +154,7 @@ static PJ_XY som_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ static PJ_LP som_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_som_data *Q = static_cast(P->opaque); int nn; double lamt, sdsq, s, lamdp, phidp, sppsq, dd, sd, sl, fac, scl, sav, spp; @@ -205,9 +204,9 @@ static PJ_LP som_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ return lp; } -static PJ *setup(PJ *P) { +static PJ *som_setup(PJ *P) { double esc, ess, lam; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_som_data *Q = static_cast(P->opaque); Q->sa = sin(Q->alf); Q->ca = cos(Q->alf); if (fabs(Q->ca) < 1e-9) @@ -240,9 +239,9 @@ static PJ *setup(PJ *P) { return P; } -PJ *PROJECTION(som) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(som) { + struct pj_som_data *Q = static_cast( + calloc(1, sizeof(struct pj_som_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -273,14 +272,14 @@ PJ *PROJECTION(som) { Q->rlm = 0; - return setup(P); + return som_setup(P); } -PJ *PROJECTION(misrsom) { +PJ *PJ_PROJECTION(misrsom) { int path; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_som_data *Q = static_cast( + calloc(1, sizeof(struct pj_som_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -298,13 +297,13 @@ PJ *PROJECTION(misrsom) { Q->rlm = 0; - return setup(P); + return som_setup(P); } -PJ *PROJECTION(lsat) { +PJ *PJ_PROJECTION(lsat) { int land, path; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_som_data *Q = static_cast( + calloc(1, sizeof(struct pj_som_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -338,5 +337,7 @@ PJ *PROJECTION(lsat) { Q->rlm = M_PI * (1. / 248. + .5161290322580645); - return setup(P); + return som_setup(P); } + +#undef TOL diff --git a/src/projections/somerc.cpp b/src/projections/somerc.cpp index 5bb198bd0b..42048dd9fd 100644 --- a/src/projections/somerc.cpp +++ b/src/projections/somerc.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -9,7 +9,7 @@ PROJ_HEAD(somerc, "Swiss. Obl. Mercator") "\n\tCyl, Ell\n\tFor CH1903"; namespace { // anonymous namespace -struct pj_opaque { +struct pj_somerc { double K, c, hlf_e, kR, cosp0, sinp0; }; } // anonymous namespace @@ -20,7 +20,7 @@ struct pj_opaque { static PJ_XY somerc_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ PJ_XY xy = {0.0, 0.0}; double phip, lamp, phipp, lampp, sp, cp; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_somerc *Q = static_cast(P->opaque); sp = P->e * sin(lp.phi); phip = 2. * atan(exp(Q->c * (log(tan(M_FORTPI + 0.5 * lp.phi)) - @@ -38,7 +38,7 @@ static PJ_XY somerc_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ static PJ_LP somerc_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_somerc *Q = static_cast(P->opaque); double phip, lamp, phipp, lampp, cp, esp, con, delp; int i; @@ -67,10 +67,10 @@ static PJ_LP somerc_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ return (lp); } -PJ *PROJECTION(somerc) { +PJ *PJ_PROJECTION(somerc) { double cp, phip0, sp; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_somerc *Q = + static_cast(calloc(1, sizeof(struct pj_somerc))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -92,3 +92,6 @@ PJ *PROJECTION(somerc) { P->fwd = somerc_e_forward; return P; } + +#undef EPS +#undef NITER diff --git a/src/projections/stere.cpp b/src/projections/stere.cpp index 7a745a810b..e928518d11 100644 --- a/src/projections/stere.cpp +++ b/src/projections/stere.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include "proj.h" #include "proj_internal.h" #include @@ -12,7 +12,7 @@ enum Mode { S_POLE = 0, N_POLE = 1, OBLIQ = 2, EQUIT = 3 }; } // anonymous namespace namespace { // anonymous namespace -struct pj_opaque { +struct pj_stere { double phits; double sinX1; double cosX1; @@ -21,8 +21,8 @@ struct pj_opaque { }; } // anonymous namespace -#define sinph0 static_cast(P->opaque)->sinX1 -#define cosph0 static_cast(P->opaque)->cosX1 +#define sinph0 static_cast(P->opaque)->sinX1 +#define cosph0 static_cast(P->opaque)->cosX1 #define EPS10 1.e-10 #define TOL 1.e-8 #define NITER 8 @@ -36,7 +36,7 @@ static double ssfn_(double phit, double sinphi, double eccen) { static PJ_XY stere_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_stere *Q = static_cast(P->opaque); double coslam, sinlam, sinX = 0.0, cosX = 0.0, A = 0.0, sinphi; coslam = cos(lp.lam); @@ -93,7 +93,7 @@ static PJ_XY stere_e_forward(PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ static PJ_XY stere_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_stere *Q = static_cast(P->opaque); double sinphi, cosphi, coslam, sinlam; sinphi = sin(lp.phi); @@ -136,7 +136,7 @@ static PJ_XY stere_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP stere_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_stere *Q = static_cast(P->opaque); double cosphi, sinphi, tp = 0.0, phi_l = 0.0, rho, halfe = 0.0, halfpi = 0.0; @@ -189,7 +189,7 @@ static PJ_LP stere_e_inverse(PJ_XY xy, PJ *P) { /* Ellipsoidal, inverse */ static PJ_LP stere_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_stere *Q = static_cast(P->opaque); double c, sinc, cosc; const double rh = hypot(xy.x, xy.y); @@ -230,9 +230,9 @@ static PJ_LP stere_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -static PJ *setup(PJ *P) { /* general initialization */ +static PJ *stere_setup(PJ *P) { /* general initialization */ double t; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_stere *Q = static_cast(P->opaque); if (fabs((t = fabs(P->phi0)) - M_HALFPI) < EPS10) Q->mode = P->phi0 < 0. ? S_POLE : N_POLE; @@ -292,9 +292,9 @@ static PJ *setup(PJ *P) { /* general initialization */ return P; } -PJ *PROJECTION(stere) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(stere) { + struct pj_stere *Q = + static_cast(calloc(1, sizeof(struct pj_stere))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -303,12 +303,12 @@ PJ *PROJECTION(stere) { ? pj_param(P->ctx, P->params, "rlat_ts").f : M_HALFPI; - return setup(P); + return stere_setup(P); } -PJ *PROJECTION(ups) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(ups) { + struct pj_stere *Q = + static_cast(calloc(1, sizeof(struct pj_stere))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -327,5 +327,12 @@ PJ *PROJECTION(ups) { Q->phits = M_HALFPI; P->lam0 = 0.; - return setup(P); + return stere_setup(P); } + +#undef sinph0 +#undef cosph0 +#undef EPS10 +#undef TOL +#undef NITER +#undef CONV diff --git a/src/projections/sterea.cpp b/src/projections/sterea.cpp index 4442f4273c..6b7f84a6d5 100644 --- a/src/projections/sterea.cpp +++ b/src/projections/sterea.cpp @@ -23,7 +23,7 @@ ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#define PJ_LIB_ + #include "proj.h" #include "proj_internal.h" #include @@ -92,7 +92,7 @@ static PJ *destructor(PJ *P, int errlev) { return pj_default_destructor(P, errlev); } -PJ *PROJECTION(sterea) { +PJ *PJ_PROJECTION(sterea) { double R; struct pj_opaque *Q = static_cast(calloc(1, sizeof(struct pj_opaque))); diff --git a/src/projections/sts.cpp b/src/projections/sts.cpp index 59ddf06272..ebaa28ab3d 100644 --- a/src/projections/sts.cpp +++ b/src/projections/sts.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -12,7 +12,7 @@ PROJ_HEAD(fouc, "Foucaut") "\n\tPCyl, Sph"; PROJ_HEAD(mbt_s, "McBryde-Thomas Flat-Polar Sine (No. 1)") "\n\tPCyl, Sph"; namespace { // anonymous namespace -struct pj_opaque { +struct pj_sts { double C_x, C_y, C_p; int tan_mode; }; @@ -20,7 +20,7 @@ struct pj_opaque { static PJ_XY sts_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_sts *Q = static_cast(P->opaque); xy.x = Q->C_x * lp.lam * cos(lp.phi); xy.y = Q->C_y; @@ -38,7 +38,7 @@ static PJ_XY sts_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP sts_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_sts *Q = static_cast(P->opaque); xy.y /= Q->C_y; lp.phi = Q->tan_mode ? atan(xy.y) : aasin(P->ctx, xy.y); @@ -56,25 +56,25 @@ static PJ *setup(PJ *P, double p, double q, int mode) { P->es = 0.; P->inv = sts_s_inverse; P->fwd = sts_s_forward; - static_cast(P->opaque)->C_x = q / p; - static_cast(P->opaque)->C_y = p; - static_cast(P->opaque)->C_p = 1 / q; - static_cast(P->opaque)->tan_mode = mode; + static_cast(P->opaque)->C_x = q / p; + static_cast(P->opaque)->C_y = p; + static_cast(P->opaque)->C_p = 1 / q; + static_cast(P->opaque)->tan_mode = mode; return P; } -PJ *PROJECTION(fouc) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(fouc) { + struct pj_sts *Q = + static_cast(calloc(1, sizeof(struct pj_sts))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; return setup(P, 2., 2., 1); } -PJ *PROJECTION(kav5) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(kav5) { + struct pj_sts *Q = + static_cast(calloc(1, sizeof(struct pj_sts))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -82,18 +82,18 @@ PJ *PROJECTION(kav5) { return setup(P, 1.50488, 1.35439, 0); } -PJ *PROJECTION(qua_aut) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(qua_aut) { + struct pj_sts *Q = + static_cast(calloc(1, sizeof(struct pj_sts))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; return setup(P, 2., 2., 0); } -PJ *PROJECTION(mbt_s) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(mbt_s) { + struct pj_sts *Q = + static_cast(calloc(1, sizeof(struct pj_sts))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; diff --git a/src/projections/tcc.cpp b/src/projections/tcc.cpp index 51a8fbd63b..f9ed54c8fd 100644 --- a/src/projections/tcc.cpp +++ b/src/projections/tcc.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -23,7 +23,7 @@ static PJ_XY tcc_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ return xy; } -PJ *PROJECTION(tcc) { +PJ *PJ_PROJECTION(tcc) { P->es = 0.; P->fwd = tcc_s_forward; P->inv = nullptr; diff --git a/src/projections/tcea.cpp b/src/projections/tcea.cpp index c839655b25..a2cac1707c 100644 --- a/src/projections/tcea.cpp +++ b/src/projections/tcea.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -26,7 +26,7 @@ static PJ_LP tcea_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(tcea) { +PJ *PJ_PROJECTION(tcea) { P->inv = tcea_s_inverse; P->fwd = tcea_s_forward; P->es = 0.; diff --git a/src/projections/times.cpp b/src/projections/times.cpp index 9c8eab828a..11ac6b6db9 100644 --- a/src/projections/times.cpp +++ b/src/projections/times.cpp @@ -29,8 +29,6 @@ * Flattening the Earth, Snyder, J.P., 1993, p.213-214. *****************************************************************************/ -#define PJ_LIB_ - #include #include "proj.h" @@ -68,7 +66,7 @@ static PJ_LP times_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(times) { +PJ *PJ_PROJECTION(times) { P->es = 0.0; P->inv = times_s_inverse; diff --git a/src/projections/tmerc.cpp b/src/projections/tmerc.cpp index c3b65c14d0..76576a1c72 100644 --- a/src/projections/tmerc.cpp +++ b/src/projections/tmerc.cpp @@ -10,8 +10,6 @@ * slower, but more accurate implementation. */ -#define PJ_LIB_ - #include #include @@ -711,7 +709,7 @@ static bool getAlgoFromParams(PJ *P, TMercAlgo &algo) { // /*****************************************************************************/ -PJ *PROJECTION(tmerc) { +PJ *PJ_PROJECTION(tmerc) { /* exact transverse mercator only exists in ellipsoidal form, */ /* use approximate version if +a sphere is requested */ @@ -723,7 +721,7 @@ PJ *PROJECTION(tmerc) { return setup(P, algo); } -PJ *PROJECTION(etmerc) { +PJ *PJ_PROJECTION(etmerc) { if (P->es == 0.0) { proj_log_error( P, _("Invalid value for eccentricity: it should not be zero")); @@ -736,7 +734,7 @@ PJ *PROJECTION(etmerc) { /* UTM uses the Poder/Engsager implementation for the underlying projection */ /* UNLESS +approx is set in which case the Evenden/Snyder implementation is * used. */ -PJ *PROJECTION(utm) { +PJ *PJ_PROJECTION(utm) { long zone; if (P->es == 0.0) { proj_log_error( diff --git a/src/projections/tobmerc.cpp b/src/projections/tobmerc.cpp index 0c3fb812db..5ed875e460 100644 --- a/src/projections/tobmerc.cpp +++ b/src/projections/tobmerc.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -40,7 +40,7 @@ static PJ_LP tobmerc_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(tobmerc) { +PJ *PJ_PROJECTION(tobmerc) { P->inv = tobmerc_s_inverse; P->fwd = tobmerc_s_forward; return P; diff --git a/src/projections/tpeqd.cpp b/src/projections/tpeqd.cpp index abba06ca67..b62a95d595 100644 --- a/src/projections/tpeqd.cpp +++ b/src/projections/tpeqd.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include "proj.h" #include "proj_internal.h" #include @@ -8,7 +8,7 @@ PROJ_HEAD(tpeqd, "Two Point Equidistant") "\n\tMisc Sph\n\tlat_1= lon_1= lat_2= lon_2="; namespace { // anonymous namespace -struct pj_opaque { +struct pj_tpeqd { double cp1, sp1, cp2, sp2, ccs, cs, sc, r2z0, z02, dlam2; double hz0, thz0, rhshz0, ca, sa, lp, lamc; }; @@ -16,7 +16,7 @@ struct pj_opaque { static PJ_XY tpeqd_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_tpeqd *Q = static_cast(P->opaque); double t, z1, z2, dl1, dl2, sp, cp; sp = sin(lp.phi); @@ -39,7 +39,7 @@ static PJ_XY tpeqd_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP tpeqd_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_tpeqd *Q = static_cast(P->opaque); double cz1, cz2, s, d, cp, sp; cz1 = cos(hypot(xy.y, xy.x + Q->hz0)); @@ -60,10 +60,10 @@ static PJ_LP tpeqd_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(tpeqd) { +PJ *PJ_PROJECTION(tpeqd) { double lam_1, lam_2, phi_1, phi_2, A12; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_tpeqd *Q = + static_cast(calloc(1, sizeof(struct pj_tpeqd))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; diff --git a/src/projections/urm5.cpp b/src/projections/urm5.cpp index f93e7cb0d2..a669397d3b 100644 --- a/src/projections/urm5.cpp +++ b/src/projections/urm5.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -9,14 +9,14 @@ PROJ_HEAD(urm5, "Urmaev V") "\n\tPCyl, Sph, no inv\n\tn= q= alpha="; namespace { // anonymous namespace -struct pj_opaque { +struct pj_urm5 { double m, rmn, q3, n; }; } // anonymous namespace static PJ_XY urm5_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_urm5 *Q = static_cast(P->opaque); double t; t = lp.phi = aasin(P->ctx, Q->n * sin(lp.phi)); @@ -26,10 +26,10 @@ static PJ_XY urm5_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ return xy; } -PJ *PROJECTION(urm5) { +PJ *PJ_PROJECTION(urm5) { double alpha, t; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_urm5 *Q = + static_cast(calloc(1, sizeof(struct pj_urm5))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; diff --git a/src/projections/urmfps.cpp b/src/projections/urmfps.cpp index 99acb6016c..d0a4738ec8 100644 --- a/src/projections/urmfps.cpp +++ b/src/projections/urmfps.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -10,7 +10,7 @@ PROJ_HEAD(urmfps, "Urmaev Flat-Polar Sinusoidal") "\n\tPCyl, Sph\n\tn="; PROJ_HEAD(wag1, "Wagner I (Kavrayskiy VI)") "\n\tPCyl, Sph"; namespace { // anonymous namespace -struct pj_opaque { +struct pj_urmfps { double n, C_y; }; } // anonymous namespace @@ -21,33 +21,33 @@ struct pj_opaque { static PJ_XY urmfps_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; lp.phi = aasin(P->ctx, - static_cast(P->opaque)->n * sin(lp.phi)); + static_cast(P->opaque)->n * sin(lp.phi)); xy.x = C_x * lp.lam * cos(lp.phi); - xy.y = static_cast(P->opaque)->C_y * lp.phi; + xy.y = static_cast(P->opaque)->C_y * lp.phi; return xy; } static PJ_LP urmfps_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; - xy.y /= static_cast(P->opaque)->C_y; + xy.y /= static_cast(P->opaque)->C_y; lp.phi = aasin(P->ctx, - sin(xy.y) / static_cast(P->opaque)->n); + sin(xy.y) / static_cast(P->opaque)->n); lp.lam = xy.x / (C_x * cos(xy.y)); return lp; } -static PJ *setup(PJ *P) { - static_cast(P->opaque)->C_y = - Cy / static_cast(P->opaque)->n; +static PJ *urmfps_setup(PJ *P) { + static_cast(P->opaque)->C_y = + Cy / static_cast(P->opaque)->n; P->es = 0.; P->inv = urmfps_s_inverse; P->fwd = urmfps_s_forward; return P; } -PJ *PROJECTION(urmfps) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(urmfps) { + struct pj_urmfps *Q = + static_cast(calloc(1, sizeof(struct pj_urmfps))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); @@ -65,17 +65,20 @@ PJ *PROJECTION(urmfps) { return pj_default_destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); } - return setup(P); + return urmfps_setup(P); } -PJ *PROJECTION(wag1) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(wag1) { + struct pj_urmfps *Q = + static_cast(calloc(1, sizeof(struct pj_urmfps))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; - static_cast(P->opaque)->n = + static_cast(P->opaque)->n = 0.8660254037844386467637231707; - return setup(P); + return urmfps_setup(P); } + +#undef C_x +#undef Cy diff --git a/src/projections/vandg.cpp b/src/projections/vandg.cpp index c3f39cb90f..3a3afebf89 100644 --- a/src/projections/vandg.cpp +++ b/src/projections/vandg.cpp @@ -1,6 +1,5 @@ // Changes to handle +over are: Copyright 2011-2014 Morelli Informatik -#define PJ_LIB_ #include "proj.h" #include "proj_internal.h" @@ -129,10 +128,18 @@ static PJ_LP vandg_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return lp; } -PJ *PROJECTION(vandg) { +PJ *PJ_PROJECTION(vandg) { P->es = 0.; P->inv = vandg_s_inverse; P->fwd = vandg_s_forward; return P; } + +#undef TOL +#undef THIRD +#undef C2_27 +#undef PI4_3 +#undef PISQ +#undef TPISQ +#undef HPISQ diff --git a/src/projections/vandg2.cpp b/src/projections/vandg2.cpp index 37fe81e56d..c64aff8707 100644 --- a/src/projections/vandg2.cpp +++ b/src/projections/vandg2.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -7,7 +7,7 @@ #include "proj_internal.h" namespace { // anonymous namespace -struct pj_opaque { +struct pj_vandg2 { int vdg3; }; } // anonymous namespace @@ -19,7 +19,7 @@ PROJ_HEAD(vandg3, "van der Grinten III") "\n\tMisc Sph, no inv"; static PJ_XY vandg2_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - struct pj_opaque *Q = static_cast(P->opaque); + struct pj_vandg2 *Q = static_cast(P->opaque); double x1, at, bt, ct; bt = fabs(M_TWO_D_PI * lp.phi); @@ -52,9 +52,9 @@ static PJ_XY vandg2_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ return xy; } -PJ *PROJECTION(vandg2) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(vandg2) { + struct pj_vandg2 *Q = + static_cast(calloc(1, sizeof(struct pj_vandg2))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -65,9 +65,9 @@ PJ *PROJECTION(vandg2) { return P; } -PJ *PROJECTION(vandg3) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(vandg3) { + struct pj_vandg2 *Q = + static_cast(calloc(1, sizeof(struct pj_vandg2))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; @@ -78,3 +78,5 @@ PJ *PROJECTION(vandg3) { return P; } + +#undef TOL diff --git a/src/projections/vandg4.cpp b/src/projections/vandg4.cpp index e379e59186..58440f511a 100644 --- a/src/projections/vandg4.cpp +++ b/src/projections/vandg4.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -48,7 +48,7 @@ static PJ_XY vandg4_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ return xy; } -PJ *PROJECTION(vandg4) { +PJ *PJ_PROJECTION(vandg4) { P->es = 0.; P->fwd = vandg4_s_forward; diff --git a/src/projections/wag2.cpp b/src/projections/wag2.cpp index bbe41240f7..f937b8c432 100644 --- a/src/projections/wag2.cpp +++ b/src/projections/wag2.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -28,9 +28,14 @@ static PJ_LP wag2_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ return (lp); } -PJ *PROJECTION(wag2) { +PJ *PJ_PROJECTION(wag2) { P->es = 0.; P->inv = wag2_s_inverse; P->fwd = wag2_s_forward; return P; } + +#undef C_x +#undef C_y +#undef C_p1 +#undef C_p2 diff --git a/src/projections/wag3.cpp b/src/projections/wag3.cpp index ecdcfe208d..cbf939984a 100644 --- a/src/projections/wag3.cpp +++ b/src/projections/wag3.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -11,14 +11,14 @@ PROJ_HEAD(wag3, "Wagner III") "\n\tPCyl, Sph\n\tlat_ts="; #define TWOTHIRD 0.6666666666666666666667 namespace { // anonymous namespace -struct pj_opaque { +struct pj_wag3 { double C_x; }; } // anonymous namespace static PJ_XY wag3_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - xy.x = static_cast(P->opaque)->C_x * lp.lam * + xy.x = static_cast(P->opaque)->C_x * lp.lam * cos(TWOTHIRD * lp.phi); xy.y = lp.phi; return xy; @@ -27,26 +27,27 @@ static PJ_XY wag3_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ static PJ_LP wag3_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ PJ_LP lp = {0.0, 0.0}; lp.phi = xy.y; - lp.lam = xy.x / (static_cast(P->opaque)->C_x * + lp.lam = xy.x / (static_cast(P->opaque)->C_x * cos(TWOTHIRD * lp.phi)); return lp; } -PJ *PROJECTION(wag3) { +PJ *PJ_PROJECTION(wag3) { double ts; - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); + struct pj_wag3 *Q = + static_cast(calloc(1, sizeof(struct pj_wag3))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; ts = pj_param(P->ctx, P->params, "rlat_ts").f; - static_cast(P->opaque)->C_x = - cos(ts) / cos(2. * ts / 3.); + static_cast(P->opaque)->C_x = cos(ts) / cos(2. * ts / 3.); P->es = 0.; P->inv = wag3_s_inverse; P->fwd = wag3_s_forward; return P; } + +#undef TWOTHIRD diff --git a/src/projections/wag7.cpp b/src/projections/wag7.cpp index dfb753eb85..5383a04099 100644 --- a/src/projections/wag7.cpp +++ b/src/projections/wag7.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include @@ -23,7 +23,7 @@ static PJ_XY wag7_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ return (xy); } -PJ *PROJECTION(wag7) { +PJ *PJ_PROJECTION(wag7) { P->fwd = wag7_s_forward; P->inv = nullptr; P->es = 0.; diff --git a/src/projections/wink1.cpp b/src/projections/wink1.cpp index c0169248d7..092a1137ab 100644 --- a/src/projections/wink1.cpp +++ b/src/projections/wink1.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -9,15 +9,16 @@ PROJ_HEAD(wink1, "Winkel I") "\n\tPCyl, Sph\n\tlat_ts="; namespace { // anonymous namespace -struct pj_opaque { +struct pj_wink1_data { double cosphi1; }; } // anonymous namespace static PJ_XY wink1_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ PJ_XY xy = {0.0, 0.0}; - xy.x = .5 * lp.lam * - (static_cast(P->opaque)->cosphi1 + cos(lp.phi)); + xy.x = + .5 * lp.lam * + (static_cast(P->opaque)->cosphi1 + cos(lp.phi)); xy.y = lp.phi; return (xy); } @@ -27,18 +28,18 @@ static PJ_LP wink1_s_inverse(PJ_XY xy, PJ *P) { /* Spheroidal, inverse */ lp.phi = xy.y; lp.lam = 2. * xy.x / - (static_cast(P->opaque)->cosphi1 + cos(lp.phi)); + (static_cast(P->opaque)->cosphi1 + cos(lp.phi)); return (lp); } -PJ *PROJECTION(wink1) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(wink1) { + struct pj_wink1_data *Q = static_cast( + calloc(1, sizeof(struct pj_wink1_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; - static_cast(P->opaque)->cosphi1 = + static_cast(P->opaque)->cosphi1 = cos(pj_param(P->ctx, P->params, "rlat_ts").f); P->es = 0.; P->inv = wink1_s_inverse; diff --git a/src/projections/wink2.cpp b/src/projections/wink2.cpp index dd2d8aac82..721a51e0db 100644 --- a/src/projections/wink2.cpp +++ b/src/projections/wink2.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -9,7 +9,7 @@ PROJ_HEAD(wink2, "Winkel II") "\n\tPCyl, Sph\n\tlat_1="; namespace { // anonymous namespace -struct pj_opaque { +struct pj_wink2_data { double cosphi1; }; } // anonymous namespace @@ -34,8 +34,9 @@ static PJ_XY wink2_s_forward(PJ_LP lp, PJ *P) { /* Spheroidal, forward */ lp.phi = (lp.phi < 0.) ? -M_HALFPI : M_HALFPI; else lp.phi *= 0.5; - xy.x = 0.5 * lp.lam * - (cos(lp.phi) + static_cast(P->opaque)->cosphi1); + xy.x = + 0.5 * lp.lam * + (cos(lp.phi) + static_cast(P->opaque)->cosphi1); xy.y = M_FORTPI * (sin(lp.phi) + xy.y); return xy; } @@ -50,14 +51,14 @@ static PJ_LP wink2_s_inverse(PJ_XY xy, PJ *P) { return pj_generic_inverse_2d(xy, P, lpInit, deltaXYTolerance); } -PJ *PROJECTION(wink2) { - struct pj_opaque *Q = - static_cast(calloc(1, sizeof(struct pj_opaque))); +PJ *PJ_PROJECTION(wink2) { + struct pj_wink2_data *Q = static_cast( + calloc(1, sizeof(struct pj_wink2_data))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; - static_cast(P->opaque)->cosphi1 = + static_cast(P->opaque)->cosphi1 = cos(pj_param(P->ctx, P->params, "rlat_1").f); P->es = 0.; P->fwd = wink2_s_forward; @@ -65,3 +66,6 @@ PJ *PROJECTION(wink2) { return P; } + +#undef MAX_ITER +#undef LOOP_TOL diff --git a/src/transformations/affine.cpp b/src/transformations/affine.cpp index 3b9bfec34d..7acd8dce26 100644 --- a/src/transformations/affine.cpp +++ b/src/transformations/affine.cpp @@ -20,7 +20,6 @@ * DEALINGS IN THE SOFTWARE. * ***********************************************************************/ -#define PJ_LIB_ #include #include @@ -177,7 +176,7 @@ static void computeReverseParameters(PJ *P) { } } -PJ *TRANSFORMATION(affine, 0 /* no need for ellipsoid */) { +PJ *PJ_TRANSFORMATION(affine, 0 /* no need for ellipsoid */) { struct pj_opaque_affine *Q = initQ(); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); @@ -226,7 +225,7 @@ PJ *TRANSFORMATION(affine, 0 /* no need for ellipsoid */) { /* Arcsecond to radians */ #define ARCSEC_TO_RAD (DEG_TO_RAD / 3600.0) -PJ *TRANSFORMATION(geogoffset, 0 /* no need for ellipsoid */) { +PJ *PJ_TRANSFORMATION(geogoffset, 0 /* no need for ellipsoid */) { struct pj_opaque_affine *Q = initQ(); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); diff --git a/src/transformations/defmodel.cpp b/src/transformations/defmodel.cpp index 7fa2931e02..9c9e1178a1 100644 --- a/src/transformations/defmodel.cpp +++ b/src/transformations/defmodel.cpp @@ -25,7 +25,6 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ -#define PJ_LIB_ #define PROJ_COMPILATION #include "defmodel.hpp" @@ -374,7 +373,7 @@ static void reassign_context(PJ *P, PJ_CONTEXT *ctx) { } } -PJ *TRANSFORMATION(defmodel, 1) { +PJ *PJ_TRANSFORMATION(defmodel, 1) { // Pass a dummy ellipsoid definition that will be overridden just afterwards auto cart = proj_create(P->ctx, "+proj=cart +a=1"); if (cart == nullptr) diff --git a/src/transformations/deformation.cpp b/src/transformations/deformation.cpp index a34974ac89..3abc0dabb9 100644 --- a/src/transformations/deformation.cpp +++ b/src/transformations/deformation.cpp @@ -51,7 +51,7 @@ format, up component is (was) stored in the GTX format. Both grids are * DEALINGS IN THE SOFTWARE. * ***********************************************************************/ -#define PJ_LIB_ + #include "grids.hpp" #include "proj.h" #include "proj_internal.h" @@ -80,8 +80,9 @@ struct deformationData { // --------------------------------------------------------------------------- -static bool get_grid_values(PJ *P, deformationData *Q, const PJ_LP &lp, - double &vx, double &vy, double &vz) { +static bool pj_deformation_get_grid_values(PJ *P, deformationData *Q, + const PJ_LP &lp, double &vx, + double &vy, double &vz) { GenericShiftGridSet *gridset = nullptr; auto grid = pj_find_generic_grid(Q->grids, lp, gridset); if (!grid) { @@ -122,7 +123,7 @@ static bool get_grid_values(PJ *P, deformationData *Q, const PJ_LP &lp, sampleN, sampleU, vx, vy, vz, must_retry)) { if (must_retry) - return get_grid_values(P, Q, lp, vx, vy, vz); + return pj_deformation_get_grid_values(P, Q, lp, vx, vy, vz); return false; } // divide by 1000 to get m/year @@ -133,7 +134,7 @@ static bool get_grid_values(PJ *P, deformationData *Q, const PJ_LP &lp, } /********************************************************************************/ -static PJ_XYZ get_grid_shift(PJ *P, const PJ_XYZ &cartesian) { +static PJ_XYZ pj_deformation_get_grid_shift(PJ *P, const PJ_XYZ &cartesian) { /******************************************************************************** Read correction values from grid. The cartesian input coordinates are converted to geodetic coordinates in order look up the correction values @@ -159,7 +160,7 @@ static PJ_XYZ get_grid_shift(PJ *P, const PJ_XYZ &cartesian) { double vx = 0; double vy = 0; double vz = 0; - if (!get_grid_values(P, Q, geodetic.lp, vx, vy, vz)) { + if (!pj_deformation_get_grid_values(P, Q, geodetic.lp, vx, vy, vz)) { return proj_coord_error().xyz; } shift.xyz.x = vx; @@ -201,7 +202,7 @@ static PJ_XYZ get_grid_shift(PJ *P, const PJ_XYZ &cartesian) { } /********************************************************************************/ -static PJ_XYZ reverse_shift(PJ *P, PJ_XYZ input, double dt) { +static PJ_XYZ pj_deformation_reverse_shift(PJ *P, PJ_XYZ input, double dt) { /******************************************************************************** Iteratively determine the reverse grid shift correction values. *********************************************************************************/ @@ -209,7 +210,7 @@ static PJ_XYZ reverse_shift(PJ *P, PJ_XYZ input, double dt) { double z0; int i = MAX_ITERATIONS; - delta = get_grid_shift(P, input); + delta = pj_deformation_get_grid_shift(P, input); if (delta.x == HUGE_VAL) { return delta; } @@ -226,7 +227,7 @@ static PJ_XYZ reverse_shift(PJ *P, PJ_XYZ input, double dt) { out.z = input.z + dt * delta.z; do { - delta = get_grid_shift(P, out); + delta = pj_deformation_get_grid_shift(P, out); if (delta.x == HUGE_VAL) break; @@ -245,7 +246,7 @@ static PJ_XYZ reverse_shift(PJ *P, PJ_XYZ input, double dt) { return out; } -static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P) { +static PJ_XYZ pj_deformation_forward_3d(PJ_LPZ lpz, PJ *P) { struct deformationData *Q = (struct deformationData *)P->opaque; PJ_COORD out, in; PJ_XYZ shift; @@ -258,7 +259,7 @@ static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P) { return out.xyz; } - shift = get_grid_shift(P, in.xyz); + shift = pj_deformation_get_grid_shift(P, in.xyz); if (shift.x == HUGE_VAL) { return shift; } @@ -270,7 +271,7 @@ static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P) { return out.xyz; } -static void forward_4d(PJ_COORD &coo, PJ *P) { +static void pj_deformation_forward_4d(PJ_COORD &coo, PJ *P) { struct deformationData *Q = (struct deformationData *)P->opaque; double dt; PJ_XYZ shift; @@ -281,14 +282,14 @@ static void forward_4d(PJ_COORD &coo, PJ *P) { dt = coo.xyzt.t - Q->t_epoch; } - shift = get_grid_shift(P, coo.xyz); + shift = pj_deformation_get_grid_shift(P, coo.xyz); coo.xyzt.x += dt * shift.x; coo.xyzt.y += dt * shift.y; coo.xyzt.z += dt * shift.z; } -static PJ_LPZ reverse_3d(PJ_XYZ in, PJ *P) { +static PJ_LPZ pj_deformation_reverse_3d(PJ_XYZ in, PJ *P) { struct deformationData *Q = (struct deformationData *)P->opaque; PJ_COORD out; out.xyz = in; @@ -299,12 +300,12 @@ static PJ_LPZ reverse_3d(PJ_XYZ in, PJ *P) { return out.lpz; } - out.xyz = reverse_shift(P, in, Q->dt); + out.xyz = pj_deformation_reverse_shift(P, in, Q->dt); return out.lpz; } -static void reverse_4d(PJ_COORD &coo, PJ *P) { +static void pj_deformation_reverse_4d(PJ_COORD &coo, PJ *P) { struct deformationData *Q = (struct deformationData *)P->opaque; double dt; @@ -314,10 +315,10 @@ static void reverse_4d(PJ_COORD &coo, PJ *P) { dt = coo.xyzt.t - Q->t_epoch; } - coo.xyz = reverse_shift(P, coo.xyz, dt); + coo.xyz = pj_deformation_reverse_shift(P, coo.xyz, dt); } -static PJ *destructor(PJ *P, int errlev) { +static PJ *pj_deformation_destructor(PJ *P, int errlev) { if (nullptr == P) return nullptr; @@ -332,15 +333,15 @@ static PJ *destructor(PJ *P, int errlev) { return pj_default_destructor(P, errlev); } -PJ *TRANSFORMATION(deformation, 1) { +PJ *PJ_TRANSFORMATION(deformation, 1) { auto Q = new deformationData; P->opaque = (void *)Q; - P->destructor = destructor; + P->destructor = pj_deformation_destructor; // Pass a dummy ellipsoid definition that will be overridden just afterwards Q->cart = proj_create(P->ctx, "+proj=cart +a=1"); if (Q->cart == nullptr) - return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); + return pj_deformation_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); /* inherit ellipsoid definition from P to Q->cart */ pj_inherit_ellipsoid_def(P, Q->cart); @@ -353,7 +354,7 @@ PJ *TRANSFORMATION(deformation, 1) { if (!has_grids && (!has_xy_grids || !has_z_grids)) { proj_log_error(P, _("Either +grids or (+xy_grids and +z_grids) should " "be specified.")); - return destructor(P, PROJ_ERR_INVALID_OP_MISSING_ARG); + return pj_deformation_destructor(P, PROJ_ERR_INVALID_OP_MISSING_ARG); } if (has_grids) { @@ -361,19 +362,22 @@ PJ *TRANSFORMATION(deformation, 1) { /* Was gridlist compiled properly? */ if (proj_errno(P)) { proj_log_error(P, _("could not find required grid(s).)")); - return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); + return pj_deformation_destructor( + P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); } } else { Q->hgrids = pj_hgrid_init(P, "xy_grids"); if (proj_errno(P)) { proj_log_error(P, _("could not find requested xy_grid(s).")); - return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); + return pj_deformation_destructor( + P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); } Q->vgrids = pj_vgrid_init(P, "z_grids"); if (proj_errno(P)) { proj_log_error(P, _("could not find requested z_grid(s).")); - return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); + return pj_deformation_destructor( + P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); } } @@ -385,7 +389,7 @@ PJ *TRANSFORMATION(deformation, 1) { if (pj_param_exists(P->params, "t_obs")) { proj_log_error(P, _("+t_obs parameter is deprecated. Use +dt instead.")); - return destructor(P, PROJ_ERR_INVALID_OP_MISSING_ARG); + return pj_deformation_destructor(P, PROJ_ERR_INVALID_OP_MISSING_ARG); } Q->t_epoch = HUGE_VAL; @@ -395,18 +399,19 @@ PJ *TRANSFORMATION(deformation, 1) { if (Q->dt == HUGE_VAL && Q->t_epoch == HUGE_VAL) { proj_log_error(P, _("either +dt or +t_epoch needs to be set.")); - return destructor(P, PROJ_ERR_INVALID_OP_MISSING_ARG); + return pj_deformation_destructor(P, PROJ_ERR_INVALID_OP_MISSING_ARG); } if (Q->dt != HUGE_VALL && Q->t_epoch != HUGE_VALL) { proj_log_error(P, _("+dt or +t_epoch are mutually exclusive.")); - return destructor(P, PROJ_ERR_INVALID_OP_MUTUALLY_EXCLUSIVE_ARGS); + return pj_deformation_destructor( + P, PROJ_ERR_INVALID_OP_MUTUALLY_EXCLUSIVE_ARGS); } - P->fwd4d = forward_4d; - P->inv4d = reverse_4d; - P->fwd3d = forward_3d; - P->inv3d = reverse_3d; + P->fwd4d = pj_deformation_forward_4d; + P->inv4d = pj_deformation_reverse_4d; + P->fwd3d = pj_deformation_forward_3d; + P->inv3d = pj_deformation_reverse_3d; P->fwd = nullptr; P->inv = nullptr; @@ -415,3 +420,6 @@ PJ *TRANSFORMATION(deformation, 1) { return P; } + +#undef TOL +#undef MAX_ITERATIONS diff --git a/src/transformations/gridshift.cpp b/src/transformations/gridshift.cpp index 2d473b03d7..bda2e3d415 100644 --- a/src/transformations/gridshift.cpp +++ b/src/transformations/gridshift.cpp @@ -25,8 +25,6 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ -#define PJ_LIB_ - #include #include #include @@ -710,7 +708,7 @@ PJ_LPZ gridshiftData::apply(PJ *P, PJ_DIRECTION direction, PJ_LPZ lpz) { // --------------------------------------------------------------------------- -static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P) { +static PJ_XYZ pj_gridshift_forward_3d(PJ_LPZ lpz, PJ *P) { auto Q = static_cast(P->opaque); PJ_COORD point = {{0, 0, 0, 0}}; @@ -721,7 +719,7 @@ static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P) { // --------------------------------------------------------------------------- -static PJ_LPZ reverse_3d(PJ_XYZ xyz, PJ *P) { +static PJ_LPZ pj_gridshift_reverse_3d(PJ_XYZ xyz, PJ *P) { auto Q = static_cast(P->opaque); PJ_COORD point = {{0, 0, 0, 0}}; point.xyz = xyz; @@ -733,7 +731,7 @@ static PJ_LPZ reverse_3d(PJ_XYZ xyz, PJ *P) { // --------------------------------------------------------------------------- -static PJ *destructor(PJ *P, int errlev) { +static PJ *pj_gridshift_destructor(PJ *P, int errlev) { if (nullptr == P) return nullptr; @@ -745,7 +743,7 @@ static PJ *destructor(PJ *P, int errlev) { // --------------------------------------------------------------------------- -static void reassign_context(PJ *P, PJ_CONTEXT *ctx) { +static void pj_gridshift_reassign_context(PJ *P, PJ_CONTEXT *ctx) { auto Q = (struct gridshiftData *)P->opaque; for (auto &grid : Q->m_grids) { grid->reassign_context(ctx); @@ -754,14 +752,14 @@ static void reassign_context(PJ *P, PJ_CONTEXT *ctx) { // --------------------------------------------------------------------------- -PJ *TRANSFORMATION(gridshift, 0) { +PJ *PJ_TRANSFORMATION(gridshift, 0) { auto Q = new gridshiftData; P->opaque = (void *)Q; - P->destructor = destructor; - P->reassign_context = reassign_context; + P->destructor = pj_gridshift_destructor; + P->reassign_context = pj_gridshift_reassign_context; - P->fwd3d = forward_3d; - P->inv3d = reverse_3d; + P->fwd3d = pj_gridshift_forward_3d; + P->inv3d = pj_gridshift_reverse_3d; P->fwd = nullptr; P->inv = nullptr; @@ -770,7 +768,7 @@ PJ *TRANSFORMATION(gridshift, 0) { if (0 == pj_param(P->ctx, P->params, "tgrids").i) { proj_log_error(P, _("+grids parameter missing.")); - return destructor(P, PROJ_ERR_INVALID_OP_MISSING_ARG); + return pj_gridshift_destructor(P, PROJ_ERR_INVALID_OP_MISSING_ARG); } if (P->ctx->defer_grid_opening) { @@ -788,11 +786,11 @@ PJ *TRANSFORMATION(gridshift, 0) { /* Was gridlist compiled properly? */ if (proj_errno(P)) { proj_log_error(P, _("could not find required grid(s).")); - return destructor( + return pj_gridshift_destructor( P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); } if (!Q->checkGridTypes(P)) { - return destructor( + return pj_gridshift_destructor( P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); } @@ -810,7 +808,8 @@ PJ *TRANSFORMATION(gridshift, 0) { Q->m_interpolation = interpolation; } else { proj_log_error(P, _("Unsupported value for +interpolation.")); - return destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); + return pj_gridshift_destructor( + P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); } } diff --git a/src/transformations/helmert.cpp b/src/transformations/helmert.cpp index b83d1f8bd0..f100e06801 100644 --- a/src/transformations/helmert.cpp +++ b/src/transformations/helmert.cpp @@ -47,8 +47,6 @@ Last update: 2018-10-26 * ***********************************************************************/ -#define PJ_LIB_ - #include #include @@ -555,7 +553,7 @@ static PJ *read_convention(PJ *P) { } /***********************************************************************/ -PJ *TRANSFORMATION(helmert, 0) { +PJ *PJ_TRANSFORMATION(helmert, 0) { /***********************************************************************/ struct pj_opaque_helmert *Q; @@ -698,7 +696,7 @@ PJ *TRANSFORMATION(helmert, 0) { } /***********************************************************************/ -PJ *TRANSFORMATION(molobadekas, 0) { +PJ *PJ_TRANSFORMATION(molobadekas, 0) { /***********************************************************************/ struct pj_opaque_helmert *Q; diff --git a/src/transformations/hgridshift.cpp b/src/transformations/hgridshift.cpp index d9b9e92f3d..4be74159fb 100644 --- a/src/transformations/hgridshift.cpp +++ b/src/transformations/hgridshift.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -11,8 +11,8 @@ PROJ_HEAD(hgridshift, "Horizontal grid shift"); -static std::mutex gMutex{}; -static std::set gKnownGrids{}; +static std::mutex gMutexHGridShift{}; +static std::set gKnownGridsHGridShift{}; using namespace NS_PROJ; @@ -25,7 +25,7 @@ struct hgridshiftData { }; } // anonymous namespace -static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P) { +static PJ_XYZ pj_hgridshift_forward_3d(PJ_LPZ lpz, PJ *P) { auto Q = static_cast(P->opaque); PJ_COORD point = {{0, 0, 0, 0}}; point.lpz = lpz; @@ -47,7 +47,7 @@ static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P) { return point.xyz; } -static PJ_LPZ reverse_3d(PJ_XYZ xyz, PJ *P) { +static PJ_LPZ pj_hgridshift_reverse_3d(PJ_XYZ xyz, PJ *P) { auto Q = static_cast(P->opaque); PJ_COORD point = {{0, 0, 0, 0}}; point.xyz = xyz; @@ -69,7 +69,7 @@ static PJ_LPZ reverse_3d(PJ_XYZ xyz, PJ *P) { return point.lpz; } -static void forward_4d(PJ_COORD &coo, PJ *P) { +static void pj_hgridshift_forward_4d(PJ_COORD &coo, PJ *P) { struct hgridshiftData *Q = (struct hgridshiftData *)P->opaque; /* If transformation is not time restricted, we always call it */ @@ -78,7 +78,7 @@ static void forward_4d(PJ_COORD &coo, PJ *P) { // "Overlapping read/write of union is undefined behavior" // Cf // https://github.com/OSGeo/PROJ/pull/3527#pullrequestreview-1233332710 - const auto xyz = forward_3d(coo.lpz, P); + const auto xyz = pj_hgridshift_forward_3d(coo.lpz, P); coo.xyz = xyz; return; } @@ -89,12 +89,12 @@ static void forward_4d(PJ_COORD &coo, PJ *P) { // "Overlapping read/write of union is undefined behavior" // Cf // https://github.com/OSGeo/PROJ/pull/3527#pullrequestreview-1233332710 - const auto xyz = forward_3d(coo.lpz, P); + const auto xyz = pj_hgridshift_forward_3d(coo.lpz, P); coo.xyz = xyz; } } -static void reverse_4d(PJ_COORD &coo, PJ *P) { +static void pj_hgridshift_reverse_4d(PJ_COORD &coo, PJ *P) { struct hgridshiftData *Q = (struct hgridshiftData *)P->opaque; /* If transformation is not time restricted, we always call it */ @@ -103,7 +103,7 @@ static void reverse_4d(PJ_COORD &coo, PJ *P) { // "Overlapping read/write of union is undefined behavior" // Cf // https://github.com/OSGeo/PROJ/pull/3527#pullrequestreview-1233332710 - const auto lpz = reverse_3d(coo.xyz, P); + const auto lpz = pj_hgridshift_reverse_3d(coo.xyz, P); coo.lpz = lpz; return; } @@ -114,12 +114,12 @@ static void reverse_4d(PJ_COORD &coo, PJ *P) { // "Overlapping read/write of union is undefined behavior" // Cf // https://github.com/OSGeo/PROJ/pull/3527#pullrequestreview-1233332710 - const auto lpz = reverse_3d(coo.xyz, P); + const auto lpz = pj_hgridshift_reverse_3d(coo.xyz, P); coo.lpz = lpz; } } -static PJ *destructor(PJ *P, int errlev) { +static PJ *pj_hgridshift_destructor(PJ *P, int errlev) { if (nullptr == P) return nullptr; @@ -129,23 +129,23 @@ static PJ *destructor(PJ *P, int errlev) { return pj_default_destructor(P, errlev); } -static void reassign_context(PJ *P, PJ_CONTEXT *ctx) { +static void pj_hgridshift_reassign_context(PJ *P, PJ_CONTEXT *ctx) { auto Q = (struct hgridshiftData *)P->opaque; for (auto &grid : Q->grids) { grid->reassign_context(ctx); } } -PJ *TRANSFORMATION(hgridshift, 0) { +PJ *PJ_TRANSFORMATION(hgridshift, 0) { auto Q = new hgridshiftData; P->opaque = (void *)Q; - P->destructor = destructor; - P->reassign_context = reassign_context; + P->destructor = pj_hgridshift_destructor; + P->reassign_context = pj_hgridshift_reassign_context; - P->fwd4d = forward_4d; - P->inv4d = reverse_4d; - P->fwd3d = forward_3d; - P->inv3d = reverse_3d; + P->fwd4d = pj_hgridshift_forward_4d; + P->inv4d = pj_hgridshift_reverse_4d; + P->fwd3d = pj_hgridshift_forward_3d; + P->inv3d = pj_hgridshift_reverse_3d; P->fwd = nullptr; P->inv = nullptr; @@ -154,7 +154,7 @@ PJ *TRANSFORMATION(hgridshift, 0) { if (0 == pj_param(P->ctx, P->params, "tgrids").i) { proj_log_error(P, _("+grids parameter missing.")); - return destructor(P, PROJ_ERR_INVALID_OP_MISSING_ARG); + return pj_hgridshift_destructor(P, PROJ_ERR_INVALID_OP_MISSING_ARG); } /* TODO: Refactor into shared function that can be used */ @@ -181,10 +181,10 @@ PJ *TRANSFORMATION(hgridshift, 0) { Q->defer_grid_opening = true; } else { const char *gridnames = pj_param(P->ctx, P->params, "sgrids").s; - gMutex.lock(); - const bool isKnownGrid = - gKnownGrids.find(gridnames) != gKnownGrids.end(); - gMutex.unlock(); + gMutexHGridShift.lock(); + const bool isKnownGrid = gKnownGridsHGridShift.find(gridnames) != + gKnownGridsHGridShift.end(); + gMutexHGridShift.unlock(); if (isKnownGrid) { Q->defer_grid_opening = true; } else { @@ -192,13 +192,13 @@ PJ *TRANSFORMATION(hgridshift, 0) { /* Was gridlist compiled properly? */ if (proj_errno(P)) { proj_log_error(P, _("could not find required grid(s).")); - return destructor( + return pj_hgridshift_destructor( P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); } - gMutex.lock(); - gKnownGrids.insert(gridnames); - gMutex.unlock(); + gMutexHGridShift.lock(); + gKnownGridsHGridShift.insert(gridnames); + gMutexHGridShift.unlock(); } } @@ -206,6 +206,6 @@ PJ *TRANSFORMATION(hgridshift, 0) { } void pj_clear_hgridshift_knowngrids_cache() { - std::lock_guard lock(gMutex); - gKnownGrids.clear(); + std::lock_guard lock(gMutexHGridShift); + gKnownGridsHGridShift.clear(); } diff --git a/src/transformations/horner.cpp b/src/transformations/horner.cpp index d72107c63e..295e12c47d 100644 --- a/src/transformations/horner.cpp +++ b/src/transformations/horner.cpp @@ -76,8 +76,6 @@ Engsager * *****************************************************************************/ -#define PJ_LIB_ - #include #include #include @@ -551,7 +549,7 @@ static int parse_coefs(PJ *P, double *coefs, const char *param, int ncoefs) { } /*********************************************************************/ -PJ *PROJECTION(horner) { +PJ *PJ_PROJECTION(horner) { /*********************************************************************/ int degree = 0; HORNER *Q; diff --git a/src/transformations/molodensky.cpp b/src/transformations/molodensky.cpp index 9f9eb81102..2ad2311d0f 100644 --- a/src/transformations/molodensky.cpp +++ b/src/transformations/molodensky.cpp @@ -42,7 +42,6 @@ * DEALINGS IN THE SOFTWARE. * ***********************************************************************/ -#define PJ_LIB_ #include #include @@ -52,8 +51,8 @@ PROJ_HEAD(molodensky, "Molodensky transform"); -static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P); -static PJ_LPZ reverse_3d(PJ_XYZ xyz, PJ *P); +static PJ_XYZ pj_molodensky_forward_3d(PJ_LPZ lpz, PJ *P); +static PJ_LPZ pj_molodensky_reverse_3d(PJ_XYZ xyz, PJ *P); namespace { // anonymous namespace struct pj_opaque_molodensky { @@ -208,20 +207,20 @@ static PJ_LPZ calc_abridged_params(PJ_LPZ lpz, PJ *P) { return lpz; } -static PJ_XY forward_2d(PJ_LP lp, PJ *P) { +static PJ_XY pj_molodensky_forward_2d(PJ_LP lp, PJ *P) { PJ_COORD point = {{0, 0, 0, 0}}; point.lp = lp; // Assigning in 2 steps avoids cppcheck warning // "Overlapping read/write of union is undefined behavior" // Cf https://github.com/OSGeo/PROJ/pull/3527#pullrequestreview-1233332710 - const auto xyz = forward_3d(point.lpz, P); + const auto xyz = pj_molodensky_forward_3d(point.lpz, P); point.xyz = xyz; return point.xy; } -static PJ_LP reverse_2d(PJ_XY xy, PJ *P) { +static PJ_LP pj_molodensky_reverse_2d(PJ_XY xy, PJ *P) { PJ_COORD point = {{0, 0, 0, 0}}; point.xy = xy; @@ -229,13 +228,13 @@ static PJ_LP reverse_2d(PJ_XY xy, PJ *P) { // Assigning in 2 steps avoids cppcheck warning // "Overlapping read/write of union is undefined behavior" // Cf https://github.com/OSGeo/PROJ/pull/3527#pullrequestreview-1233332710 - const auto lpz = reverse_3d(point.xyz, P); + const auto lpz = pj_molodensky_reverse_3d(point.xyz, P); point.lpz = lpz; return point.lp; } -static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P) { +static PJ_XYZ pj_molodensky_forward_3d(PJ_LPZ lpz, PJ *P) { struct pj_opaque_molodensky *Q = (struct pj_opaque_molodensky *)P->opaque; PJ_COORD point = {{0, 0, 0, 0}}; @@ -260,15 +259,15 @@ static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P) { return point.xyz; } -static void forward_4d(PJ_COORD &obs, PJ *P) { +static void pj_molodensky_forward_4d(PJ_COORD &obs, PJ *P) { // Assigning in 2 steps avoids cppcheck warning // "Overlapping read/write of union is undefined behavior" // Cf https://github.com/OSGeo/PROJ/pull/3527#pullrequestreview-1233332710 - const auto xyz = forward_3d(obs.lpz, P); + const auto xyz = pj_molodensky_forward_3d(obs.lpz, P); obs.xyz = xyz; } -static PJ_LPZ reverse_3d(PJ_XYZ xyz, PJ *P) { +static PJ_LPZ pj_molodensky_reverse_3d(PJ_XYZ xyz, PJ *P) { struct pj_opaque_molodensky *Q = (struct pj_opaque_molodensky *)P->opaque; PJ_COORD point = {{0, 0, 0, 0}}; PJ_LPZ lpz; @@ -293,27 +292,27 @@ static PJ_LPZ reverse_3d(PJ_XYZ xyz, PJ *P) { return point.lpz; } -static void reverse_4d(PJ_COORD &obs, PJ *P) { +static void pj_molodensky_reverse_4d(PJ_COORD &obs, PJ *P) { // Assigning in 2 steps avoids cppcheck warning // "Overlapping read/write of union is undefined behavior" // Cf https://github.com/OSGeo/PROJ/pull/3527#pullrequestreview-1233332710 - const auto lpz = reverse_3d(obs.xyz, P); + const auto lpz = pj_molodensky_reverse_3d(obs.xyz, P); obs.lpz = lpz; } -PJ *TRANSFORMATION(molodensky, 1) { +PJ *PJ_TRANSFORMATION(molodensky, 1) { struct pj_opaque_molodensky *Q = static_cast( calloc(1, sizeof(struct pj_opaque_molodensky))); if (nullptr == Q) return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = (void *)Q; - P->fwd4d = forward_4d; - P->inv4d = reverse_4d; - P->fwd3d = forward_3d; - P->inv3d = reverse_3d; - P->fwd = forward_2d; - P->inv = reverse_2d; + P->fwd4d = pj_molodensky_forward_4d; + P->inv4d = pj_molodensky_reverse_4d; + P->fwd3d = pj_molodensky_forward_3d; + P->inv3d = pj_molodensky_reverse_3d; + P->fwd = pj_molodensky_forward_2d; + P->inv = pj_molodensky_reverse_2d; P->left = PJ_IO_UNITS_RADIANS; P->right = PJ_IO_UNITS_RADIANS; diff --git a/src/transformations/tinshift.cpp b/src/transformations/tinshift.cpp index bd3cce09a0..7b044b20bf 100644 --- a/src/transformations/tinshift.cpp +++ b/src/transformations/tinshift.cpp @@ -25,7 +25,6 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ -#define PJ_LIB_ #define PROJ_COMPILATION #include "tinshift.hpp" @@ -49,7 +48,7 @@ struct tinshiftData { } // namespace -static PJ *destructor(PJ *P, int errlev) { +static PJ *pj_tinshift_destructor(PJ *P, int errlev) { if (nullptr == P) return nullptr; @@ -78,18 +77,19 @@ static void tinshift_reverse_4d(PJ_COORD &coo, PJ *P) { } } -PJ *TRANSFORMATION(tinshift, 1) { +PJ *PJ_TRANSFORMATION(tinshift, 1) { const char *filename = pj_param(P->ctx, P->params, "sfile").s; if (!filename) { proj_log_error(P, _("+file= should be specified.")); - return destructor(P, PROJ_ERR_INVALID_OP_MISSING_ARG); + return pj_tinshift_destructor(P, PROJ_ERR_INVALID_OP_MISSING_ARG); } auto file = NS_PROJ::FileManager::open_resource_file(P->ctx, filename); if (nullptr == file) { proj_log_error(P, _("Cannot open %s"), filename); - return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); + return pj_tinshift_destructor( + P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); } file->seek(0, SEEK_END); unsigned long long size = file->tell(); @@ -98,7 +98,8 @@ PJ *TRANSFORMATION(tinshift, 1) { // large for any valid use ! if (size > 100 * 1024 * 1024) { proj_log_error(P, _("File %s too large"), filename); - return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); + return pj_tinshift_destructor( + P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); } file->seek(0); std::string jsonStr; @@ -106,25 +107,26 @@ PJ *TRANSFORMATION(tinshift, 1) { jsonStr.resize(static_cast(size)); } catch (const std::bad_alloc &) { proj_log_error(P, _("Cannot read %s. Not enough memory"), filename); - return destructor(P, PROJ_ERR_OTHER); + return pj_tinshift_destructor(P, PROJ_ERR_OTHER); } if (file->read(&jsonStr[0], jsonStr.size()) != jsonStr.size()) { proj_log_error(P, _("Cannot read %s"), filename); - return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); + return pj_tinshift_destructor( + P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); } auto Q = new tinshiftData(); P->opaque = (void *)Q; - P->destructor = destructor; + P->destructor = pj_tinshift_destructor; try { Q->evaluator.reset(new Evaluator(TINShiftFile::parse(jsonStr))); } catch (const std::exception &e) { proj_log_error(P, _("invalid model: %s"), e.what()); - return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); + return pj_tinshift_destructor( + P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); } - P->destructor = destructor; P->fwd4d = tinshift_forward_4d; P->inv4d = tinshift_reverse_4d; P->left = PJ_IO_UNITS_WHATEVER; diff --git a/src/transformations/vertoffset.cpp b/src/transformations/vertoffset.cpp index fe4b235f4c..55bb27dc98 100644 --- a/src/transformations/vertoffset.cpp +++ b/src/transformations/vertoffset.cpp @@ -20,7 +20,6 @@ * DEALINGS IN THE SOFTWARE. * ***********************************************************************/ -#define PJ_LIB_ #include #include @@ -77,7 +76,7 @@ static PJ_LPZ reverse_3d(PJ_XYZ xyz, PJ *P) { /* Arcsecond to radians */ #define ARCSEC_TO_RAD (DEG_TO_RAD / 3600.0) -PJ *TRANSFORMATION(vertoffset, 1) { +PJ *PJ_TRANSFORMATION(vertoffset, 1) { struct pj_opaque_vertoffset *Q = static_cast( calloc(1, sizeof(struct pj_opaque_vertoffset))); if (nullptr == Q) diff --git a/src/transformations/vgridshift.cpp b/src/transformations/vgridshift.cpp index 8b62bc0a69..6460bfd644 100644 --- a/src/transformations/vgridshift.cpp +++ b/src/transformations/vgridshift.cpp @@ -1,4 +1,4 @@ -#define PJ_LIB_ + #include #include @@ -11,8 +11,8 @@ PROJ_HEAD(vgridshift, "Vertical grid shift"); -static std::mutex gMutex{}; -static std::set gKnownGrids{}; +static std::mutex gMutexVGridShift{}; +static std::set gKnownGridsVGridShift{}; using namespace NS_PROJ; @@ -51,7 +51,7 @@ static void deal_with_vertcon_gtx_hack(PJ *P) { } } -static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P) { +static PJ_XYZ pj_vgridshift_forward_3d(PJ_LPZ lpz, PJ *P) { struct vgridshiftData *Q = (struct vgridshiftData *)P->opaque; PJ_COORD point = {{0, 0, 0, 0}}; point.lpz = lpz; @@ -75,7 +75,7 @@ static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P) { return point.xyz; } -static PJ_LPZ reverse_3d(PJ_XYZ xyz, PJ *P) { +static PJ_LPZ pj_vgridshift_reverse_3d(PJ_XYZ xyz, PJ *P) { struct vgridshiftData *Q = (struct vgridshiftData *)P->opaque; PJ_COORD point = {{0, 0, 0, 0}}; point.xyz = xyz; @@ -99,7 +99,7 @@ static PJ_LPZ reverse_3d(PJ_XYZ xyz, PJ *P) { return point.lpz; } -static void forward_4d(PJ_COORD &coo, PJ *P) { +static void pj_vgridshift_forward_4d(PJ_COORD &coo, PJ *P) { struct vgridshiftData *Q = (struct vgridshiftData *)P->opaque; /* If transformation is not time restricted, we always call it */ @@ -108,7 +108,7 @@ static void forward_4d(PJ_COORD &coo, PJ *P) { // "Overlapping read/write of union is undefined behavior" // Cf // https://github.com/OSGeo/PROJ/pull/3527#pullrequestreview-1233332710 - const auto xyz = forward_3d(coo.lpz, P); + const auto xyz = pj_vgridshift_forward_3d(coo.lpz, P); coo.xyz = xyz; return; } @@ -119,12 +119,12 @@ static void forward_4d(PJ_COORD &coo, PJ *P) { // "Overlapping read/write of union is undefined behavior" // Cf // https://github.com/OSGeo/PROJ/pull/3527#pullrequestreview-1233332710 - const auto xyz = forward_3d(coo.lpz, P); + const auto xyz = pj_vgridshift_forward_3d(coo.lpz, P); coo.xyz = xyz; } } -static void reverse_4d(PJ_COORD &coo, PJ *P) { +static void pj_vgridshift_reverse_4d(PJ_COORD &coo, PJ *P) { struct vgridshiftData *Q = (struct vgridshiftData *)P->opaque; /* If transformation is not time restricted, we always call it */ @@ -133,7 +133,7 @@ static void reverse_4d(PJ_COORD &coo, PJ *P) { // "Overlapping read/write of union is undefined behavior" // Cf // https://github.com/OSGeo/PROJ/pull/3527#pullrequestreview-1233332710 - const auto lpz = reverse_3d(coo.xyz, P); + const auto lpz = pj_vgridshift_reverse_3d(coo.xyz, P); coo.lpz = lpz; return; } @@ -144,12 +144,12 @@ static void reverse_4d(PJ_COORD &coo, PJ *P) { // "Overlapping read/write of union is undefined behavior" // Cf // https://github.com/OSGeo/PROJ/pull/3527#pullrequestreview-1233332710 - const auto lpz = reverse_3d(coo.xyz, P); + const auto lpz = pj_vgridshift_reverse_3d(coo.xyz, P); coo.lpz = lpz; } } -static PJ *destructor(PJ *P, int errlev) { +static PJ *pj_vgridshift_destructor(PJ *P, int errlev) { if (nullptr == P) return nullptr; @@ -159,22 +159,22 @@ static PJ *destructor(PJ *P, int errlev) { return pj_default_destructor(P, errlev); } -static void reassign_context(PJ *P, PJ_CONTEXT *ctx) { +static void pj_vgridshift_reassign_context(PJ *P, PJ_CONTEXT *ctx) { auto Q = (struct vgridshiftData *)P->opaque; for (auto &grid : Q->grids) { grid->reassign_context(ctx); } } -PJ *TRANSFORMATION(vgridshift, 0) { +PJ *PJ_TRANSFORMATION(vgridshift, 0) { auto Q = new vgridshiftData; P->opaque = (void *)Q; - P->destructor = destructor; - P->reassign_context = reassign_context; + P->destructor = pj_vgridshift_destructor; + P->reassign_context = pj_vgridshift_reassign_context; if (!pj_param(P->ctx, P->params, "tgrids").i) { proj_log_error(P, _("+grids parameter missing.")); - return destructor(P, PROJ_ERR_INVALID_OP_MISSING_ARG); + return pj_vgridshift_destructor(P, PROJ_ERR_INVALID_OP_MISSING_ARG); } /* TODO: Refactor into shared function that can be used */ @@ -207,10 +207,10 @@ PJ *TRANSFORMATION(vgridshift, 0) { Q->defer_grid_opening = true; } else { const char *gridnames = pj_param(P->ctx, P->params, "sgrids").s; - gMutex.lock(); - const bool isKnownGrid = - gKnownGrids.find(gridnames) != gKnownGrids.end(); - gMutex.unlock(); + gMutexVGridShift.lock(); + const bool isKnownGrid = gKnownGridsVGridShift.find(gridnames) != + gKnownGridsVGridShift.end(); + gMutexVGridShift.unlock(); if (isKnownGrid) { Q->defer_grid_opening = true; @@ -222,20 +222,20 @@ PJ *TRANSFORMATION(vgridshift, 0) { /* Was gridlist compiled properly? */ if (proj_errno(P)) { proj_log_error(P, _("could not find required grid(s).")); - return destructor( + return pj_vgridshift_destructor( P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); } - gMutex.lock(); - gKnownGrids.insert(gridnames); - gMutex.unlock(); + gMutexVGridShift.lock(); + gKnownGridsVGridShift.insert(gridnames); + gMutexVGridShift.unlock(); } } - P->fwd4d = forward_4d; - P->inv4d = reverse_4d; - P->fwd3d = forward_3d; - P->inv3d = reverse_3d; + P->fwd4d = pj_vgridshift_forward_4d; + P->inv4d = pj_vgridshift_reverse_4d; + P->fwd3d = pj_vgridshift_forward_3d; + P->inv3d = pj_vgridshift_reverse_3d; P->fwd = nullptr; P->inv = nullptr; @@ -246,6 +246,6 @@ PJ *TRANSFORMATION(vgridshift, 0) { } void pj_clear_vgridshift_knowngrids_cache() { - std::lock_guard lock(gMutex); - gKnownGrids.clear(); + std::lock_guard lock(gMutexVGridShift); + gKnownGridsVGridShift.clear(); } diff --git a/src/transformations/xyzgridshift.cpp b/src/transformations/xyzgridshift.cpp index 12ecf5e58a..68281d1e7c 100644 --- a/src/transformations/xyzgridshift.cpp +++ b/src/transformations/xyzgridshift.cpp @@ -25,8 +25,6 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ -#define PJ_LIB_ - #include #include #include @@ -168,7 +166,7 @@ static PJ_COORD direct_adjustment(PJ *P, xyzgridshiftData *Q, PJ_COORD point, // --------------------------------------------------------------------------- -static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P) { +static PJ_XYZ pj_xyzgridshift_forward_3d(PJ_LPZ lpz, PJ *P) { auto Q = static_cast(P->opaque); PJ_COORD point = {{0, 0, 0, 0}}; point.lpz = lpz; @@ -182,7 +180,7 @@ static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P) { return point.xyz; } -static PJ_LPZ reverse_3d(PJ_XYZ xyz, PJ *P) { +static PJ_LPZ pj_xyzgridshift_reverse_3d(PJ_XYZ xyz, PJ *P) { auto Q = static_cast(P->opaque); PJ_COORD point = {{0, 0, 0, 0}}; point.xyz = xyz; @@ -196,7 +194,7 @@ static PJ_LPZ reverse_3d(PJ_XYZ xyz, PJ *P) { return point.lpz; } -static PJ *destructor(PJ *P, int errlev) { +static PJ *pj_xyzgridshift_destructor(PJ *P, int errlev) { if (nullptr == P) return nullptr; @@ -211,23 +209,23 @@ static PJ *destructor(PJ *P, int errlev) { return pj_default_destructor(P, errlev); } -static void reassign_context(PJ *P, PJ_CONTEXT *ctx) { +static void pj_xyzgridshift_reassign_context(PJ *P, PJ_CONTEXT *ctx) { auto Q = (struct xyzgridshiftData *)P->opaque; for (auto &grid : Q->grids) { grid->reassign_context(ctx); } } -PJ *TRANSFORMATION(xyzgridshift, 0) { +PJ *PJ_TRANSFORMATION(xyzgridshift, 0) { auto Q = new xyzgridshiftData; P->opaque = (void *)Q; - P->destructor = destructor; - P->reassign_context = reassign_context; + P->destructor = pj_xyzgridshift_destructor; + P->reassign_context = pj_xyzgridshift_reassign_context; P->fwd4d = nullptr; P->inv4d = nullptr; - P->fwd3d = forward_3d; - P->inv3d = reverse_3d; + P->fwd3d = pj_xyzgridshift_forward_3d; + P->inv3d = pj_xyzgridshift_reverse_3d; P->fwd = nullptr; P->inv = nullptr; @@ -237,7 +235,7 @@ PJ *TRANSFORMATION(xyzgridshift, 0) { // Pass a dummy ellipsoid definition that will be overridden just afterwards Q->cart = proj_create(P->ctx, "+proj=cart +a=1"); if (Q->cart == nullptr) - return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); + return pj_xyzgridshift_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); /* inherit ellipsoid definition from P to Q->cart */ pj_inherit_ellipsoid_def(P, Q->cart); @@ -253,13 +251,14 @@ PJ *TRANSFORMATION(xyzgridshift, 0) { Q->grid_ref_is_input = false; } else { proj_log_error(P, _("unusupported value for grid_ref")); - return destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); + return pj_xyzgridshift_destructor( + P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); } } if (0 == pj_param(P->ctx, P->params, "tgrids").i) { proj_log_error(P, _("+grids parameter missing.")); - return destructor(P, PROJ_ERR_INVALID_OP_MISSING_ARG); + return pj_xyzgridshift_destructor(P, PROJ_ERR_INVALID_OP_MISSING_ARG); } /* multiplier for delta x,y,z */ @@ -274,7 +273,8 @@ PJ *TRANSFORMATION(xyzgridshift, 0) { /* Was gridlist compiled properly? */ if (proj_errno(P)) { proj_log_error(P, _("could not find required grid(s).")); - return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); + return pj_xyzgridshift_destructor( + P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID); } } diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index e58b11931a..1d2b197704 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -133,7 +133,7 @@ else() PROPERTY ENVIRONMENT ${PROJ_TEST_ENVIRONMENT}) endif() -add_executable(proj_test_cpp_api +set(PROJ_TEST_CPP_API_SOURCES main.cpp test_util.cpp test_common.cpp @@ -147,6 +147,11 @@ add_executable(proj_test_cpp_api test_factory.cpp test_c_api.cpp test_grids.cpp) +add_executable(proj_test_cpp_api ${PROJ_TEST_CPP_API_SOURCES}) +if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16) + set_property(SOURCE ${PROJ_TEST_CPP_API_SOURCES} PROPERTY SKIP_UNITY_BUILD_INCLUSION ON) +endif () + target_link_libraries(proj_test_cpp_api PRIVATE GTest::gtest PRIVATE ${PROJ_LIBRARIES} @@ -157,7 +162,7 @@ set_property(TEST proj_test_cpp_api if(TIFF_ENABLED) target_compile_definitions(proj_test_cpp_api PRIVATE -DTIFF_ENABLED) endif() - + add_executable(gie_self_tests main.cpp gie_self_tests.cpp) diff --git a/test/unit/test_primitives.hpp b/test/unit/test_primitives.hpp index 45c0df1cd7..49ee83a6ac 100644 --- a/test/unit/test_primitives.hpp +++ b/test/unit/test_primitives.hpp @@ -26,6 +26,9 @@ * DEALINGS IN THE SOFTWARE. ****************************************************************************/ +#ifndef TEST_PRIMITIVES_HPP_INCLUDED +#define TEST_PRIMITIVES_HPP_INCLUDED + #include "gtest_include.h" #ifndef FROM_PROJ_CPP @@ -99,3 +102,5 @@ static ::testing::AssertionResult ComparePROJString(const char *m_expr, << m_expr << " and " << n_expr << " (" << m << " and " << n << ") are different"; } + +#endif /* TEST_PRIMITIVES_HPP_INCLUDED */ diff --git a/travis/install.sh b/travis/install.sh index 711f2db29b..e61bb7d17a 100755 --- a/travis/install.sh +++ b/travis/install.sh @@ -55,6 +55,7 @@ mkdir shared_build cd shared_build cmake \ -D CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \ + -DCMAKE_UNITY_BUILD=ON \ -D USE_CCACHE=${USE_CCACHE} \ ${PROJ_CMAKE_BUILD_OPTIONS:-} \ -D PROJ_DB_CACHE_DIR=$HOME/.ccache \