From 4e36fd85b9bd9f80c83d7f262c5a8fb3ae44cde2 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 21 Jun 2018 22:43:14 +0200 Subject: Add support for deg, rad and grad in unitconvert (fixes #1052), and document that it supports numeric factors (refs #1053) --- src/pj_transform.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'src/pj_transform.c') diff --git a/src/pj_transform.c b/src/pj_transform.c index e67cc525..b459e4a2 100644 --- a/src/pj_transform.c +++ b/src/pj_transform.c @@ -69,8 +69,8 @@ static int adjust_axis( projCtx ctx, const char *axis, int denormalize_flag, #define M_BF (defn->datum_params[6]) /* -** This table is intended to indicate for any given error code in -** the range 0 to -56, whether that error will occur for all locations (ie. +** This table is intended to indicate for any given error code +** whether that error will occur for all locations (ie. ** it is a problem with the coordinate system as a whole) in which case the ** value would be 0, or if the problem is with the point being transformed ** in which case the value is 1. @@ -98,6 +98,19 @@ static const int transient_error[60] = { /* 50 to 59 */ 1, 0, 1, 0, 1, 1, 1, 1, 0, 0 }; +/* -------------------------------------------------------------------- */ +/* Read transient_error[] in a safe way. */ +/* -------------------------------------------------------------------- */ +static int get_transient_error_value(int pos_index) +{ + const int array_size = + (int)(sizeof(transient_error) / sizeof(transient_error[0])); + if( pos_index < 0 || pos_index >= array_size ) { + return 0; + } + return transient_error[pos_index]; +} + /* -------------------------------------------------------------------- */ /* Transform unusual input coordinate axis orientation to */ @@ -211,7 +224,7 @@ static int geographic_to_projected (PJ *P, long n, int dist, double *x, double * && P->ctx->last_errno != ERANGE) && (P->ctx->last_errno > 0 || P->ctx->last_errno < -44 || n == 1 - || transient_error[-P->ctx->last_errno] == 0 ) ) + || get_transient_error_value(-P->ctx->last_errno) == 0 ) ) { return P->ctx->last_errno; } @@ -249,7 +262,7 @@ static int geographic_to_projected (PJ *P, long n, int dist, double *x, double * && P->ctx->last_errno != ERANGE) && (P->ctx->last_errno > 0 || P->ctx->last_errno < -44 || n == 1 - || transient_error[-P->ctx->last_errno] == 0 ) ) + || get_transient_error_value(-P->ctx->last_errno) == 0 ) ) { return P->ctx->last_errno; } @@ -319,7 +332,7 @@ static int projected_to_geographic (PJ *P, long n, int dist, double *x, double * && P->ctx->last_errno != ERANGE) && (P->ctx->last_errno > 0 || P->ctx->last_errno < -44 || n == 1 - || transient_error[-P->ctx->last_errno] == 0 ) ) + || get_transient_error_value(-P->ctx->last_errno) == 0 ) ) { return P->ctx->last_errno; } @@ -358,7 +371,7 @@ static int projected_to_geographic (PJ *P, long n, int dist, double *x, double * && P->ctx->last_errno != ERANGE) && (P->ctx->last_errno > 0 || P->ctx->last_errno < -44 || n == 1 - || transient_error[-P->ctx->last_errno] == 0 ) ) + || get_transient_error_value(-P->ctx->last_errno) == 0 ) ) { return P->ctx->last_errno; } @@ -850,7 +863,7 @@ int pj_datum_transform( PJ *src, PJ *dst, z_is_temp = TRUE; } -#define CHECK_RETURN(defn) {if( defn->ctx->last_errno != 0 && (defn->ctx->last_errno > 0 || transient_error[-defn->ctx->last_errno] == 0) ) { if( z_is_temp ) pj_dalloc(z); return defn->ctx->last_errno; }} +#define CHECK_RETURN(defn) {if( defn->ctx->last_errno != 0 && (defn->ctx->last_errno > 0 || get_transient_error_value(-defn->ctx->last_errno) == 0) ) { if( z_is_temp ) pj_dalloc(z); return defn->ctx->last_errno; }} /* -------------------------------------------------------------------- */ /* If this datum requires grid shifts, then apply it to geodetic */ -- cgit v1.2.3