Skip to content

Commit

Permalink
bugfix: Apply normalisation also to SphereT as was already done for u…
Browse files Browse the repository at this point in the history
…nit-sphere (#242)
  • Loading branch information
wdeconinck authored Nov 22, 2024
1 parent 9a1ea76 commit 893381f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/atlas/util/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ template <typename SphereT>
class GeometrySphereT : public GeometryBase {
public:
void lonlat2xyz(const Point2& lonlat, Point3& xyz) const override {
#if ATLAS_ECKIT_VERSION_AT_LEAST(1, 24, 0)
SphereT::convertSphericalToCartesian(lonlat, xyz, 0., true);
#else
SphereT::convertSphericalToCartesian(lonlat, xyz);
#endif
}
void xyz2lonlat(const Point3& xyz, Point2& lonlat) const override {
SphereT::convertCartesianToSpherical(xyz, lonlat);
Expand Down
6 changes: 6 additions & 0 deletions src/tests/AtlasTestEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ bool approx_eq(const Point2& v1, const Point2& v2) {
bool approx_eq(const Point2& v1, const Point2& v2, const double& t) {
return approx_eq(v1[0], v2[0], t) && approx_eq(v1[1], v2[1], t);
}
bool approx_eq(const Point3& v1, const Point3& v2) {
return approx_eq(v1[0], v2[0]) && approx_eq(v1[1], v2[1]) && approx_eq(v1[2], v2[2]);
}
bool approx_eq(const Point3& v1, const Point3& v2, const double& t) {
return approx_eq(v1[0], v2[0], t) && approx_eq(v1[1], v2[1], t) && approx_eq(v1[2], v2[2], t);
}

template <typename T1, typename T2>
std::string expect_message(const std::string& condition, const T1& lhs, const T2& rhs, const eckit::CodeLocation& loc) {
Expand Down
8 changes: 8 additions & 0 deletions src/tests/util/test_earth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "atlas/util/Earth.h"
#include "atlas/util/Point.h"
#include "atlas/util/Geometry.h"

#include "tests/AtlasTestEnvironment.h"

Expand Down Expand Up @@ -169,6 +170,13 @@ CASE("test_earth_great_circle_latitude_given_longitude") {
EXPECT(eckit::types::is_approximately_equal(lat, -6.81, 0.01));
}

CASE("test_across_pole") {
const PointLonLat P1{-16.875,-105.255};
atlas::geometry::Earth geo;
EXPECT_APPROX_EQ(geo.xyz(P1), PointXYZ(-1.60418e+06,486624,-6.14673e+06), 50.);
}


} // namespace test
} // namespace atlas

Expand Down

0 comments on commit 893381f

Please sign in to comment.