aboutsummaryrefslogtreecommitdiff
path: root/src/4D_api.cpp
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2021-04-03 17:52:58 +0200
committerEven Rouault <even.rouault@spatialys.com>2021-04-03 17:52:58 +0200
commit722cf8840c390fa9c5bb34d6a882cf072dd77044 (patch)
treedd6ac0f5a211a88025a5adc245490d4dcd611dd5 /src/4D_api.cpp
parentd6d46c210286006059f8bb64f62523f3805cf262 (diff)
downloadPROJ-722cf8840c390fa9c5bb34d6a882cf072dd77044.tar.gz
PROJ-722cf8840c390fa9c5bb34d6a882cf072dd77044.zip
reproject_bbox(): reduce number of magic values
Diffstat (limited to 'src/4D_api.cpp')
-rw-r--r--src/4D_api.cpp30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/4D_api.cpp b/src/4D_api.cpp
index 4ef9b616..c7725d3a 100644
--- a/src/4D_api.cpp
+++ b/src/4D_api.cpp
@@ -993,25 +993,31 @@ static void reproject_bbox(PJ* pjGeogToCrs,
maxx = -maxx;
maxy = -maxy;
- std::vector<double> x(21 * 4), y(21 * 4);
- for( int j = 0; j <= 20; j++ )
+ constexpr int N_STEPS = 20;
+ constexpr int N_STEPS_P1 = N_STEPS+1;
+ constexpr int XY_SIZE = N_STEPS_P1 * 4;
+ std::vector<double> x(XY_SIZE);
+ std::vector<double> y(XY_SIZE);
+ const double step_lon = (east_lon - west_lon) / N_STEPS;
+ const double step_lat = (north_lat - south_lat) / N_STEPS;
+ for( int j = 0; j <= N_STEPS; j++ )
{
- x[j] = west_lon + j * (east_lon - west_lon) / 20;
+ x[j] = west_lon + j * step_lon;
y[j] = south_lat;
- x[21+j] = west_lon + j * (east_lon - west_lon) / 20;
- y[21+j] = north_lat;
- x[21*2+j] = west_lon;
- y[21*2+j] = south_lat + j * (north_lat - south_lat) / 20;
- x[21*3+j] = east_lon;
- y[21*3+j] = south_lat + j * (north_lat - south_lat) / 20;
+ x[N_STEPS_P1+j] = x[j];
+ y[N_STEPS_P1+j] = north_lat;
+ x[N_STEPS_P1*2+j] = west_lon;
+ y[N_STEPS_P1*2+j] = south_lat + j * step_lat;
+ x[N_STEPS_P1*3+j] = east_lon;
+ y[N_STEPS_P1*3+j] = y[N_STEPS_P1*2+j];
}
proj_trans_generic (
pjGeogToCrs, PJ_FWD,
- &x[0], sizeof(double), 21 * 4,
- &y[0], sizeof(double), 21 * 4,
+ &x[0], sizeof(double), XY_SIZE,
+ &y[0], sizeof(double), XY_SIZE,
nullptr, 0, 0,
nullptr, 0, 0);
- for( int j = 0; j < 21 * 4; j++ )
+ for( int j = 0; j < XY_SIZE; j++ )
{
if( x[j] != HUGE_VAL && y[j] != HUGE_VAL )
{