From 23ade0a2173b6de976abce99d5e69d9beee25778 Mon Sep 17 00:00:00 2001 From: twsearle <14909402+twsearle@users.noreply.github.com> Date: Mon, 24 Jun 2024 12:28:56 +0100 Subject: [PATCH] Wrap out-of-bounds source cells into the domain Change originally proposed by s-good, twsearle is just here for the PR admin. Co-authored-by: s-good --- .../unstructured/UnstructuredBilinearLonLat.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/atlas/interpolation/method/unstructured/UnstructuredBilinearLonLat.cc b/src/atlas/interpolation/method/unstructured/UnstructuredBilinearLonLat.cc index 62276db31..840c851a8 100644 --- a/src/atlas/interpolation/method/unstructured/UnstructuredBilinearLonLat.cc +++ b/src/atlas/interpolation/method/unstructured/UnstructuredBilinearLonLat.cc @@ -419,15 +419,22 @@ Method::Triplets UnstructuredBilinearLonLat::projectPointToElements(size_t ip, c } // shift cells on the east-west periodic boundary from the east to the west // so that the quad surrounds a point with output longitude in [0,360) - if (lons[0] > lons[1] || lons[3] > lons[2]) { - lons[0] -= 360; - lons[3] -= 360; + double minlon = std::numeric_limits::max(); + for ( int i = 0; i < 4; i++ ) { + minlon = std::min( minlon, lons[i] ); + } + for ( int i = 0; i < 4; i++ ) { + if ( (lons[i] - minlon) > 180 ) { + lons[i] -= 360; + } } element::Quad2D quad( PointLonLat{lons[0], (*ilonlat_)(idx[0], LAT)}, PointLonLat{lons[1], (*ilonlat_)(idx[1], LAT)}, PointLonLat{lons[2], (*ilonlat_)(idx[2], LAT)}, PointLonLat{lons[3], (*ilonlat_)(idx[3], LAT)}); + ATLAS_ASSERT( quad.validate() ); + if (itc == elems.begin()) { inv_dist_weight_quad(quad, o_loc, inv_dist_w); }