Skip to content

Commit

Permalink
Enable latitude normalisation in KDTree coordinate transform (#140)
Browse files Browse the repository at this point in the history
* Enable latitude normalisation in coordinate transform

* Add eckit compatibility guard

---------

Co-authored-by: Willem Deconinck <[email protected]>
  • Loading branch information
fmahebert and wdeconinck authored Jun 6, 2023
1 parent a79eed1 commit 0e00ad9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
17 changes: 17 additions & 0 deletions src/atlas/util/Geometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions src/atlas/util/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }
Expand Down

0 comments on commit 0e00ad9

Please sign in to comment.