Skip to content

Commit

Permalink
Improve a bit performance of +proj=axisswap +order=2,1
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Dec 11, 2022
1 parent c1ed706 commit c2a5164
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/conversions/axisswap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ It is only necessary to specify the axes that are affected by the swap
#include <stdlib.h>
#include <string.h>

#include <algorithm>

#include "proj.h"
#include "proj_internal.h"

Expand All @@ -75,20 +77,14 @@ static int sign(int x) {

static PJ_XY forward_2d(PJ_LP lp, PJ *P) {
struct pj_opaque *Q = (struct pj_opaque *) P->opaque;
unsigned int i;
PJ_COORD out, in;

in.v[0] = lp.lam;
in.v[1] = lp.phi;
out = proj_coord_error();

for (i=0; i<2; i++)
out.v[i] = in.v[Q->axis[i]] * Q->sign[i];
PJ_XY xy;

return out.xy;
double in[2] = {lp.lam, lp.phi};
xy.x = in[Q->axis[0]] * Q->sign[0];
xy.y = in[Q->axis[1]] * Q->sign[1];
return xy;
}


static PJ_LP reverse_2d(PJ_XY xy, PJ *P) {
struct pj_opaque *Q = (struct pj_opaque *) P->opaque;
unsigned int i;
Expand All @@ -104,7 +100,6 @@ 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;
unsigned int i;
Expand Down Expand Up @@ -137,6 +132,10 @@ static PJ_LPZ reverse_3d(PJ_XYZ xyz, PJ *P) {
return out.lpz;
}

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;
Expand Down Expand Up @@ -273,9 +272,18 @@ PJ *CONVERSION(axisswap,0) {
P->fwd3d = forward_3d;
P->inv3d = reverse_3d;
}
if (n == 2 && Q->axis[0] < 2 && Q->axis[1] < 2) {
P->fwd = forward_2d;
P->inv = reverse_2d;
if (n == 2) {
if( Q->axis[0] == 1 && Q->sign[0] == 1 &&
Q->axis[1] == 0 && Q->sign[1] == 1 )
{
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;
}
}


Expand Down

0 comments on commit c2a5164

Please sign in to comment.