From 0e00ad91bd8fdaaf1268619260c8488fa2626381 Mon Sep 17 00:00:00 2001 From: Francois Hebert Date: Tue, 6 Jun 2023 06:49:53 -0600 Subject: [PATCH] Enable latitude normalisation in KDTree coordinate transform (#140) * Enable latitude normalisation in coordinate transform * Add eckit compatibility guard --------- Co-authored-by: Willem Deconinck --- src/atlas/util/Geometry.cc | 17 +++++++++++++++++ src/atlas/util/Geometry.h | 8 ++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/atlas/util/Geometry.cc b/src/atlas/util/Geometry.cc index 4196e5e02..7d8e07797 100644 --- a/src/atlas/util/Geometry.cc +++ b/src/atlas/util/Geometry.cc @@ -11,11 +11,28 @@ #include "eckit/geometry/Point2.h" #include "eckit/geometry/Point3.h" +#include "atlas/library/config.h" #include "atlas/runtime/Exception.h" #include "atlas/util/Geometry.h" namespace atlas { +namespace geometry { +namespace detail { +void GeometrySphere::lonlat2xyz(const Point2& lonlat, Point3& xyz) const { +#if ATLAS_ECKIT_VERSION_AT_LEAST(1, 24, 0) + Sphere::convertSphericalToCartesian(radius_, lonlat, xyz, 0., true); +#else + Sphere::convertSphericalToCartesian(radius_, lonlat, xyz); +#endif +} +void GeometrySphere::xyz2lonlat(const Point3& xyz, Point2& lonlat) const { + Sphere::convertCartesianToSpherical(radius_, xyz, lonlat); +} + +} // namespace detail +} // namespace geometry + extern "C" { // ------------------------------------------------------------------ // C wrapper interfaces to C++ routines diff --git a/src/atlas/util/Geometry.h b/src/atlas/util/Geometry.h index 2566ee685..3880645e8 100644 --- a/src/atlas/util/Geometry.h +++ b/src/atlas/util/Geometry.h @@ -71,12 +71,8 @@ class GeometrySphere : public GeometryBase { public: GeometrySphere(double radius): radius_(radius) {} - void lonlat2xyz(const Point2& lonlat, Point3& xyz) const override { - Sphere::convertSphericalToCartesian(radius_, lonlat, xyz); - } - void xyz2lonlat(const Point3& xyz, Point2& lonlat) const override { - Sphere::convertCartesianToSpherical(radius_, xyz, lonlat); - } + void lonlat2xyz(const Point2& lonlat, Point3& xyz) const override; + void xyz2lonlat(const Point3& xyz, Point2& lonlat) const override; double distance(const Point2& p1, const Point2& p2) const override { return Sphere::distance(radius_, p1, p2); } double distance(const Point3& p1, const Point3& p2) const override { return Sphere::distance(radius_, p1, p2); } double radius() const override { return radius_; }