From 069e46384f9cef25eb1ab29ea86d40ab6cc6261d Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 3 Sep 2023 23:36:40 +0200 Subject: [PATCH] Ellipsoid::_isEquivalentTo(): fix so that an ellipsoid of semi-major axis A (and non-zero inv flattening) isn't equivalent to a sphere of radius A... or to another ellipsoid of same semi-major axis but defined from a semi-minor axis and not inverse flattening Discovered when debugging corner cases of https://github.com/OSGeo/PROJ/pull/3879 ... --- src/iso19111/datum.cpp | 2 +- test/unit/test_datum.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/iso19111/datum.cpp b/src/iso19111/datum.cpp index 777addd22c..4e3b472768 100644 --- a/src/iso19111/datum.cpp +++ b/src/iso19111/datum.cpp @@ -1156,7 +1156,7 @@ bool Ellipsoid::_isEquivalentTo(const util::IComparable *other, } } else { - if (!otherEllipsoid->computeSemiMinorAxis()._isEquivalentTo( + if (!computeSemiMinorAxis()._isEquivalentTo( otherEllipsoid->computeSemiMinorAxis(), criterion)) { return false; } diff --git a/test/unit/test_datum.cpp b/test/unit/test_datum.cpp index 423438cca1..b06d5dbc19 100644 --- a/test/unit/test_datum.cpp +++ b/test/unit/test_datum.cpp @@ -124,6 +124,12 @@ TEST(datum, ellipsoid_from_inverse_flattening) { EXPECT_FALSE(Ellipsoid::WGS84->isEquivalentTo( Ellipsoid::GRS1980.get(), IComparable::Criterion::EQUIVALENT)); + + auto sphere = Ellipsoid::createSphere(PropertyMap(), Length(6378137)); + EXPECT_FALSE(Ellipsoid::WGS84->isEquivalentTo( + sphere.get(), IComparable::Criterion::EQUIVALENT)); + EXPECT_FALSE(sphere->isEquivalentTo(Ellipsoid::WGS84.get(), + IComparable::Criterion::EQUIVALENT)); } // ---------------------------------------------------------------------------