MCPcopy Create free account
hub / github.com/OSGeo/PROJ / pj_hgrid_apply_internal

Function pj_hgrid_apply_internal

src/grids.cpp:3401–3504  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3399#define TOL 1e-12
3400
3401static PJ_LP pj_hgrid_apply_internal(PJ_CONTEXT *ctx, PJ_LP in,
3402 PJ_DIRECTION direction,
3403 const HorizontalShiftGrid *grid,
3404 HorizontalShiftGridSet *gridset,
3405 const ListOfHGrids &grids,
3406 bool &shouldRetry) {
3407 PJ_LP t, tb, del, dif;
3408 int i = MAX_ITERATIONS;
3409 const double toltol = TOL * TOL;
3410
3411 shouldRetry = false;
3412 if (in.lam == HUGE_VAL)
3413 return in;
3414
3415 /* normalize input to ll origin */
3416 tb = in;
3417 const auto *extent = &(grid->extentAndRes());
3418 const double epsilon =
3419 (extent->resX + extent->resY) * REL_TOLERANCE_HGRIDSHIFT;
3420 tb.lam -= extent->west;
3421 if (tb.lam + epsilon < 0)
3422 tb.lam += 2 * M_PI;
3423 else if (tb.lam - epsilon > extent->east - extent->west)
3424 tb.lam -= 2 * M_PI;
3425 tb.phi -= extent->south;
3426
3427 t = pj_hgrid_interpolate(tb, grid, true);
3428 if (grid->hasChanged()) {
3429 shouldRetry = gridset->reopen(ctx);
3430 return t;
3431 }
3432 if (t.lam == HUGE_VAL)
3433 return t;
3434
3435 if (direction == PJ_FWD) {
3436 in.lam += t.lam;
3437 in.phi += t.phi;
3438 return in;
3439 }
3440
3441 t.lam = tb.lam - t.lam;
3442 t.phi = tb.phi - t.phi;
3443
3444 do {
3445 del = pj_hgrid_interpolate(t, grid, true);
3446 if (grid->hasChanged()) {
3447 shouldRetry = gridset->reopen(ctx);
3448 return t;
3449 }
3450
3451 /* We can possibly go outside of the initial guessed grid, so try */
3452 /* to fetch a new grid into which iterate... */
3453 if (del.lam == HUGE_VAL) {
3454 PJ_LP lp;
3455 lp.lam = t.lam + extent->west;
3456 lp.phi = t.phi + extent->south;
3457 auto newGrid = findGrid(grids, lp, gridset);
3458 if (newGrid == nullptr || newGrid == grid || newGrid->isNullGrid())

Callers 1

pj_hgrid_applyFunction · 0.85

Calls 9

pj_hgrid_interpolateFunction · 0.85
findGridFunction · 0.85
pj_logFunction · 0.85
proj_context_errno_setFunction · 0.85
adjlonFunction · 0.85
hasChangedMethod · 0.45
reopenMethod · 0.45
isNullGridMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected