From 1dfaa89a017fb7a7967eb40192c698b1dc978f6a Mon Sep 17 00:00:00 2001 From: Aditya Date: Thu, 26 May 2022 17:35:24 -0700 Subject: [PATCH 01/25] Added distance calculation method considering the radius Signed-off-by: Aditya --- include/gz/math/SphericalCoordinates.hh | 18 +++++++++++++++++ src/SphericalCoordinates.cc | 20 +++++++++++++++++++ src/SphericalCoordinates_TEST.cc | 16 +++++++++++++++ .../src/SphericalCoordinates.cc | 18 ++++++++++++++++- 4 files changed, 71 insertions(+), 1 deletion(-) diff --git a/include/gz/math/SphericalCoordinates.hh b/include/gz/math/SphericalCoordinates.hh index fa3481000..e301b5776 100644 --- a/include/gz/math/SphericalCoordinates.hh +++ b/include/gz/math/SphericalCoordinates.hh @@ -141,6 +141,24 @@ namespace ignition const ignition::math::Angle &_latB, const ignition::math::Angle &_lonB); + + /// \brief Get the distance between two points expressed in geographic + /// latitude and longitude. It assumes that both points are at the + /// given radius from the centre of the celestial body. + /// Example: _latA = 38.0016667 and _lonA = -123.0016667) represents + /// the point with latitude 38d 0'6.00"N and longitude 123d 0'6.00"W. + /// \param[in] _latA Latitude of point A. + /// \param[in] _lonA Longitude of point A. + /// \param[in] _latB Latitude of point B. + /// \param[in] _lonB Longitude of point B. + /// \param[in] _radius Radius of the celestial body in metres. + /// \return Distance in meters. + public: static double Distance(const ignition::math::Angle &_latA, + const ignition::math::Angle &_lonA, + const ignition::math::Angle &_latB, + const ignition::math::Angle &_lonB, + const double &_radius); + /// \brief Get SurfaceType currently in use. /// \return Current SurfaceType value. public: SurfaceType Surface() const; diff --git a/src/SphericalCoordinates.cc b/src/SphericalCoordinates.cc index c66d93e46..287043ef1 100644 --- a/src/SphericalCoordinates.cc +++ b/src/SphericalCoordinates.cc @@ -303,6 +303,26 @@ double SphericalCoordinates::Distance(const ignition::math::Angle &_latA, return d; } +////////////////////////////////////////////////// +/// Based on Haversine formula (http://en.wikipedia.org/wiki/Haversine_formula). +double SphericalCoordinates::Distance(const ignition::math::Angle &_latA, + const ignition::math::Angle &_lonA, + const ignition::math::Angle &_latB, + const ignition::math::Angle &_lonB, + const double &_radius) +{ + ignition::math::Angle dLat = _latB - _latA; + ignition::math::Angle dLon = _lonB - _lonA; + + double a = sin(dLat.Radian() / 2) * sin(dLat.Radian() / 2) + + sin(dLon.Radian() / 2) * sin(dLon.Radian() / 2) * + cos(_latA.Radian()) * cos(_latB.Radian()); + + double c = 2 * atan2(sqrt(a), sqrt(1 - a)); + double d = _radius * c; + return d; +} + ////////////////////////////////////////////////// void SphericalCoordinates::UpdateTransformationMatrix() { diff --git a/src/SphericalCoordinates_TEST.cc b/src/SphericalCoordinates_TEST.cc index e6297d688..f08e4029b 100644 --- a/src/SphericalCoordinates_TEST.cc +++ b/src/SphericalCoordinates_TEST.cc @@ -316,6 +316,22 @@ TEST(SphericalCoordinatesTest, Distance) EXPECT_NEAR(14002, d, 20); } +////////////////////////////////////////////////// +// Test distance when radius is supplied +TEST(SphericalCoordinatesTest, DistanceWithRadius) +{ + ignition::math::Angle latA, longA, latB, longB; + latA.SetDegree(46.250944); + longA.SetDegree(-122.249972); + latB.SetDegree(46.124953); + longB.SetDegree(-122.251683); + double earthRadius = 6371000.0; + double d = math::SphericalCoordinates::Distance(latA, longA, latB, longB, + earthRadius * 0.5); + + EXPECT_NEAR(14002 * 0.5, d, 20); +} + ////////////////////////////////////////////////// TEST(SphericalCoordinatesTest, BadSetSurface) { diff --git a/src/python_pybind11/src/SphericalCoordinates.cc b/src/python_pybind11/src/SphericalCoordinates.cc index 211e6b517..6c3d2a44e 100644 --- a/src/python_pybind11/src/SphericalCoordinates.cc +++ b/src/python_pybind11/src/SphericalCoordinates.cc @@ -58,11 +58,27 @@ void defineMathSphericalCoordinates(py::module &m, const std::string &typestr) py::overload_cast(&Class::Convert), "Convert a SurfaceType to a string.") .def("distance", - &Class::Distance, + py::overload_cast< + const ignition::math::Angle&, + const ignition::math::Angle&, + const ignition::math::Angle&, + const ignition::math::Angle&>(&Class::Distance), "Get the distance between two points expressed in geographic " "latitude and longitude. It assumes that both points are at sea level." " Example: _latA = 38.0016667 and _lonA = -123.0016667) represents " "the point with latitude 38d 0'6.00\"N and longitude 123d 0'6.00\"W.") + .def("distance", + py::overload_cast< + const ignition::math::Angle&, + const ignition::math::Angle&, + const ignition::math::Angle&, + const ignition::math::Angle&, + const double&>(&Class::Distance), + "Get the distance between two points expressed in geographic" + "latitude and longitude. It assumes that both points are at the" + "given radius from the centre of the celestial body." + " Example: _latA = 38.0016667 and _lonA = -123.0016667) represents " + "the point with latitude 38d 0'6.00\"N and longitude 123d 0'6.00\"W.") .def("surface", &Class::Surface, "Get SurfaceType currently in use.") From 99f24961d61d40e4fa5291701bbb20e903d1d3a0 Mon Sep 17 00:00:00 2001 From: Aditya Date: Wed, 1 Jun 2022 22:46:30 -0700 Subject: [PATCH 02/25] Reverted overloading of Distance function Signed-off-by: Aditya --- include/gz/math/SphericalCoordinates.hh | 25 ++++++------------------- src/SphericalCoordinates.cc | 20 -------------------- src/SphericalCoordinates_TEST.cc | 16 ---------------- 3 files changed, 6 insertions(+), 55 deletions(-) diff --git a/include/gz/math/SphericalCoordinates.hh b/include/gz/math/SphericalCoordinates.hh index 90a1af490..fa86a498b 100644 --- a/include/gz/math/SphericalCoordinates.hh +++ b/include/gz/math/SphericalCoordinates.hh @@ -41,7 +41,12 @@ namespace gz { /// \brief Model of reference ellipsoid for earth, based on /// WGS 84 standard. see wikipedia: World_Geodetic_System - EARTH_WGS84 = 1 + EARTH_WGS84 = 1, + + /// |brief Model of the moon, based on the Selenographic + /// coordinate system, see wikipedia: Selenographic + /// Coordinate System + MOON_SCS = 2 }; /// \enum CoordinateType @@ -141,24 +146,6 @@ namespace gz const gz::math::Angle &_latB, const gz::math::Angle &_lonB); - - /// \brief Get the distance between two points expressed in geographic - /// latitude and longitude. It assumes that both points are at the - /// given radius from the centre of the celestial body. - /// Example: _latA = 38.0016667 and _lonA = -123.0016667) represents - /// the point with latitude 38d 0'6.00"N and longitude 123d 0'6.00"W. - /// \param[in] _latA Latitude of point A. - /// \param[in] _lonA Longitude of point A. - /// \param[in] _latB Latitude of point B. - /// \param[in] _lonB Longitude of point B. - /// \param[in] _radius Radius of the celestial body in metres. - /// \return Distance in meters. - public: static double Distance(const ignition::math::Angle &_latA, - const ignition::math::Angle &_lonA, - const ignition::math::Angle &_latB, - const ignition::math::Angle &_lonB, - const double &_radius); - /// \brief Get SurfaceType currently in use. /// \return Current SurfaceType value. public: SurfaceType Surface() const; diff --git a/src/SphericalCoordinates.cc b/src/SphericalCoordinates.cc index 95124bed5..de95c0a2c 100644 --- a/src/SphericalCoordinates.cc +++ b/src/SphericalCoordinates.cc @@ -303,26 +303,6 @@ double SphericalCoordinates::Distance(const gz::math::Angle &_latA, return d; } -////////////////////////////////////////////////// -/// Based on Haversine formula (http://en.wikipedia.org/wiki/Haversine_formula). -double SphericalCoordinates::Distance(const ignition::math::Angle &_latA, - const ignition::math::Angle &_lonA, - const ignition::math::Angle &_latB, - const ignition::math::Angle &_lonB, - const double &_radius) -{ - ignition::math::Angle dLat = _latB - _latA; - ignition::math::Angle dLon = _lonB - _lonA; - - double a = sin(dLat.Radian() / 2) * sin(dLat.Radian() / 2) + - sin(dLon.Radian() / 2) * sin(dLon.Radian() / 2) * - cos(_latA.Radian()) * cos(_latB.Radian()); - - double c = 2 * atan2(sqrt(a), sqrt(1 - a)); - double d = _radius * c; - return d; -} - ////////////////////////////////////////////////// void SphericalCoordinates::UpdateTransformationMatrix() { diff --git a/src/SphericalCoordinates_TEST.cc b/src/SphericalCoordinates_TEST.cc index 141525779..f0e4b0191 100644 --- a/src/SphericalCoordinates_TEST.cc +++ b/src/SphericalCoordinates_TEST.cc @@ -316,22 +316,6 @@ TEST(SphericalCoordinatesTest, Distance) EXPECT_NEAR(14002, d, 20); } -////////////////////////////////////////////////// -// Test distance when radius is supplied -TEST(SphericalCoordinatesTest, DistanceWithRadius) -{ - ignition::math::Angle latA, longA, latB, longB; - latA.SetDegree(46.250944); - longA.SetDegree(-122.249972); - latB.SetDegree(46.124953); - longB.SetDegree(-122.251683); - double earthRadius = 6371000.0; - double d = math::SphericalCoordinates::Distance(latA, longA, latB, longB, - earthRadius * 0.5); - - EXPECT_NEAR(14002 * 0.5, d, 20); -} - ////////////////////////////////////////////////// TEST(SphericalCoordinatesTest, BadSetSurface) { From 4d684005e57fbf61ada751180ae18d014740a719 Mon Sep 17 00:00:00 2001 From: Aditya Date: Thu, 2 Jun 2022 16:14:49 -0700 Subject: [PATCH 03/25] Added MOON and CUSTOM surface types, api to set radius Signed-off-by: Aditya --- include/gz/math/SphericalCoordinates.hh | 33 ++++- src/SphericalCoordinates.cc | 120 ++++++++++++++++++ src/SphericalCoordinates_TEST.cc | 49 ++++++- .../src/SphericalCoordinates.cc | 18 +-- 4 files changed, 196 insertions(+), 24 deletions(-) diff --git a/include/gz/math/SphericalCoordinates.hh b/include/gz/math/SphericalCoordinates.hh index fa86a498b..26def0d28 100644 --- a/include/gz/math/SphericalCoordinates.hh +++ b/include/gz/math/SphericalCoordinates.hh @@ -45,8 +45,11 @@ namespace gz /// |brief Model of the moon, based on the Selenographic /// coordinate system, see wikipedia: Selenographic - /// Coordinate System - MOON_SCS = 2 + /// Coordinate System. + MOON_SCS = 2, + + /// |brief Custom surface type + CUSTOM_SURFACE = 10 }; /// \enum CoordinateType @@ -90,6 +93,15 @@ namespace gz const double _elevation, const gz::math::Angle &_heading); + /// |brief Set the radius of surface, in case the SurfaceType is set + /// to CUSTOM_SURFACE. + /// Returns true if the SurfaceType was CUSTOM_SURFACE and the radius + /// provided is positive, otherwise returns false. + /// |param[in] _radius Radius of the custom SurfaceType in meters. + public: bool SetSurfaceRadius(const double _radius); + + /// |brief Get the radius of the specified SurfaceType. + public: double GetSurfaceRadius() const; /// \brief Convert a Cartesian position vector to geodetic coordinates. /// This performs a `PositionTransform` from LOCAL to SPHERICAL. @@ -146,6 +158,23 @@ namespace gz const gz::math::Angle &_latB, const gz::math::Angle &_lonB); + /// \brief Get the distance between two points expressed in geographic + /// latitude and longitude. It assumes that both points are at sea level. + /// Example: _latA = 38.0016667 and _lonA = -123.0016667) represents + /// the point with latitude 38d 0'6.00"N and longitude 123d 0'6.00"W. + /// This is different from the static Distance() method as it takes into + /// account the surface type. + /// \param[in] _latA Latitude of point A. + /// \param[in] _lonA Longitude of point A. + /// \param[in] _latB Latitude of point B. + /// \param[in] _lonB Longitude of point B. + /// \return Distance in meters. + public: double DistanceBetweenPoints( + const gz::math::Angle &_latA, + const gz::math::Angle &_lonA, + const gz::math::Angle &_latB, + const gz::math::Angle &_lonB); + /// \brief Get SurfaceType currently in use. /// \return Current SurfaceType value. public: SurfaceType Surface() const; diff --git a/src/SphericalCoordinates.cc b/src/SphericalCoordinates.cc index de95c0a2c..dc599369f 100644 --- a/src/SphericalCoordinates.cc +++ b/src/SphericalCoordinates.cc @@ -38,12 +38,31 @@ const double g_EarthWGS84Flattening = 1.0/298.257223563; // Radius of the Earth (meters). const double g_EarthRadius = 6371000.0; +// Radius of the Moon (meters). +// Source: https://lunar.gsfc.nasa.gov/library/451-SCI-000958.pdf +const double g_MoonRadius = 1737400.0; + +// a: Equatorial radius of the Moon. +// Source : https://nssdc.gsfc.nasa.gov/planetary/factsheet/moonfact.html +const double g_MoonAxisEquatorial = 1738100.0; + +// b: Polar radius of the Moon. +// Source : https://nssdc.gsfc.nasa.gov/planetary/factsheet/moonfact.html +const double g_MoonAxisPolar = 1736000.0; + +// if: Unitless flattening parameter for the Moon. +// Source : https://nssdc.gsfc.nasa.gov/planetary/factsheet/moonfact.html +const double g_MoonFlattening = 0.0012; + // Private data for the SphericalCoordinates class. class gz::math::SphericalCoordinates::Implementation { /// \brief Type of surface being used. public: SphericalCoordinates::SurfaceType surfaceType; + /// |brief Radius of the given SurfaceType. + public: double surfaceRadius = 0; + /// \brief Latitude of reference point. public: gz::math::Angle latitudeReference; @@ -94,6 +113,10 @@ SphericalCoordinates::SurfaceType SphericalCoordinates::Convert( { if ("EARTH_WGS84" == _str) return EARTH_WGS84; + else if ("MOON_SCS" == _str) + return MOON_SCS; + else if ("CUSTOM_SURFACE" == _str) + return CUSTOM_SURFACE; std::cerr << "SurfaceType string not recognized, " << "EARTH_WGS84 returned by default" << std::endl; @@ -106,6 +129,10 @@ std::string SphericalCoordinates::Convert( { if (_type == EARTH_WGS84) return "EARTH_WGS84"; + else if (_type == MOON_SCS) + return "MOON_SCS"; + else if (_type == CUSTOM_SURFACE) + return "CUSTOM_SURFACE"; std::cerr << "SurfaceType not recognized, " << "EARTH_WGS84 returned by default" << std::endl; @@ -117,6 +144,7 @@ SphericalCoordinates::SphericalCoordinates() : dataPtr(gz::utils::MakeImpl()) { this->SetSurface(EARTH_WGS84); + this->dataPtr->surfaceRadius = g_EarthRadius; this->SetElevationReference(0.0); } @@ -125,6 +153,20 @@ SphericalCoordinates::SphericalCoordinates(const SurfaceType _type) : SphericalCoordinates() { this->SetSurface(_type); + switch(_type) + { + case EARTH_WGS84: + this->dataPtr->surfaceRadius = g_EarthRadius; + break; + case MOON_SCS: + this->dataPtr->surfaceRadius = g_MoonRadius; + break; + case CUSTOM_SURFACE: + this->dataPtr->surfaceRadius = 0; + break; + default: + std::cerr << "Unknown surface type [" << _type << "]" << std::endl; + } this->SetElevationReference(0.0); } @@ -149,6 +191,24 @@ SphericalCoordinates::SphericalCoordinates(const SurfaceType _type, this->UpdateTransformationMatrix(); } +////////////////////////////////////////////////// +bool SphericalCoordinates::SetSurfaceRadius(const double _radius) +{ + if ( (this->Surface() == CUSTOM_SURFACE) && _radius > 0) + { + this->dataPtr->surfaceRadius = _radius; + return true; + } + + return false; +} + +////////////////////////////////////////////////// +double SphericalCoordinates::GetSurfaceRadius() const +{ + return this->dataPtr->surfaceRadius; +} + ////////////////////////////////////////////////// SphericalCoordinates::SurfaceType SphericalCoordinates::Surface() const { @@ -210,6 +270,35 @@ void SphericalCoordinates::SetSurface(const SurfaceType &_type) break; } + case MOON_SCS: + { + // Set the semi-major axis + this->dataPtr->ellA = g_MoonAxisEquatorial; + + // Set the semi-minor axis + this->dataPtr->ellB = g_MoonAxisPolar; + + // Set the flattening parameter + this->dataPtr->ellF = g_MoonFlattening; + + // Set the first eccentricity ellipse parameter + // https://en.wikipedia.org/wiki/Eccentricity_(mathematics)#Ellipses + this->dataPtr->ellE = sqrt(1.0 - + std::pow(this->dataPtr->ellB, 2) / std::pow(this->dataPtr->ellA, 2)); + + // Set the second eccentricity ellipse parameter + // https://en.wikipedia.org/wiki/Eccentricity_(mathematics)#Ellipses + this->dataPtr->ellP = sqrt( + std::pow(this->dataPtr->ellA, 2) / std::pow(this->dataPtr->ellB, 2) - + 1.0); + + break; + } + case CUSTOM_SURFACE: + { + // TODO aditya: Add API to get and set semi major axes, eccentricity + } + break; default: { std::cerr << "Unknown surface type[" @@ -303,6 +392,37 @@ double SphericalCoordinates::Distance(const gz::math::Angle &_latA, return d; } +////////////////////////////////////////////////// +/// Based on Haversine formula (http://en.wikipedia.org/wiki/Haversine_formula). +/// This takes into account the surface type. +double SphericalCoordinates::DistanceBetweenPoints( + const gz::math::Angle &_latA, + const gz::math::Angle &_lonA, + const gz::math::Angle &_latB, + const gz::math::Angle &_lonB) +{ + gz::math::Angle dLat = _latB - _latA; + gz::math::Angle dLon = _lonB - _lonA; + + double a = sin(dLat.Radian() / 2) * sin(dLat.Radian() / 2) + + sin(dLon.Radian() / 2) * sin(dLon.Radian() / 2) * + cos(_latA.Radian()) * cos(_latB.Radian()); + + double c = 2 * atan2(sqrt(a), sqrt(1 - a)); + if ( this->dataPtr->surfaceRadius > 0 ) + { + double d = this->dataPtr->surfaceRadius * c; + return d; + } + else + { + std::cerr << "Surface radius is invalid or not set for the given " + "surface type" << std::endl; + } + + return -1; +} + ////////////////////////////////////////////////// void SphericalCoordinates::UpdateTransformationMatrix() { diff --git a/src/SphericalCoordinates_TEST.cc b/src/SphericalCoordinates_TEST.cc index f0e4b0191..88028f00a 100644 --- a/src/SphericalCoordinates_TEST.cc +++ b/src/SphericalCoordinates_TEST.cc @@ -80,7 +80,12 @@ TEST(SphericalCoordinatesTest, Convert) EXPECT_EQ("EARTH_WGS84", math::SphericalCoordinates::Convert(st)); EXPECT_EQ("EARTH_WGS84", math::SphericalCoordinates::Convert( - static_cast(2))); + static_cast(3))); + + // For the Moon surface type + st = math::SphericalCoordinates::MOON_SCS; + EXPECT_EQ(math::SphericalCoordinates::Convert("MOON_SCS"), st); + EXPECT_EQ("MOON_SCS", math::SphericalCoordinates::Convert(st)); } ////////////////////////////////////////////////// @@ -311,17 +316,51 @@ TEST(SphericalCoordinatesTest, Distance) longA.SetDegree(-122.249972); latB.SetDegree(46.124953); longB.SetDegree(-122.251683); - double d = math::SphericalCoordinates::Distance(latA, longA, latB, longB); - EXPECT_NEAR(14002, d, 20); + // Calculating distance using the static method. + double d1 = math::SphericalCoordinates::Distance(latA, longA, latB, longB); + EXPECT_NEAR(14002, d1, 20); + + // Using the non static method. The default surface type is EARTH_WGS84. + auto earthSC = math::SphericalCoordinates(); + double d2 = earthSC.DistanceBetweenPoints(latA, longA, latB, longB); + EXPECT_NEAR(d1, d2, 0.1); + + earthSC = math::SphericalCoordinates( + math::SphericalCoordinates::SurfaceType::EARTH_WGS84); + double d3 = earthSC.DistanceBetweenPoints(latA, longA, latB, longB); + EXPECT_NEAR(d2, d3, 0.1); + + //Setting the surface type as Moon. + auto moonSC = math::SphericalCoordinates( + math::SphericalCoordinates::SurfaceType::MOON_SCS); + double d4 = moonSC.DistanceBetweenPoints(latA, longA, latB, longB); + EXPECT_NEAR(3820, d4, 5); + + // Using a custom surface. + auto customSC = math::SphericalCoordinates( + math::SphericalCoordinates::SurfaceType::CUSTOM_SURFACE); + // Setting negative radius is not allowed. + EXPECT_FALSE(customSC.SetSurfaceRadius(-1000.0)); + EXPECT_NEAR(customSC.GetSurfaceRadius(), 0.0, 0.001); + + // DistanceBetweenPoints should return invalid result as the radius + // for the custom surface is not set. + EXPECT_LT(customSC.DistanceBetweenPoints(latA, longA, latB, longB), 0); + + // Setting a positive radius is allowed. + EXPECT_TRUE(customSC.SetSurfaceRadius(6371000.0)); + EXPECT_NEAR(customSC.GetSurfaceRadius(), 6371000.0, 0.01); + + EXPECT_NEAR(customSC.DistanceBetweenPoints(latA, longA, latB, longB), d1, 0.1); } ////////////////////////////////////////////////// TEST(SphericalCoordinatesTest, BadSetSurface) { math::SphericalCoordinates sc; - sc.SetSurface(static_cast(2)); - EXPECT_EQ(sc.Surface(), 2); + sc.SetSurface(static_cast(3)); + EXPECT_EQ(sc.Surface(), 3); } ////////////////////////////////////////////////// diff --git a/src/python_pybind11/src/SphericalCoordinates.cc b/src/python_pybind11/src/SphericalCoordinates.cc index 8dcee05a4..69e5046e5 100644 --- a/src/python_pybind11/src/SphericalCoordinates.cc +++ b/src/python_pybind11/src/SphericalCoordinates.cc @@ -58,27 +58,11 @@ void defineMathSphericalCoordinates(py::module &m, const std::string &typestr) py::overload_cast(&Class::Convert), "Convert a SurfaceType to a string.") .def("distance", - py::overload_cast< - const ignition::math::Angle&, - const ignition::math::Angle&, - const ignition::math::Angle&, - const ignition::math::Angle&>(&Class::Distance), + &Class::Distance, "Get the distance between two points expressed in geographic " "latitude and longitude. It assumes that both points are at sea level." " Example: _latA = 38.0016667 and _lonA = -123.0016667) represents " "the point with latitude 38d 0'6.00\"N and longitude 123d 0'6.00\"W.") - .def("distance", - py::overload_cast< - const ignition::math::Angle&, - const ignition::math::Angle&, - const ignition::math::Angle&, - const ignition::math::Angle&, - const double&>(&Class::Distance), - "Get the distance between two points expressed in geographic" - "latitude and longitude. It assumes that both points are at the" - "given radius from the centre of the celestial body." - " Example: _latA = 38.0016667 and _lonA = -123.0016667) represents " - "the point with latitude 38d 0'6.00\"N and longitude 123d 0'6.00\"W.") .def("surface", &Class::Surface, "Get SurfaceType currently in use.") From ecd86e024d43a84cf8be3c8880718c914d4c176f Mon Sep 17 00:00:00 2001 From: Aditya Date: Fri, 3 Jun 2022 17:48:49 -0700 Subject: [PATCH 04/25] Added new constructor for custom surface, updated tests Signed-off-by: Aditya --- include/gz/math/SphericalCoordinates.hh | 21 ++++----- src/SphericalCoordinates.cc | 58 +++++++++++++++---------- src/SphericalCoordinates_TEST.cc | 17 +++----- 3 files changed, 50 insertions(+), 46 deletions(-) diff --git a/include/gz/math/SphericalCoordinates.hh b/include/gz/math/SphericalCoordinates.hh index 26def0d28..5e2a99559 100644 --- a/include/gz/math/SphericalCoordinates.hh +++ b/include/gz/math/SphericalCoordinates.hh @@ -81,6 +81,17 @@ namespace gz /// \param[in] _type SurfaceType specification. public: explicit SphericalCoordinates(const SurfaceType _type); + /// \brief Constructor with surface type input and properties + /// input. To be used for CUSTOM_SURFACE. + /// \param[in] _type SurfaceType specification. + public: SphericalCoordinates( + const SurfaceType _type, + const double _radius, + const double _axisEquatorial, + const double _axisPolar, + const double _flattening + ); + /// \brief Constructor with surface type, angle, and elevation inputs. /// \param[in] _type SurfaceType specification. /// \param[in] _latitude Reference latitude. @@ -93,16 +104,6 @@ namespace gz const double _elevation, const gz::math::Angle &_heading); - /// |brief Set the radius of surface, in case the SurfaceType is set - /// to CUSTOM_SURFACE. - /// Returns true if the SurfaceType was CUSTOM_SURFACE and the radius - /// provided is positive, otherwise returns false. - /// |param[in] _radius Radius of the custom SurfaceType in meters. - public: bool SetSurfaceRadius(const double _radius); - - /// |brief Get the radius of the specified SurfaceType. - public: double GetSurfaceRadius() const; - /// \brief Convert a Cartesian position vector to geodetic coordinates. /// This performs a `PositionTransform` from LOCAL to SPHERICAL. /// diff --git a/src/SphericalCoordinates.cc b/src/SphericalCoordinates.cc index dc599369f..7407de1ee 100644 --- a/src/SphericalCoordinates.cc +++ b/src/SphericalCoordinates.cc @@ -162,7 +162,8 @@ SphericalCoordinates::SphericalCoordinates(const SurfaceType _type) this->dataPtr->surfaceRadius = g_MoonRadius; break; case CUSTOM_SURFACE: - this->dataPtr->surfaceRadius = 0; + std::cerr << "Please supply ellipsoidal properties with the custom surface" + << std::endl; break; default: std::cerr << "Unknown surface type [" << _type << "]" << std::endl; @@ -170,6 +171,38 @@ SphericalCoordinates::SphericalCoordinates(const SurfaceType _type) this->SetElevationReference(0.0); } +////////////////////////////////////////////////// +SphericalCoordinates::SphericalCoordinates( + const SurfaceType _type, + const double _radius, + const double _axisEquatorial, + const double _axisPolar, + const double _flattening) + : SphericalCoordinates() +{ + if (_type != CUSTOM_SURFACE) + { + std::cerr << "Surface type should be set to SURFACE_CUSTOM" + << std::endl; + return; + } + + // Set properties + this->dataPtr->surfaceType = _type; + + this->dataPtr->ellA = _axisEquatorial; + this->dataPtr->ellB = _axisPolar; + this->dataPtr->ellF = _flattening; + this->dataPtr->ellE = sqrt(1.0 - + std::pow(this->dataPtr->ellB, 2) / std::pow(this->dataPtr->ellA, 2)); + this->dataPtr->ellP = sqrt( + std::pow(this->dataPtr->ellA, 2) / std::pow(this->dataPtr->ellB, 2) - + 1.0); + this->dataPtr->surfaceRadius = _radius; + + this->SetElevationReference(0.0); +} + ////////////////////////////////////////////////// SphericalCoordinates::SphericalCoordinates(const SurfaceType _type, const gz::math::Angle &_latitude, @@ -191,24 +224,6 @@ SphericalCoordinates::SphericalCoordinates(const SurfaceType _type, this->UpdateTransformationMatrix(); } -////////////////////////////////////////////////// -bool SphericalCoordinates::SetSurfaceRadius(const double _radius) -{ - if ( (this->Surface() == CUSTOM_SURFACE) && _radius > 0) - { - this->dataPtr->surfaceRadius = _radius; - return true; - } - - return false; -} - -////////////////////////////////////////////////// -double SphericalCoordinates::GetSurfaceRadius() const -{ - return this->dataPtr->surfaceRadius; -} - ////////////////////////////////////////////////// SphericalCoordinates::SurfaceType SphericalCoordinates::Surface() const { @@ -294,11 +309,6 @@ void SphericalCoordinates::SetSurface(const SurfaceType &_type) break; } - case CUSTOM_SURFACE: - { - // TODO aditya: Add API to get and set semi major axes, eccentricity - } - break; default: { std::cerr << "Unknown surface type[" diff --git a/src/SphericalCoordinates_TEST.cc b/src/SphericalCoordinates_TEST.cc index 88028f00a..54cad82fa 100644 --- a/src/SphericalCoordinates_TEST.cc +++ b/src/SphericalCoordinates_TEST.cc @@ -339,18 +339,11 @@ TEST(SphericalCoordinatesTest, Distance) // Using a custom surface. auto customSC = math::SphericalCoordinates( - math::SphericalCoordinates::SurfaceType::CUSTOM_SURFACE); - // Setting negative radius is not allowed. - EXPECT_FALSE(customSC.SetSurfaceRadius(-1000.0)); - EXPECT_NEAR(customSC.GetSurfaceRadius(), 0.0, 0.001); - - // DistanceBetweenPoints should return invalid result as the radius - // for the custom surface is not set. - EXPECT_LT(customSC.DistanceBetweenPoints(latA, longA, latB, longB), 0); - - // Setting a positive radius is allowed. - EXPECT_TRUE(customSC.SetSurfaceRadius(6371000.0)); - EXPECT_NEAR(customSC.GetSurfaceRadius(), 6371000.0, 0.01); + math::SphericalCoordinates::SurfaceType::CUSTOM_SURFACE, + 6371000.0, + 6378137.0, + 6356752.314245, + 1.0/298.25722); EXPECT_NEAR(customSC.DistanceBetweenPoints(latA, longA, latB, longB), d1, 0.1); } From d804ebd658ac7dbd3fd1f05d4afbce63d3b4115a Mon Sep 17 00:00:00 2001 From: Aditya Date: Fri, 3 Jun 2022 17:57:28 -0700 Subject: [PATCH 05/25] Linter erros fixed Signed-off-by: Aditya --- src/SphericalCoordinates.cc | 4 ++-- src/SphericalCoordinates_TEST.cc | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/SphericalCoordinates.cc b/src/SphericalCoordinates.cc index 7407de1ee..9788595bc 100644 --- a/src/SphericalCoordinates.cc +++ b/src/SphericalCoordinates.cc @@ -162,8 +162,8 @@ SphericalCoordinates::SphericalCoordinates(const SurfaceType _type) this->dataPtr->surfaceRadius = g_MoonRadius; break; case CUSTOM_SURFACE: - std::cerr << "Please supply ellipsoidal properties with the custom surface" - << std::endl; + std::cerr << "Please supply ellipsoidal properties with the " + "custom surface." << std::endl; break; default: std::cerr << "Unknown surface type [" << _type << "]" << std::endl; diff --git a/src/SphericalCoordinates_TEST.cc b/src/SphericalCoordinates_TEST.cc index 54cad82fa..0d9f23fb5 100644 --- a/src/SphericalCoordinates_TEST.cc +++ b/src/SphericalCoordinates_TEST.cc @@ -331,7 +331,7 @@ TEST(SphericalCoordinatesTest, Distance) double d3 = earthSC.DistanceBetweenPoints(latA, longA, latB, longB); EXPECT_NEAR(d2, d3, 0.1); - //Setting the surface type as Moon. + // Setting the surface type as Moon. auto moonSC = math::SphericalCoordinates( math::SphericalCoordinates::SurfaceType::MOON_SCS); double d4 = moonSC.DistanceBetweenPoints(latA, longA, latB, longB); @@ -345,7 +345,8 @@ TEST(SphericalCoordinatesTest, Distance) 6356752.314245, 1.0/298.25722); - EXPECT_NEAR(customSC.DistanceBetweenPoints(latA, longA, latB, longB), d1, 0.1); + EXPECT_NEAR(customSC.DistanceBetweenPoints(latA, longA, latB, longB), + d1, 0.1); } ////////////////////////////////////////////////// From b401946aaf0b4b02c32fcada9cea585a48c4e40e Mon Sep 17 00:00:00 2001 From: Aditya Date: Fri, 10 Jun 2022 15:03:17 -0700 Subject: [PATCH 06/25] Updated docstrings Signed-off-by: Aditya --- include/gz/math/SphericalCoordinates.hh | 8 ++++++-- src/SphericalCoordinates.cc | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/gz/math/SphericalCoordinates.hh b/include/gz/math/SphericalCoordinates.hh index 5e2a99559..f181e7c5a 100644 --- a/include/gz/math/SphericalCoordinates.hh +++ b/include/gz/math/SphericalCoordinates.hh @@ -43,12 +43,12 @@ namespace gz /// WGS 84 standard. see wikipedia: World_Geodetic_System EARTH_WGS84 = 1, - /// |brief Model of the moon, based on the Selenographic + /// \brief Model of the moon, based on the Selenographic /// coordinate system, see wikipedia: Selenographic /// Coordinate System. MOON_SCS = 2, - /// |brief Custom surface type + /// \brief Custom surface type CUSTOM_SURFACE = 10 }; @@ -84,6 +84,10 @@ namespace gz /// \brief Constructor with surface type input and properties /// input. To be used for CUSTOM_SURFACE. /// \param[in] _type SurfaceType specification. + /// \param[in] _radius Radius of the surface. + /// \param[in] _axisEquatorial Semi major axis of the surface. + /// \param[in] _axisPolar Semi minor axis of the surface. + /// \param[in] _axisPolar Flattening parameter of the surface. public: SphericalCoordinates( const SurfaceType _type, const double _radius, diff --git a/src/SphericalCoordinates.cc b/src/SphericalCoordinates.cc index 9788595bc..85ce663dc 100644 --- a/src/SphericalCoordinates.cc +++ b/src/SphericalCoordinates.cc @@ -60,7 +60,7 @@ class gz::math::SphericalCoordinates::Implementation /// \brief Type of surface being used. public: SphericalCoordinates::SurfaceType surfaceType; - /// |brief Radius of the given SurfaceType. + /// \brief Radius of the given SurfaceType. public: double surfaceRadius = 0; /// \brief Latitude of reference point. From 03869a999a85f1a5e71c707413d01655f993b40b Mon Sep 17 00:00:00 2001 From: Aditya Date: Mon, 13 Jun 2022 14:19:21 -0700 Subject: [PATCH 07/25] Filter neg values in sllipse props, overload SetSurface Signed-off-by: Aditya --- include/gz/math/SphericalCoordinates.hh | 12 +++ src/SphericalCoordinates.cc | 86 +++++++++++++++---- .../src/SphericalCoordinates.cc | 15 +++- 3 files changed, 95 insertions(+), 18 deletions(-) diff --git a/include/gz/math/SphericalCoordinates.hh b/include/gz/math/SphericalCoordinates.hh index f181e7c5a..50523abaf 100644 --- a/include/gz/math/SphericalCoordinates.hh +++ b/include/gz/math/SphericalCoordinates.hh @@ -206,6 +206,18 @@ namespace gz /// \param[in] _type SurfaceType value. public: void SetSurface(const SurfaceType &_type); + /// \brief Set SurfaceType for planetary surface model with + /// custom ellipsoid properties. + /// \param[in] _type SurfaceType value. + /// \param[in] _axisEquatorial Equatorial axis of the surface. + /// \param[in] _axisPolar Polar axis of the surface. + /// \param[in] _flattening Falttening parameter of the surface. + public: void SetSurface( + const SurfaceType &_type, + const double _axisEquatorial, + const double _axisPolar, + const double _flattening); + /// \brief Set reference geodetic latitude. /// \param[in] _angle Reference geodetic latitude. public: void SetLatitudeReference(const gz::math::Angle &_angle); diff --git a/src/SphericalCoordinates.cc b/src/SphericalCoordinates.cc index 85ce663dc..6c5c564e1 100644 --- a/src/SphericalCoordinates.cc +++ b/src/SphericalCoordinates.cc @@ -180,25 +180,20 @@ SphericalCoordinates::SphericalCoordinates( const double _flattening) : SphericalCoordinates() { - if (_type != CUSTOM_SURFACE) - { - std::cerr << "Surface type should be set to SURFACE_CUSTOM" - << std::endl; - return; - } - // Set properties - this->dataPtr->surfaceType = _type; + this->SetSurface(_type, _axisEquatorial, + _axisPolar, _flattening); - this->dataPtr->ellA = _axisEquatorial; - this->dataPtr->ellB = _axisPolar; - this->dataPtr->ellF = _flattening; - this->dataPtr->ellE = sqrt(1.0 - - std::pow(this->dataPtr->ellB, 2) / std::pow(this->dataPtr->ellA, 2)); - this->dataPtr->ellP = sqrt( - std::pow(this->dataPtr->ellA, 2) / std::pow(this->dataPtr->ellB, 2) - - 1.0); - this->dataPtr->surfaceRadius = _radius; + if (_radius > 0) + { + this->dataPtr->surfaceRadius = _radius; + } + else + { + std::cerr << "Value of _radius should be greater than zero " + " defaulting to Earth's flattening value."<< std::endl; + this->dataPtr->surfaceRadius = g_EarthRadius; + } this->SetElevationReference(0.0); } @@ -318,6 +313,63 @@ void SphericalCoordinates::SetSurface(const SurfaceType &_type) } } +////////////////////////////////////////////////// +void SphericalCoordinates::SetSurface( + const SurfaceType &_type, + const double _axisEquatorial, + const double _axisPolar, + const double _flattening) +{ + if (_type != EARTH_WGS84 || + _type != MOON_SCS || + _type != CUSTOM_SURFACE) + { + std::cerr << "Unknown surface type[" + << _type << "]\n"; + return; + } + + this->dataPtr->surfaceType = _type; + if (_axisEquatorial > 0) + { + this->dataPtr->ellA = _axisEquatorial; + } + else + { + std::cerr << "Value of _axisEquatorial should be greater than zero " + " defaulting to Earth's equatorial radius." << std::endl; + this->dataPtr->ellA = g_EarthWGS84AxisEquatorial; + } + + if (_axisPolar > 0) + { + this->dataPtr->ellB = _axisPolar; + } + else + { + std::cerr << "Value of _axisPolar should be greater than zero " + " defaulting to Earth's polar radius." << std::endl; + this->dataPtr->ellB = g_EarthWGS84AxisPolar; + } + + if (_flattening > 0) + { + this->dataPtr->ellF = _flattening; + } + else + { + std::cerr << "Value of _flattening should be greater than zero " + " defaulting to Earth's flattening value."<< std::endl; + this->dataPtr->ellF = g_EarthWGS84Flattening; + } + + this->dataPtr->ellE = sqrt(1.0 - + std::pow(this->dataPtr->ellB, 2) / std::pow(this->dataPtr->ellA, 2)); + this->dataPtr->ellP = sqrt( + std::pow(this->dataPtr->ellA, 2) / std::pow(this->dataPtr->ellB, 2) - + 1.0); +} + ////////////////////////////////////////////////// void SphericalCoordinates::SetLatitudeReference( const gz::math::Angle &_angle) diff --git a/src/python_pybind11/src/SphericalCoordinates.cc b/src/python_pybind11/src/SphericalCoordinates.cc index 69e5046e5..88b36d485 100644 --- a/src/python_pybind11/src/SphericalCoordinates.cc +++ b/src/python_pybind11/src/SphericalCoordinates.cc @@ -42,6 +42,8 @@ void defineMathSphericalCoordinates(py::module &m, const std::string &typestr) .def(py::init()) + .def(py::init()) .def(py::self != py::self) .def(py::self == py::self) .def("spherical_from_local_position", @@ -63,6 +65,12 @@ void defineMathSphericalCoordinates(py::module &m, const std::string &typestr) "latitude and longitude. It assumes that both points are at sea level." " Example: _latA = 38.0016667 and _lonA = -123.0016667) represents " "the point with latitude 38d 0'6.00\"N and longitude 123d 0'6.00\"W.") + .def("distance", + &Class::DistanceBetweenPoints, + "Get the distance between two points expressed in geographic " + "latitude and longitude. It assumes that both points are at sea level." + " Example: _latA = 38.0016667 and _lonA = -123.0016667) represents " + "the point with latitude 38d 0'6.00\"N and longitude 123d 0'6.00\"W.") .def("surface", &Class::Surface, "Get SurfaceType currently in use.") @@ -81,7 +89,12 @@ void defineMathSphericalCoordinates(py::module &m, const std::string &typestr) "angle from East to x-axis, or equivalently " "from North to y-axis.") .def("set_surface", - &Class::SetSurface, + py::overload_cast(&Class::SetSurface), + "Set SurfaceType for planetary surface model.") + .def("set_surface", + py::overload_cast(&Class::SetSurface), "Set SurfaceType for planetary surface model.") .def("set_latitude_reference", &Class::SetLatitudeReference, From d34ce645aaee80507333a9ef11205ed6c71b0884 Mon Sep 17 00:00:00 2001 From: Aditya Date: Mon, 13 Jun 2022 16:44:24 -0700 Subject: [PATCH 08/25] Added getter methods, tests Signed-off-by: Aditya --- include/gz/math/SphericalCoordinates.hh | 16 +++++++++++ src/SphericalCoordinates.cc | 24 ++++++++++++++++ src/SphericalCoordinates_TEST.cc | 38 +++++++++++++++++++++++++ 3 files changed, 78 insertions(+) diff --git a/include/gz/math/SphericalCoordinates.hh b/include/gz/math/SphericalCoordinates.hh index 50523abaf..17c4da517 100644 --- a/include/gz/math/SphericalCoordinates.hh +++ b/include/gz/math/SphericalCoordinates.hh @@ -184,6 +184,22 @@ namespace gz /// \return Current SurfaceType value. public: SurfaceType Surface() const; + /// \brief Get the radius of the surface. + /// \return radius of the surface in use. + public: double GetSurfaceRadius(); + + /// \brief Get the major axis of the surface. + /// \return Equatorial axis of the surface in use. + public: double GetSurfaceAxisEquatorial(); + + /// \brief Get the minor axis of the surface. + /// \return Polar axis of the surface in use. + public: double GetSurfaceAxisPolar(); + + /// \brief Get the flattening of the surface. + /// \return Flattening parameter of the surface in use. + public: double GetSurfaceFlattening(); + /// \brief Get reference geodetic latitude. /// \return Reference geodetic latitude. public: gz::math::Angle LatitudeReference() const; diff --git a/src/SphericalCoordinates.cc b/src/SphericalCoordinates.cc index 6c5c564e1..7a970b177 100644 --- a/src/SphericalCoordinates.cc +++ b/src/SphericalCoordinates.cc @@ -485,6 +485,30 @@ double SphericalCoordinates::DistanceBetweenPoints( return -1; } +////////////////////////////////////////////////// +double SphericalCoordinates::GetSurfaceRadius() +{ + return this->dataPtr->surfaceRadius; +} + +////////////////////////////////////////////////// +double SphericalCoordinates::GetSurfaceAxisEquatorial() +{ + return this->dataPtr->ellA; +} + +////////////////////////////////////////////////// +double SphericalCoordinates::GetSurfaceAxisPolar() +{ + return this->dataPtr->ellB; +} + +////////////////////////////////////////////////// +double SphericalCoordinates::GetSurfaceFlattening() +{ + return this->dataPtr->ellF; +} + ////////////////////////////////////////////////// void SphericalCoordinates::UpdateTransformationMatrix() { diff --git a/src/SphericalCoordinates_TEST.cc b/src/SphericalCoordinates_TEST.cc index 0d9f23fb5..c12dae503 100644 --- a/src/SphericalCoordinates_TEST.cc +++ b/src/SphericalCoordinates_TEST.cc @@ -86,6 +86,11 @@ TEST(SphericalCoordinatesTest, Convert) st = math::SphericalCoordinates::MOON_SCS; EXPECT_EQ(math::SphericalCoordinates::Convert("MOON_SCS"), st); EXPECT_EQ("MOON_SCS", math::SphericalCoordinates::Convert(st)); + + // For the custom surface type + st = math::SphericalCoordinates::CUSTOM_SURFACE; + EXPECT_EQ(math::SphericalCoordinates::Convert("CUSTOM_SURFACE"), st); + EXPECT_EQ("CUSTOM_SURFACE", math::SphericalCoordinates::Convert(st)); } ////////////////////////////////////////////////// @@ -119,6 +124,39 @@ TEST(SphericalCoordinatesTest, SetFunctions) EXPECT_EQ(sc.HeadingOffset(), heading); EXPECT_NEAR(sc.ElevationReference(), elev, 1e-6); } + + // Moon surface type + st = math::SphericalCoordinates::MOON_SCS; + math::SphericalCoordinates moonSC(st); + moonSC.SetSurface(st); + EXPECT_EQ(moonSC.Surface(), st); +} + +////////////////////////////////////////////////// +/// Test invalid parameters for custom surface +TEST(SphericalCoordinatesTest, InvalidParameters) +{ + // Earth's constants + double g_EarthWGS84AxisEquatorial = 6378137.0; + double g_EarthWGS84AxisPolar = 6356752.314245; + double g_EarthWGS84Flattening = 1.0/298.257223563; + double g_EarthRadius = 6371000.0; + + // Create a custom surface with invalid parameters. + math::SphericalCoordinates sc( + math::SphericalCoordinates::CUSTOM_SURFACE, + -1, -1, -1, -1); + + // These should be rejected and default to Earth's + // parameters. + EXPECT_NEAR(sc.GetSurfaceRadius(), g_EarthRadius, + 1e-3); + EXPECT_NEAR(sc.GetSurfaceAxisEquatorial(), + g_EarthWGS84AxisEquatorial, 1e-3); + EXPECT_NEAR(sc.GetSurfaceAxisPolar(), + g_EarthWGS84AxisPolar, 1e-3); + EXPECT_NEAR(sc.GetSurfaceFlattening(), + g_EarthWGS84Flattening, 1e-3); } ////////////////////////////////////////////////// From a66fd7b9921990afca5db48e5c2fc299ef5e4336 Mon Sep 17 00:00:00 2001 From: Aditya Date: Mon, 13 Jun 2022 17:40:20 -0700 Subject: [PATCH 09/25] Added tests, pybind update Signed-off-by: Aditya --- src/SphericalCoordinates.cc | 22 +++++----------- src/SphericalCoordinates_TEST.cc | 25 +++++++++++++++---- .../src/SphericalCoordinates.cc | 12 +++++++++ 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/SphericalCoordinates.cc b/src/SphericalCoordinates.cc index 7a970b177..8d177f91c 100644 --- a/src/SphericalCoordinates.cc +++ b/src/SphericalCoordinates.cc @@ -320,9 +320,9 @@ void SphericalCoordinates::SetSurface( const double _axisPolar, const double _flattening) { - if (_type != EARTH_WGS84 || - _type != MOON_SCS || - _type != CUSTOM_SURFACE) + if ((_type != EARTH_WGS84) && + (_type != MOON_SCS) && + (_type != CUSTOM_SURFACE)) { std::cerr << "Unknown surface type[" << _type << "]\n"; @@ -352,7 +352,7 @@ void SphericalCoordinates::SetSurface( this->dataPtr->ellB = g_EarthWGS84AxisPolar; } - if (_flattening > 0) + if (_flattening >= 0) { this->dataPtr->ellF = _flattening; } @@ -471,18 +471,8 @@ double SphericalCoordinates::DistanceBetweenPoints( cos(_latA.Radian()) * cos(_latB.Radian()); double c = 2 * atan2(sqrt(a), sqrt(1 - a)); - if ( this->dataPtr->surfaceRadius > 0 ) - { - double d = this->dataPtr->surfaceRadius * c; - return d; - } - else - { - std::cerr << "Surface radius is invalid or not set for the given " - "surface type" << std::endl; - } - - return -1; + double d = this->dataPtr->surfaceRadius * c; + return d; } ////////////////////////////////////////////////// diff --git a/src/SphericalCoordinates_TEST.cc b/src/SphericalCoordinates_TEST.cc index c12dae503..dadfae5ef 100644 --- a/src/SphericalCoordinates_TEST.cc +++ b/src/SphericalCoordinates_TEST.cc @@ -143,20 +143,35 @@ TEST(SphericalCoordinatesTest, InvalidParameters) double g_EarthRadius = 6371000.0; // Create a custom surface with invalid parameters. - math::SphericalCoordinates sc( + math::SphericalCoordinates scInvalid( math::SphericalCoordinates::CUSTOM_SURFACE, -1, -1, -1, -1); // These should be rejected and default to Earth's // parameters. - EXPECT_NEAR(sc.GetSurfaceRadius(), g_EarthRadius, + EXPECT_NEAR(scInvalid.GetSurfaceRadius(), g_EarthRadius, 1e-3); - EXPECT_NEAR(sc.GetSurfaceAxisEquatorial(), + EXPECT_NEAR(scInvalid.GetSurfaceAxisEquatorial(), g_EarthWGS84AxisEquatorial, 1e-3); - EXPECT_NEAR(sc.GetSurfaceAxisPolar(), + EXPECT_NEAR(scInvalid.GetSurfaceAxisPolar(), g_EarthWGS84AxisPolar, 1e-3); - EXPECT_NEAR(sc.GetSurfaceFlattening(), + EXPECT_NEAR(scInvalid.GetSurfaceFlattening(), g_EarthWGS84Flattening, 1e-3); + + // Create a custom surface with valid parameters. + math::SphericalCoordinates scValid( + math::SphericalCoordinates::CUSTOM_SURFACE, + 100, 100, 100, 0); + + // These should be accepted + EXPECT_NEAR(scValid.GetSurfaceRadius(), 100, + 1e-3); + EXPECT_NEAR(scValid.GetSurfaceAxisEquatorial(), + 100, 1e-3); + EXPECT_NEAR(scValid.GetSurfaceAxisPolar(), + 100, 1e-3); + EXPECT_NEAR(scValid.GetSurfaceFlattening(), + 0, 1e-3); } ////////////////////////////////////////////////// diff --git a/src/python_pybind11/src/SphericalCoordinates.cc b/src/python_pybind11/src/SphericalCoordinates.cc index 88b36d485..788f96c90 100644 --- a/src/python_pybind11/src/SphericalCoordinates.cc +++ b/src/python_pybind11/src/SphericalCoordinates.cc @@ -74,6 +74,18 @@ void defineMathSphericalCoordinates(py::module &m, const std::string &typestr) .def("surface", &Class::Surface, "Get SurfaceType currently in use.") + .def("get_surface_radius", + &Class::GetSurfaceRadius, + "Get the radius of the surface.") + .def("get_surface_axis_equatorial", + &Class::GetSurfaceAxisEquatorial, + "Get the major of the surface.") + .def("get_surface_axis_polar", + &Class::GetSurfaceAxisPolar, + "Get the minor axis of the surface.") + .def("get_surface_flattening", + &Class::GetSurfaceFlattening, + "Get the flattening parameter of the surface.") .def("latitude_reference", &Class::LatitudeReference, "Get reference geodetic latitude.") From 5f3668c59e3ac35b6f228bf896d3cc45f94ba62f Mon Sep 17 00:00:00 2001 From: Aditya Date: Mon, 13 Jun 2022 20:39:11 -0700 Subject: [PATCH 10/25] Add invalid surface tests Signed-off-by: Aditya --- src/SphericalCoordinates_TEST.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/SphericalCoordinates_TEST.cc b/src/SphericalCoordinates_TEST.cc index dadfae5ef..cb3288662 100644 --- a/src/SphericalCoordinates_TEST.cc +++ b/src/SphericalCoordinates_TEST.cc @@ -391,6 +391,11 @@ TEST(SphericalCoordinatesTest, Distance) EXPECT_NEAR(3820, d4, 5); // Using a custom surface. + // For custom surfaces, the surface properties need to be set. + // THis one will throw an error. + auto invalidCustomSC = math::SphericalCoordinates( + math::SphericalCoordinates::CUSTOM_SURFACE); + // This one should be accepted. auto customSC = math::SphericalCoordinates( math::SphericalCoordinates::SurfaceType::CUSTOM_SURFACE, 6371000.0, @@ -406,6 +411,8 @@ TEST(SphericalCoordinatesTest, Distance) TEST(SphericalCoordinatesTest, BadSetSurface) { math::SphericalCoordinates sc; + sc.SetSurface(static_cast(3), + 10, 10, 0); sc.SetSurface(static_cast(3)); EXPECT_EQ(sc.Surface(), 3); } From 0a30e5ae20b661b2e7d761a994e605febe4b72b4 Mon Sep 17 00:00:00 2001 From: Aditya Date: Tue, 14 Jun 2022 15:50:12 -0700 Subject: [PATCH 11/25] Added test for constructor Signed-off-by: Aditya --- src/SphericalCoordinates_TEST.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/SphericalCoordinates_TEST.cc b/src/SphericalCoordinates_TEST.cc index cb3288662..36c6466e3 100644 --- a/src/SphericalCoordinates_TEST.cc +++ b/src/SphericalCoordinates_TEST.cc @@ -63,6 +63,11 @@ TEST(SphericalCoordinatesTest, Constructor) math::SphericalCoordinates sc2(sc); EXPECT_EQ(sc, sc2); } + + // Bad surface type, this should throw an error + math::SphericalCoordinates invalidSC( + static_cast(3)); + EXPECT_EQ(invalidSC.Surface(), 3); } ////////////////////////////////////////////////// From 723b454920851387442d007060ea8da7b52b2e07 Mon Sep 17 00:00:00 2001 From: Aditya Date: Wed, 15 Jun 2022 00:19:58 -0700 Subject: [PATCH 12/25] Deprecated and renamed the static Distance() function Signed-off-by: Aditya --- include/gz/math/SphericalCoordinates.hh | 20 +++++++++++++++++++- src/SphericalCoordinates.cc | 13 ++++++++++++- src/SphericalCoordinates_TEST.cc | 3 ++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/include/gz/math/SphericalCoordinates.hh b/include/gz/math/SphericalCoordinates.hh index 17c4da517..79bc71399 100644 --- a/include/gz/math/SphericalCoordinates.hh +++ b/include/gz/math/SphericalCoordinates.hh @@ -158,7 +158,25 @@ namespace gz /// \param[in] _latB Latitude of point B. /// \param[in] _lonB Longitude of point B. /// \return Distance in meters. - public: static double Distance(const gz::math::Angle &_latA, + /// \deprecated Use DistanceWGS84 instead. + public: GZ_DEPRECATED(7) static double Distance( + const gz::math::Angle &_latA, + const gz::math::Angle &_lonA, + const gz::math::Angle &_latB, + const gz::math::Angle &_lonB); + + /// \brief Get the distance between two points expressed in geographic + /// latitude and longitude. It assumes that both points are at sea level. + /// Example: _latA = 38.0016667 and _lonA = -123.0016667) represents + /// the point with latitude 38d 0'6.00"N and longitude 123d 0'6.00"W. + /// This method assumes that the surface model is EARTH_WGS84. + /// \param[in] _latA Latitude of point A. + /// \param[in] _lonA Longitude of point A. + /// \param[in] _latB Latitude of point B. + /// \param[in] _lonB Longitude of point B. + /// \return Distance in meters. + public: static double DistanceWGS84( + const gz::math::Angle &_latA, const gz::math::Angle &_lonA, const gz::math::Angle &_latB, const gz::math::Angle &_lonB); diff --git a/src/SphericalCoordinates.cc b/src/SphericalCoordinates.cc index 8d177f91c..885f0c025 100644 --- a/src/SphericalCoordinates.cc +++ b/src/SphericalCoordinates.cc @@ -437,7 +437,7 @@ gz::math::Vector3d SphericalCoordinates::LocalFromGlobalVelocity( ////////////////////////////////////////////////// /// Based on Haversine formula (http://en.wikipedia.org/wiki/Haversine_formula). -double SphericalCoordinates::Distance(const gz::math::Angle &_latA, +double SphericalCoordinates::DistanceWGS84(const gz::math::Angle &_latA, const gz::math::Angle &_lonA, const gz::math::Angle &_latB, const gz::math::Angle &_lonB) @@ -454,6 +454,17 @@ double SphericalCoordinates::Distance(const gz::math::Angle &_latA, return d; } +////////////////////////////////////////////////// +/// Based on Haversine formula (http://en.wikipedia.org/wiki/Haversine_formula). +double SphericalCoordinates::Distance(const gz::math::Angle &_latA, + const gz::math::Angle &_lonA, + const gz::math::Angle &_latB, + const gz::math::Angle &_lonB) +{ + return gz::math::SphericalCoordinates::DistanceWGS84( + _latA, _lonA, _latB, _lonB); +} + ////////////////////////////////////////////////// /// Based on Haversine formula (http://en.wikipedia.org/wiki/Haversine_formula). /// This takes into account the surface type. diff --git a/src/SphericalCoordinates_TEST.cc b/src/SphericalCoordinates_TEST.cc index 36c6466e3..3e65a9d61 100644 --- a/src/SphericalCoordinates_TEST.cc +++ b/src/SphericalCoordinates_TEST.cc @@ -376,7 +376,8 @@ TEST(SphericalCoordinatesTest, Distance) longB.SetDegree(-122.251683); // Calculating distance using the static method. - double d1 = math::SphericalCoordinates::Distance(latA, longA, latB, longB); + double d1 = math::SphericalCoordinates::DistanceWGS84( + latA, longA, latB, longB); EXPECT_NEAR(14002, d1, 20); // Using the non static method. The default surface type is EARTH_WGS84. From 243b673579d98863ec7f933107a2159162e3e7b8 Mon Sep 17 00:00:00 2001 From: Aditya Date: Wed, 15 Jun 2022 00:39:41 -0700 Subject: [PATCH 13/25] Fixed pybind warnings Signed-off-by: Aditya --- src/python_pybind11/src/SphericalCoordinates.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/python_pybind11/src/SphericalCoordinates.cc b/src/python_pybind11/src/SphericalCoordinates.cc index 788f96c90..6e0f0ba9c 100644 --- a/src/python_pybind11/src/SphericalCoordinates.cc +++ b/src/python_pybind11/src/SphericalCoordinates.cc @@ -59,13 +59,14 @@ void defineMathSphericalCoordinates(py::module &m, const std::string &typestr) .def("convert", py::overload_cast(&Class::Convert), "Convert a SurfaceType to a string.") - .def("distance", - &Class::Distance, + .def("distance_WGS84", + &Class::DistanceWGS84, "Get the distance between two points expressed in geographic " "latitude and longitude. It assumes that both points are at sea level." " Example: _latA = 38.0016667 and _lonA = -123.0016667) represents " - "the point with latitude 38d 0'6.00\"N and longitude 123d 0'6.00\"W.") - .def("distance", + "the point with latitude 38d 0'6.00\"N and longitude 123d 0'6.00\"W." + " This function assumes the surface is EARTH_WGS84.") + .def("distance_between_points", &Class::DistanceBetweenPoints, "Get the distance between two points expressed in geographic " "latitude and longitude. It assumes that both points are at sea level." From 8a30e0741278ea237fd379d13265ee4d4093f80f Mon Sep 17 00:00:00 2001 From: Aditya Date: Wed, 15 Jun 2022 09:16:02 -0700 Subject: [PATCH 14/25] Fixed broken pybind test Signed-off-by: Aditya --- src/python_pybind11/test/SphericalCoordinates_TEST.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_pybind11/test/SphericalCoordinates_TEST.py b/src/python_pybind11/test/SphericalCoordinates_TEST.py index 50a52ef96..baffa1bf9 100644 --- a/src/python_pybind11/test/SphericalCoordinates_TEST.py +++ b/src/python_pybind11/test/SphericalCoordinates_TEST.py @@ -263,7 +263,7 @@ def test_distance(self): longA.set_degree(-122.249972) latB.set_degree(46.124953) longB.set_degree(-122.251683) - d = SphericalCoordinates.distance(latA, longA, latB, longB) + d = SphericalCoordinates.distance_WGS84(latA, longA, latB, longB) self.assertAlmostEqual(14002, d, delta=20) From b1baee53f003c614bfeec7c28afb2458a82cd7bc Mon Sep 17 00:00:00 2001 From: Aditya Date: Thu, 16 Jun 2022 12:22:25 -0700 Subject: [PATCH 15/25] Updaed Migration.md, renamed methods, updated error msgs Signed-off-by: Aditya --- Migration.md | 4 ++++ include/gz/math/SphericalCoordinates.hh | 8 ++++---- src/SphericalCoordinates.cc | 15 ++++++++------- src/SphericalCoordinates_TEST.cc | 16 ++++++++-------- src/python_pybind11/src/SphericalCoordinates.cc | 8 ++++---- 5 files changed, 28 insertions(+), 23 deletions(-) diff --git a/Migration.md b/Migration.md index 9ab36ad94..26b4d3cca 100644 --- a/Migration.md +++ b/Migration.md @@ -18,6 +18,10 @@ release will remove the deprecated code. + All mutator functions that lacked a `Set` prefix have been deprecated and replaced by version with a `Set` prefix. +1. **SphericalCoordinates.hh** + + ***Deprecation:*** public: static double Distance(const Angle&, const Angle&, const Angle&, const Angle&) + + ***Replacement:*** public: static double DistanceWGS84(const Angle&, const Angle&, const Angle&, const Angle&) + 1. **Matrix3.hh** + ***Deprecation:*** public: void Axes(const Vector3 &, const Vector3 &, const Vector3 &) + ***Replacement:*** public: void SetAxes(const Vector3 &, const Vector3 &, const Vector3 &) diff --git a/include/gz/math/SphericalCoordinates.hh b/include/gz/math/SphericalCoordinates.hh index 79bc71399..67e41152b 100644 --- a/include/gz/math/SphericalCoordinates.hh +++ b/include/gz/math/SphericalCoordinates.hh @@ -204,19 +204,19 @@ namespace gz /// \brief Get the radius of the surface. /// \return radius of the surface in use. - public: double GetSurfaceRadius(); + public: double SurfaceRadius(); /// \brief Get the major axis of the surface. /// \return Equatorial axis of the surface in use. - public: double GetSurfaceAxisEquatorial(); + public: double SurfaceAxisEquatorial(); /// \brief Get the minor axis of the surface. /// \return Polar axis of the surface in use. - public: double GetSurfaceAxisPolar(); + public: double SurfaceAxisPolar(); /// \brief Get the flattening of the surface. /// \return Flattening parameter of the surface in use. - public: double GetSurfaceFlattening(); + public: double SurfaceFlattening(); /// \brief Get reference geodetic latitude. /// \return Reference geodetic latitude. diff --git a/src/SphericalCoordinates.cc b/src/SphericalCoordinates.cc index 885f0c025..a11274d67 100644 --- a/src/SphericalCoordinates.cc +++ b/src/SphericalCoordinates.cc @@ -191,7 +191,7 @@ SphericalCoordinates::SphericalCoordinates( else { std::cerr << "Value of _radius should be greater than zero " - " defaulting to Earth's flattening value."<< std::endl; + " defaulting to Earth's radius."<< std::endl; this->dataPtr->surfaceRadius = g_EarthRadius; } @@ -358,8 +358,9 @@ void SphericalCoordinates::SetSurface( } else { - std::cerr << "Value of _flattening should be greater than zero " - " defaulting to Earth's flattening value."<< std::endl; + std::cerr << "Value of _flattening should be greater than " + " or equal to zero, defaulting to Earth's flattening value." + << std::endl; this->dataPtr->ellF = g_EarthWGS84Flattening; } @@ -487,25 +488,25 @@ double SphericalCoordinates::DistanceBetweenPoints( } ////////////////////////////////////////////////// -double SphericalCoordinates::GetSurfaceRadius() +double SphericalCoordinates::SurfaceRadius() { return this->dataPtr->surfaceRadius; } ////////////////////////////////////////////////// -double SphericalCoordinates::GetSurfaceAxisEquatorial() +double SphericalCoordinates::SurfaceAxisEquatorial() { return this->dataPtr->ellA; } ////////////////////////////////////////////////// -double SphericalCoordinates::GetSurfaceAxisPolar() +double SphericalCoordinates::SurfaceAxisPolar() { return this->dataPtr->ellB; } ////////////////////////////////////////////////// -double SphericalCoordinates::GetSurfaceFlattening() +double SphericalCoordinates::SurfaceFlattening() { return this->dataPtr->ellF; } diff --git a/src/SphericalCoordinates_TEST.cc b/src/SphericalCoordinates_TEST.cc index 3e65a9d61..782510b14 100644 --- a/src/SphericalCoordinates_TEST.cc +++ b/src/SphericalCoordinates_TEST.cc @@ -154,13 +154,13 @@ TEST(SphericalCoordinatesTest, InvalidParameters) // These should be rejected and default to Earth's // parameters. - EXPECT_NEAR(scInvalid.GetSurfaceRadius(), g_EarthRadius, + EXPECT_NEAR(scInvalid.SurfaceRadius(), g_EarthRadius, 1e-3); - EXPECT_NEAR(scInvalid.GetSurfaceAxisEquatorial(), + EXPECT_NEAR(scInvalid.SurfaceAxisEquatorial(), g_EarthWGS84AxisEquatorial, 1e-3); - EXPECT_NEAR(scInvalid.GetSurfaceAxisPolar(), + EXPECT_NEAR(scInvalid.SurfaceAxisPolar(), g_EarthWGS84AxisPolar, 1e-3); - EXPECT_NEAR(scInvalid.GetSurfaceFlattening(), + EXPECT_NEAR(scInvalid.SurfaceFlattening(), g_EarthWGS84Flattening, 1e-3); // Create a custom surface with valid parameters. @@ -169,13 +169,13 @@ TEST(SphericalCoordinatesTest, InvalidParameters) 100, 100, 100, 0); // These should be accepted - EXPECT_NEAR(scValid.GetSurfaceRadius(), 100, + EXPECT_NEAR(scValid.SurfaceRadius(), 100, 1e-3); - EXPECT_NEAR(scValid.GetSurfaceAxisEquatorial(), + EXPECT_NEAR(scValid.SurfaceAxisEquatorial(), 100, 1e-3); - EXPECT_NEAR(scValid.GetSurfaceAxisPolar(), + EXPECT_NEAR(scValid.SurfaceAxisPolar(), 100, 1e-3); - EXPECT_NEAR(scValid.GetSurfaceFlattening(), + EXPECT_NEAR(scValid.SurfaceFlattening(), 0, 1e-3); } diff --git a/src/python_pybind11/src/SphericalCoordinates.cc b/src/python_pybind11/src/SphericalCoordinates.cc index 6e0f0ba9c..ae21944ab 100644 --- a/src/python_pybind11/src/SphericalCoordinates.cc +++ b/src/python_pybind11/src/SphericalCoordinates.cc @@ -76,16 +76,16 @@ void defineMathSphericalCoordinates(py::module &m, const std::string &typestr) &Class::Surface, "Get SurfaceType currently in use.") .def("get_surface_radius", - &Class::GetSurfaceRadius, + &Class::SurfaceRadius, "Get the radius of the surface.") .def("get_surface_axis_equatorial", - &Class::GetSurfaceAxisEquatorial, + &Class::SurfaceAxisEquatorial, "Get the major of the surface.") .def("get_surface_axis_polar", - &Class::GetSurfaceAxisPolar, + &Class::SurfaceAxisPolar, "Get the minor axis of the surface.") .def("get_surface_flattening", - &Class::GetSurfaceFlattening, + &Class::SurfaceFlattening, "Get the flattening parameter of the surface.") .def("latitude_reference", &Class::LatitudeReference, From 765b8d9286ae44a856a61269e5c28bc159e3589b Mon Sep 17 00:00:00 2001 From: Aditya Date: Thu, 16 Jun 2022 12:39:12 -0700 Subject: [PATCH 16/25] Set radius in SetSurface method Signed-off-by: Aditya --- include/gz/math/SphericalCoordinates.hh | 1 + src/SphericalCoordinates.cc | 47 ++++++++----------- src/SphericalCoordinates_TEST.cc | 2 +- .../src/SphericalCoordinates.cc | 2 +- 4 files changed, 22 insertions(+), 30 deletions(-) diff --git a/include/gz/math/SphericalCoordinates.hh b/include/gz/math/SphericalCoordinates.hh index 67e41152b..9b9eb57a3 100644 --- a/include/gz/math/SphericalCoordinates.hh +++ b/include/gz/math/SphericalCoordinates.hh @@ -248,6 +248,7 @@ namespace gz /// \param[in] _flattening Falttening parameter of the surface. public: void SetSurface( const SurfaceType &_type, + const double _radius, const double _axisEquatorial, const double _axisPolar, const double _flattening); diff --git a/src/SphericalCoordinates.cc b/src/SphericalCoordinates.cc index a11274d67..a73e0ef87 100644 --- a/src/SphericalCoordinates.cc +++ b/src/SphericalCoordinates.cc @@ -144,7 +144,6 @@ SphericalCoordinates::SphericalCoordinates() : dataPtr(gz::utils::MakeImpl()) { this->SetSurface(EARTH_WGS84); - this->dataPtr->surfaceRadius = g_EarthRadius; this->SetElevationReference(0.0); } @@ -153,21 +152,6 @@ SphericalCoordinates::SphericalCoordinates(const SurfaceType _type) : SphericalCoordinates() { this->SetSurface(_type); - switch(_type) - { - case EARTH_WGS84: - this->dataPtr->surfaceRadius = g_EarthRadius; - break; - case MOON_SCS: - this->dataPtr->surfaceRadius = g_MoonRadius; - break; - case CUSTOM_SURFACE: - std::cerr << "Please supply ellipsoidal properties with the " - "custom surface." << std::endl; - break; - default: - std::cerr << "Unknown surface type [" << _type << "]" << std::endl; - } this->SetElevationReference(0.0); } @@ -181,20 +165,9 @@ SphericalCoordinates::SphericalCoordinates( : SphericalCoordinates() { // Set properties - this->SetSurface(_type, _axisEquatorial, + this->SetSurface(_type, _radius, _axisEquatorial, _axisPolar, _flattening); - if (_radius > 0) - { - this->dataPtr->surfaceRadius = _radius; - } - else - { - std::cerr << "Value of _radius should be greater than zero " - " defaulting to Earth's radius."<< std::endl; - this->dataPtr->surfaceRadius = g_EarthRadius; - } - this->SetElevationReference(0.0); } @@ -278,6 +251,9 @@ void SphericalCoordinates::SetSurface(const SurfaceType &_type) std::pow(this->dataPtr->ellA, 2) / std::pow(this->dataPtr->ellB, 2) - 1.0); + // Set the radius of the surface. + this->dataPtr->surfaceRadius = g_EarthRadius; + break; } case MOON_SCS: @@ -302,6 +278,9 @@ void SphericalCoordinates::SetSurface(const SurfaceType &_type) std::pow(this->dataPtr->ellA, 2) / std::pow(this->dataPtr->ellB, 2) - 1.0); + // Set the radius of the surface. + this->dataPtr->surfaceRadius = g_MoonRadius; + break; } default: @@ -316,6 +295,7 @@ void SphericalCoordinates::SetSurface(const SurfaceType &_type) ////////////////////////////////////////////////// void SphericalCoordinates::SetSurface( const SurfaceType &_type, + const double _radius, const double _axisEquatorial, const double _axisPolar, const double _flattening) @@ -364,6 +344,17 @@ void SphericalCoordinates::SetSurface( this->dataPtr->ellF = g_EarthWGS84Flattening; } + if (_radius > 0) + { + this->dataPtr->surfaceRadius = _radius; + } + else + { + std::cerr << "Value of _radius should be greater than zero " + " defaulting to Earth's radius."<< std::endl; + this->dataPtr->surfaceRadius = g_EarthRadius; + } + this->dataPtr->ellE = sqrt(1.0 - std::pow(this->dataPtr->ellB, 2) / std::pow(this->dataPtr->ellA, 2)); this->dataPtr->ellP = sqrt( diff --git a/src/SphericalCoordinates_TEST.cc b/src/SphericalCoordinates_TEST.cc index 782510b14..f1fa97c61 100644 --- a/src/SphericalCoordinates_TEST.cc +++ b/src/SphericalCoordinates_TEST.cc @@ -418,7 +418,7 @@ TEST(SphericalCoordinatesTest, BadSetSurface) { math::SphericalCoordinates sc; sc.SetSurface(static_cast(3), - 10, 10, 0); + 10, 10, 10, 0); sc.SetSurface(static_cast(3)); EXPECT_EQ(sc.Surface(), 3); } diff --git a/src/python_pybind11/src/SphericalCoordinates.cc b/src/python_pybind11/src/SphericalCoordinates.cc index ae21944ab..23deff49a 100644 --- a/src/python_pybind11/src/SphericalCoordinates.cc +++ b/src/python_pybind11/src/SphericalCoordinates.cc @@ -107,7 +107,7 @@ void defineMathSphericalCoordinates(py::module &m, const std::string &typestr) .def("set_surface", py::overload_cast(&Class::SetSurface), + const double, const double>(&Class::SetSurface), "Set SurfaceType for planetary surface model.") .def("set_latitude_reference", &Class::SetLatitudeReference, From c487de33a152c1375deb5a69ab266cc6e24ec9e8 Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Thu, 16 Jun 2022 14:34:49 -0700 Subject: [PATCH 17/25] [ign -> gz] CMake functions (#441) Signed-off-by: Louise Poubel --- CMakeLists.txt | 12 ++++++------ eigen3/include/gz/math/CMakeLists.txt | 3 +-- eigen3/src/CMakeLists.txt | 7 +++---- include/gz/math/CMakeLists.txt | 2 +- src/CMakeLists.txt | 6 +++--- src/graph/CMakeLists.txt | 4 ++-- test/integration/CMakeLists.txt | 4 ++-- test/performance/CMakeLists.txt | 2 +- test/regression/CMakeLists.txt | 2 +- 9 files changed, 20 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d7e08cef..b5f4ba639 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ find_package(ignition-cmake3 REQUIRED) #============================================================================ set (c++standard 17) set (CMAKE_CXX_STANDARD 17) -ign_configure_project( +gz_configure_project( REPLACE_IGNITION_INCLUDE_PATH gz/math VERSION_SUFFIX pre1) @@ -42,12 +42,12 @@ option(USE_DIST_PACKAGES_FOR_PYTHON #-------------------------------------- # Find ignition-utils -ign_find_package(ignition-utils2 REQUIRED) +gz_find_package(ignition-utils2 REQUIRED) set(IGN_UTILS_VER ${ignition-utils2_VERSION_MAJOR}) #-------------------------------------- # Find eigen3 -ign_find_package( +gz_find_package( EIGEN3 REQUIRED_BY eigen3 PRETTY eigen3 @@ -105,14 +105,14 @@ set(FAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/fake/install") #============================================================================ # Configure the build #============================================================================ -ign_configure_build(QUIT_IF_BUILD_ERRORS +gz_configure_build(QUIT_IF_BUILD_ERRORS COMPONENTS eigen3) #============================================================================ # Create package information #============================================================================ -ign_create_packages() +gz_create_packages() #============================================================================ # Configure documentation @@ -120,6 +120,6 @@ ign_create_packages() configure_file(${CMAKE_SOURCE_DIR}/api.md.in ${CMAKE_BINARY_DIR}/api.md) configure_file(${CMAKE_SOURCE_DIR}/tutorials.md.in ${CMAKE_BINARY_DIR}/tutorials.md) -ign_create_docs( +gz_create_docs( API_MAINPAGE_MD "${CMAKE_BINARY_DIR}/api.md" TUTORIALS_MAINPAGE_MD "${CMAKE_BINARY_DIR}/tutorials.md") diff --git a/eigen3/include/gz/math/CMakeLists.txt b/eigen3/include/gz/math/CMakeLists.txt index 68a87c4fe..1128e2c6e 100644 --- a/eigen3/include/gz/math/CMakeLists.txt +++ b/eigen3/include/gz/math/CMakeLists.txt @@ -1,2 +1 @@ - -ign_install_all_headers(COMPONENT eigen3) +gz_install_all_headers(COMPONENT eigen3) diff --git a/eigen3/src/CMakeLists.txt b/eigen3/src/CMakeLists.txt index 78a06082e..e3a610516 100644 --- a/eigen3/src/CMakeLists.txt +++ b/eigen3/src/CMakeLists.txt @@ -1,14 +1,13 @@ - -ign_add_component(eigen3 INTERFACE +gz_add_component(eigen3 INTERFACE GET_TARGET_NAME component) target_link_libraries(${component} INTERFACE Eigen3::Eigen) # Collect source files into the "sources" variable and unit test files into the # "gtest_sources" variable -ign_get_libsources_and_unittests(sources gtest_sources) +gz_get_libsources_and_unittests(sources gtest_sources) # Build the unit tests -ign_build_tests(TYPE UNIT SOURCES ${gtest_sources} +gz_build_tests(TYPE UNIT SOURCES ${gtest_sources} LIB_DEPS ${component}) diff --git a/include/gz/math/CMakeLists.txt b/include/gz/math/CMakeLists.txt index ef62a88a5..b0ebcadc8 100644 --- a/include/gz/math/CMakeLists.txt +++ b/include/gz/math/CMakeLists.txt @@ -1,3 +1,3 @@ # Exclude the detail directory from inclusion. The purpose is to prevent the detail/* header files from being included in math.hh. A side effect is that the detail headers are not installed. The next install line solves this problem. -ign_install_all_headers(EXCLUDE_DIRS detail) +gz_install_all_headers(EXCLUDE_DIRS detail) install(DIRECTORY detail DESTINATION ${IGN_INCLUDE_INSTALL_DIR_FULL}/gz/${IGN_DESIGNATION}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 709d6beb7..fcade4a54 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,10 +1,10 @@ # Collect source files into the "sources" variable and unit test files into the # "gtest_sources" variable -ign_get_libsources_and_unittests(sources gtest_sources) +gz_get_libsources_and_unittests(sources gtest_sources) # Create the library target -ign_create_core_library(SOURCES ${sources} CXX_STANDARD ${c++standard}) +gz_create_core_library(SOURCES ${sources} CXX_STANDARD ${c++standard}) target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME} PUBLIC @@ -12,7 +12,7 @@ target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME} ) # Build the unit tests -ign_build_tests(TYPE UNIT SOURCES ${gtest_sources}) +gz_build_tests(TYPE UNIT SOURCES ${gtest_sources}) # graph namespace add_subdirectory(graph) diff --git a/src/graph/CMakeLists.txt b/src/graph/CMakeLists.txt index 70ba555bd..58a5b3d1e 100644 --- a/src/graph/CMakeLists.txt +++ b/src/graph/CMakeLists.txt @@ -1,7 +1,7 @@ # Collect source files into the "sources" variable and unit test files into the # "gtest_sources" variable -ign_get_libsources_and_unittests(sources gtest_sources) +gz_get_libsources_and_unittests(sources gtest_sources) # Build the unit tests -ign_build_tests(TYPE UNIT SOURCES ${gtest_sources}) +gz_build_tests(TYPE UNIT SOURCES ${gtest_sources}) diff --git a/test/integration/CMakeLists.txt b/test/integration/CMakeLists.txt index b6940585d..bb6ee2848 100644 --- a/test/integration/CMakeLists.txt +++ b/test/integration/CMakeLists.txt @@ -1,6 +1,6 @@ set(TEST_TYPE "INTEGRATION") -ign_get_sources(tests) +gz_get_sources(tests) # Test symbols having the right name on linux only if (UNIX AND NOT APPLE) @@ -9,7 +9,7 @@ if (UNIX AND NOT APPLE) COMMAND bash ${CMAKE_CURRENT_BINARY_DIR}/all_symbols_have_version.bash $) endif() -ign_build_tests(TYPE INTEGRATION SOURCES ${tests}) +gz_build_tests(TYPE INTEGRATION SOURCES ${tests}) if(TARGET INTEGRATION_ExamplesBuild_TEST) add_dependencies(INTEGRATION_ExamplesBuild_TEST FAKE_INSTALL) diff --git a/test/performance/CMakeLists.txt b/test/performance/CMakeLists.txt index 7cf00db61..854be5c54 100644 --- a/test/performance/CMakeLists.txt +++ b/test/performance/CMakeLists.txt @@ -5,4 +5,4 @@ set(tests link_directories(${PROJECT_BINARY_DIR}/test) -ign_build_tests(TYPE PERFORMANCE SOURCES ${tests}) +gz_build_tests(TYPE PERFORMANCE SOURCES ${tests}) diff --git a/test/regression/CMakeLists.txt b/test/regression/CMakeLists.txt index ebbc7da64..aac9ecda7 100644 --- a/test/regression/CMakeLists.txt +++ b/test/regression/CMakeLists.txt @@ -5,4 +5,4 @@ set(tests link_directories(${PROJECT_BINARY_DIR}/test) -ign_build_tests(TYPE REGRESSION SOURCES ${tests}) +gz_build_tests(TYPE REGRESSION SOURCES ${tests}) From d4ca4c45e34e5064999085ef726d51e0d970ef08 Mon Sep 17 00:00:00 2001 From: methylDragon Date: Fri, 17 Jun 2022 15:07:29 -0700 Subject: [PATCH 18/25] ign -> gz Macro Migration : gz-math (#437) Signed-off-by: methylDragon Signed-off-by: Louise Poubel Co-authored-by: Louise Poubel --- Migration.md | 13 +++ examples/diff_drive_odometry.cc | 6 +- examples/helpers_example.cc | 6 +- examples/helpers_example.rb | 6 +- examples/pose3_example.cc | 4 +- examples/pose3_example.rb | 2 +- examples/quaternion_from_euler.cc | 12 +- examples/quaternion_to_euler.cc | 6 +- include/gz/math/Angle.hh | 18 +-- include/gz/math/AxisAlignedBox.hh | 2 +- include/gz/math/DiffDriveOdometry.hh | 6 +- include/gz/math/Filter.hh | 4 +- include/gz/math/Frustum.hh | 2 +- include/gz/math/GaussMarkovProcess.hh | 2 +- include/gz/math/Helpers.hh | 94 ++++++++------- include/gz/math/Inertial.hh | 2 +- include/gz/math/Kmeans.hh | 2 +- include/gz/math/Line2.hh | 2 +- include/gz/math/Line3.hh | 2 +- include/gz/math/MassMatrix3.hh | 22 ++-- include/gz/math/Material.hh | 2 +- include/gz/math/Matrix3.hh | 14 +-- include/gz/math/Matrix4.hh | 18 +-- include/gz/math/PID.hh | 2 +- include/gz/math/Pose3.hh | 2 +- include/gz/math/Quaternion.hh | 6 +- include/gz/math/RollingMean.hh | 2 +- include/gz/math/RotationSpline.hh | 2 +- include/gz/math/SemanticVersion.hh | 2 +- include/gz/math/SphericalCoordinates.hh | 2 +- include/gz/math/Spline.hh | 2 +- include/gz/math/Stopwatch.hh | 2 +- include/gz/math/Temperature.hh | 4 +- include/gz/math/Triangle.hh | 2 +- include/gz/math/Triangle3.hh | 2 +- include/gz/math/Vector2.hh | 4 +- include/gz/math/Vector3.hh | 4 +- include/gz/math/Vector3Stats.hh | 2 +- include/gz/math/Vector4.hh | 4 +- include/gz/math/detail/Capsule.hh | 4 +- include/gz/math/detail/Cylinder.hh | 2 +- include/gz/math/detail/Ellipsoid.hh | 2 +- include/gz/math/detail/Sphere.hh | 4 +- include/ignition/math/Angle.hh | 4 + include/ignition/math/Helpers.hh | 12 ++ src/Angle.cc | 12 +- src/Angle_TEST.cc | 20 ++-- src/AxisAlignedBox_TEST.cc | 6 +- src/Capsule_TEST.cc | 6 +- src/Cylinder_TEST.cc | 2 +- src/DiffDriveOdometry_TEST.cc | 10 +- src/Ellipsoid_TEST.cc | 4 +- src/Frustum.cc | 2 +- src/Frustum_TEST.cc | 116 +++++++++---------- src/Helpers.i | 65 ++++++++--- src/Helpers_TEST.cc | 20 ++-- src/Inertial_TEST.cc | 54 ++++----- src/Line3_TEST.cc | 2 +- src/MassMatrix3_TEST.cc | 42 +++---- src/Matrix3_TEST.cc | 2 +- src/Matrix4_TEST.cc | 18 +-- src/OrientedBox_TEST.cc | 2 +- src/Pose_TEST.cc | 30 ++--- src/Quaternion_TEST.cc | 42 +++---- src/Sphere_TEST.cc | 2 +- src/SphericalCoordinates.cc | 8 +- src/SphericalCoordinates_TEST.cc | 10 +- src/Vector2_TEST.cc | 2 +- src/python_pybind11/src/Angle.cc | 6 +- src/python_pybind11/src/Helpers.cc | 100 +++++++++++++--- src/python_pybind11/src/Inertial.hh | 2 +- src/python_pybind11/src/MassMatrix3.hh | 8 +- src/python_pybind11/test/Helpers_TEST.py | 20 ++-- src/python_pybind11/test/MassMatrix3_TEST.py | 50 ++++---- src/ruby/Helpers.i | 79 +++++++++---- src/ruby/Inertial.i | 2 +- src/ruby/MassMatrix3.i | 12 +- 77 files changed, 622 insertions(+), 453 deletions(-) diff --git a/Migration.md b/Migration.md index 26b4d3cca..e6b1c142e 100644 --- a/Migration.md +++ b/Migration.md @@ -73,6 +73,19 @@ release will remove the deprecated code. 1. The `ignition` namespace is deprecated and will be removed in future versions. Use `gz` instead. 1. Header files under `ignition/...` are deprecated and will be removed in future versions. Use `gz/...` instead. +1. The following `IGN_` prefixed macros are deprecated and will be removed in future versions. + Additionally, they will only be available when including the corresponding `ignition/...` header. + Use the `GZ_` prefix instead. + 1. `IGN_RTOD`, `IGN_DTOR` + 1. `IGN_NORMALIZE` + 1. `IGN_PI`, `IGN_PI_2`, `IGN_PI_4` + 1. `IGN_SQRT2` + 1. `IGN_FP_VOLATILE` + 1. `IGN_SPHERE_VOLUME`, `IGN_CYLINDER_VOLUME`, `IGN_BOX_VOLUME`, `IGN_BOX_VOLUME_V` + 1. `IGN_MASSMATRIX3_DEFAULT_TOLERANCE` +1. All `IGN_*_SIZE_T` variables are deprecated and will be removed in future versions. + Please use `GZ_*_SIZE_T` instead. + ### Modifications diff --git a/examples/diff_drive_odometry.cc b/examples/diff_drive_odometry.cc index 7b0a2be06..01d0a23c0 100644 --- a/examples/diff_drive_odometry.cc +++ b/examples/diff_drive_odometry.cc @@ -31,7 +31,7 @@ int main(int argc, char **argv) double wheelSeparation = 2.0; double wheelRadius = 0.5; - double wheelCircumference = 2 * IGN_PI * wheelRadius; + double wheelCircumference = 2 * GZ_PI * wheelRadius; // This is the linear distance traveled per degree of wheel rotation. double distPerDegree = wheelCircumference / 360.0; @@ -45,7 +45,7 @@ int main(int argc, char **argv) // position. std::cout << "--- Rotate both wheels by 1 degree. ---" << '\n'; auto time1 = startTime + std::chrono::milliseconds(100); - odom.Update(IGN_DTOR(1.0), IGN_DTOR(1.0), time1); + odom.Update(GZ_DTOR(1.0), GZ_DTOR(1.0), time1); std::cout << "\tLinear velocity:\t" << distPerDegree / 0.1 << " m/s" << "\n\tOdom linear velocity:\t" << odom.LinearVelocity() << " m/s" @@ -62,7 +62,7 @@ int main(int argc, char **argv) << "by 2 degrees ---" << std::endl; auto time2 = time1 + std::chrono::milliseconds(100); - odom.Update(IGN_DTOR(2.0), IGN_DTOR(3.0), time2); + odom.Update(GZ_DTOR(2.0), GZ_DTOR(3.0), time2); std::cout << "The heading should be the arc tangent of the linear distance\n" << "traveled by the right wheel (the left wheel was stationary)\n" diff --git a/examples/helpers_example.cc b/examples/helpers_example.cc index a7ae27632..a75d1f515 100644 --- a/examples/helpers_example.cc +++ b/examples/helpers_example.cc @@ -21,13 +21,13 @@ int main(int argc, char **argv) { std::cout << "The volume of a sphere with r=2 is " - << IGN_SPHERE_VOLUME(2) << std::endl; + << GZ_SPHERE_VOLUME(2) << std::endl; std::cout << "The volume of a cylinder with r=4 and l=5 is " - << IGN_CYLINDER_VOLUME(4, 5) << std::endl; + << GZ_CYLINDER_VOLUME(4, 5) << std::endl; std::cout << "The volume of a box with x=1, y=2, and z=3 is " - << IGN_BOX_VOLUME(1, 2, 3) << std::endl; + << GZ_BOX_VOLUME(1, 2, 3) << std::endl; std::cout << "The result of clamping 2.4 to the range [1,2] is " << gz::math::clamp(2.4f, 1.0f, 2.0f) << std::endl; diff --git a/examples/helpers_example.rb b/examples/helpers_example.rb index be3100514..993b6660e 100644 --- a/examples/helpers_example.rb +++ b/examples/helpers_example.rb @@ -22,13 +22,13 @@ # require 'ignition/math' -printf("The volume of a sphere with r=2 is %f.\n", IGN_SPHERE_VOLUME(2)) +printf("The volume of a sphere with r=2 is %f.\n", GZ_SPHERE_VOLUME(2)) printf("The volume of a cylinder with r=4 and l=5 is %f.\n", - IGN_CYLINDER_VOLUME(4, 5)) + GZ_CYLINDER_VOLUME(4, 5)) printf("The volume of a box with x=1, y=2, and z=3 is %f.\n", - IGN_BOX_VOLUME(1, 2, 3)) + GZ_BOX_VOLUME(1, 2, 3)) printf("The result of clamping 2.4 to the range [1,2] is %f.\n", Gz::Math::Clamp(2.4, 1, 2)) diff --git a/examples/pose3_example.cc b/examples/pose3_example.cc index cb010eeb0..ff55e8764 100644 --- a/examples/pose3_example.cc +++ b/examples/pose3_example.cc @@ -26,8 +26,8 @@ int main(int argc, char **argv) << p << std::endl; // Construct a pose at position 1, 2, 3 with a yaw of PI radians. - gz::math::Pose3d p1(1, 2, 3, 0, 0, IGN_PI); - std::cout << "A pose3d(1, 2, 3, 0, 0, IGN_PI) has the following values\n" + gz::math::Pose3d p1(1, 2, 3, 0, 0, GZ_PI); + std::cout << "A pose3d(1, 2, 3, 0, 0, GZ_PI) has the following values\n" << p1 << std::endl; // Set the position of a pose to 10, 20, 30 diff --git a/examples/pose3_example.rb b/examples/pose3_example.rb index b8465c167..0574df411 100644 --- a/examples/pose3_example.rb +++ b/examples/pose3_example.rb @@ -30,7 +30,7 @@ # Construct a pose at position 1, 2, 3 with a yaw of PI radians. p1 = Gz::Math::Pose3d.new(1, 2, 3, 0, 0, Math::PI) -printf("A pose3d(1, 2, 3, 0, 0, IGN_PI) has the following values\n" + +printf("A pose3d(1, 2, 3, 0, 0, GZ_PI) has the following values\n" + "%f %f %f %f %f %f\n", p1.Pos().X(), p1.Pos().Y(), p1.Pos().Z(), p1.Rot().Euler().X(), p1.Rot().Euler().Y(), p1.Rot().Euler().Z()) diff --git a/examples/quaternion_from_euler.cc b/examples/quaternion_from_euler.cc index b1353c0b5..cff627101 100644 --- a/examples/quaternion_from_euler.cc +++ b/examples/quaternion_from_euler.cc @@ -53,9 +53,9 @@ int main(int argc, char **argv) return -1; } - double roll = IGN_DTOR(strToDouble(argv[1])); - double pitch = IGN_DTOR(strToDouble(argv[2])); - double yaw = IGN_DTOR(strToDouble(argv[3])); + double roll = GZ_DTOR(strToDouble(argv[1])); + double pitch = GZ_DTOR(strToDouble(argv[2])); + double yaw = GZ_DTOR(strToDouble(argv[3])); std::cout << "Converting Euler angles:\n"; printf(" roll % .6f radians\n" @@ -65,9 +65,9 @@ int main(int argc, char **argv) printf(" roll % 12.6f degrees\n" " pitch % 12.6f degrees\n" " yaw % 12.6f degrees\n", - IGN_RTOD(roll), - IGN_RTOD(pitch), - IGN_RTOD(yaw)); + GZ_RTOD(roll), + GZ_RTOD(pitch), + GZ_RTOD(yaw)); //![constructor] gz::math::Quaterniond q(roll, pitch, yaw); diff --git a/examples/quaternion_to_euler.cc b/examples/quaternion_to_euler.cc index 42886a4bf..379fa76c8 100644 --- a/examples/quaternion_to_euler.cc +++ b/examples/quaternion_to_euler.cc @@ -87,9 +87,9 @@ int main(int argc, char **argv) printf(" roll % .6f degrees\n" " pitch % .6f degrees\n" " yaw % .6f degrees\n", - IGN_RTOD(euler.X()), - IGN_RTOD(euler.Y()), - IGN_RTOD(euler.Z())); + GZ_RTOD(euler.X()), + GZ_RTOD(euler.Y()), + GZ_RTOD(euler.Z())); std::cout << "\nto Rotation matrix\n"; printf(" % .6f % .6f % .6f\n" diff --git a/include/gz/math/Angle.hh b/include/gz/math/Angle.hh index 2025c03af..635894581 100644 --- a/include/gz/math/Angle.hh +++ b/include/gz/math/Angle.hh @@ -22,23 +22,23 @@ #include #include -/// \def IGN_RTOD(d) +/// \def GZ_RTOD(d) /// \brief Macro that converts radians to degrees /// \param[in] r radians /// \return degrees -#define IGN_RTOD(r) ((r) * 180 / IGN_PI) +#define GZ_RTOD(r) ((r) * 180 / GZ_PI) -/// \def IGN_DTOR(d) +/// \def GZ_DTOR(d) /// \brief Converts degrees to radians /// \param[in] d degrees /// \return radians -#define IGN_DTOR(d) ((d) * IGN_PI / 180) +#define GZ_DTOR(d) ((d) * GZ_PI / 180) -/// \def IGN_NORMALIZE(a) +/// \def GZ_NORMALIZE(a) /// \brief Macro that normalizes an angle in the range -Pi to Pi /// \param[in] a angle /// \return the angle, in range -#define IGN_NORMALIZE(a) (atan2(sin(a), cos(a))) +#define GZ_NORMALIZE(a) (atan2(sin(a), cos(a))) namespace gz { @@ -66,15 +66,15 @@ namespace gz public: static const Angle &Zero; /// \brief An angle with a value of Pi. - /// Equivalent to math::Angle(IGN_PI). + /// Equivalent to math::Angle(GZ_PI). public: static const Angle Π /// \brief An angle with a value of Pi * 0.5. - /// Equivalent to math::Angle(IGN_PI * 0.5). + /// Equivalent to math::Angle(GZ_PI * 0.5). public: static const Angle &HalfPi; /// \brief An angle with a value of Pi * 2. - /// Equivalent to math::Angle(IGN_PI * 2). + /// Equivalent to math::Angle(GZ_PI * 2). public: static const Angle &TwoPi; /// \brief Default constructor that initializes an Angle to zero diff --git a/include/gz/math/AxisAlignedBox.hh b/include/gz/math/AxisAlignedBox.hh index 7609c75f1..d27e48a99 100644 --- a/include/gz/math/AxisAlignedBox.hh +++ b/include/gz/math/AxisAlignedBox.hh @@ -241,7 +241,7 @@ namespace gz double &_low, double &_high) const; /// \brief Private data pointer - IGN_UTILS_IMPL_PTR(dataPtr) + GZ_UTILS_IMPL_PTR(dataPtr) }; } } diff --git a/include/gz/math/DiffDriveOdometry.hh b/include/gz/math/DiffDriveOdometry.hh index 26efd9fbe..ad43dd724 100644 --- a/include/gz/math/DiffDriveOdometry.hh +++ b/include/gz/math/DiffDriveOdometry.hh @@ -67,12 +67,12 @@ namespace gz /// // ... Some time later /// /// // Both wheels have rotated the same amount - /// odom.Update(IGN_DTOR(2), IGN_DTOR(2), std::chrono::steady_clock::now()); + /// odom.Update(GZ_DTOR(2), GZ_DTOR(2), std::chrono::steady_clock::now()); /// /// // ... Some time later /// /// // The left wheel has rotated, the right wheel did not rotate - /// odom.Update(IGN_DTOR(4), IGN_DTOR(2), std::chrono::steady_clock::now()); + /// odom.Update(GZ_DTOR(4), GZ_DTOR(2), std::chrono::steady_clock::now()); /// \endcode class GZ_MATH_VISIBLE DiffDriveOdometry { @@ -131,7 +131,7 @@ namespace gz public: void SetVelocityRollingWindowSize(size_t _size); /// \brief Private data pointer. - IGN_UTILS_IMPL_PTR(dataPtr) + GZ_UTILS_IMPL_PTR(dataPtr) }; } } diff --git a/include/gz/math/Filter.hh b/include/gz/math/Filter.hh index bf81484ee..ef53aef6d 100644 --- a/include/gz/math/Filter.hh +++ b/include/gz/math/Filter.hh @@ -80,7 +80,7 @@ namespace gz // Documentation Inherited. public: virtual void Fc(double _fc, double _fs) override { - b1 = exp(-2.0 * IGN_PI * _fc / _fs); + b1 = exp(-2.0 * GZ_PI * _fc / _fs); a0 = 1.0 - b1; } @@ -179,7 +179,7 @@ namespace gz /// \param[in] _q Q coefficient. public: void Fc(double _fc, double _fs, double _q) { - double k = tan(IGN_PI * _fc / _fs); + double k = tan(GZ_PI * _fc / _fs); double kQuadDenom = k * k + k / _q + 1.0; this->a0 = k * k/ kQuadDenom; this->a1 = 2 * this->a0; diff --git a/include/gz/math/Frustum.hh b/include/gz/math/Frustum.hh index 7b715d91c..462e1385a 100644 --- a/include/gz/math/Frustum.hh +++ b/include/gz/math/Frustum.hh @@ -164,7 +164,7 @@ namespace gz private: void ComputePlanes(); /// \brief Private data pointer - IGN_UTILS_IMPL_PTR(dataPtr) + GZ_UTILS_IMPL_PTR(dataPtr) }; } } diff --git a/include/gz/math/GaussMarkovProcess.hh b/include/gz/math/GaussMarkovProcess.hh index 51e62e5b0..59a43f2c2 100644 --- a/include/gz/math/GaussMarkovProcess.hh +++ b/include/gz/math/GaussMarkovProcess.hh @@ -129,7 +129,7 @@ namespace gz public: double Update(double _dt); /// \brief Private data pointer. - IGN_UTILS_IMPL_PTR(dataPtr) + GZ_UTILS_IMPL_PTR(dataPtr) }; } } diff --git a/include/gz/math/Helpers.hh b/include/gz/math/Helpers.hh index 148860234..a1b98049d 100644 --- a/include/gz/math/Helpers.hh +++ b/include/gz/math/Helpers.hh @@ -34,49 +34,53 @@ /// \brief The default tolerance value used by MassMatrix3::IsValid(), /// MassMatrix3::IsPositive(), and MassMatrix3::ValidMoments() template +constexpr T GZ_MASSMATRIX3_DEFAULT_TOLERANCE = T(10); + +// TODO(CH3): Deprecated. Remove on tock. +template constexpr T IGN_MASSMATRIX3_DEFAULT_TOLERANCE = T(10); -/// \brief Define IGN_PI, IGN_PI_2, and IGN_PI_4. +/// \brief Define GZ_PI, GZ_PI_2, and GZ_PI_4. /// This was put here for Windows support. #ifdef M_PI -#define IGN_PI M_PI -#define IGN_PI_2 M_PI_2 -#define IGN_PI_4 M_PI_4 -#define IGN_SQRT2 M_SQRT2 +#define GZ_PI M_PI +#define GZ_PI_2 M_PI_2 +#define GZ_PI_4 M_PI_4 +#define GZ_SQRT2 M_SQRT2 #else -#define IGN_PI 3.14159265358979323846 -#define IGN_PI_2 1.57079632679489661923 -#define IGN_PI_4 0.78539816339744830962 -#define IGN_SQRT2 1.41421356237309504880 +#define GZ_PI 3.14159265358979323846 +#define GZ_PI_2 1.57079632679489661923 +#define GZ_PI_4 0.78539816339744830962 +#define GZ_SQRT2 1.41421356237309504880 #endif -/// \brief Define IGN_FP_VOLATILE for FP equality comparisons +/// \brief Define GZ_FP_VOLATILE for FP equality comparisons /// Use volatile parameters when checking floating point equality on /// the 387 math coprocessor to work around bugs from the 387 extra precision #if defined __FLT_EVAL_METHOD__ && __FLT_EVAL_METHOD__ == 2 -#define IGN_FP_VOLATILE volatile +#define GZ_FP_VOLATILE volatile #else -#define IGN_FP_VOLATILE +#define GZ_FP_VOLATILE #endif /// \brief Compute sphere volume /// \param[in] _radius Sphere radius -#define IGN_SPHERE_VOLUME(_radius) (4.0*IGN_PI*std::pow(_radius, 3)/3.0) +#define GZ_SPHERE_VOLUME(_radius) (4.0*GZ_PI*std::pow(_radius, 3)/3.0) /// \brief Compute cylinder volume /// \param[in] _r Cylinder base radius /// \param[in] _l Cylinder length -#define IGN_CYLINDER_VOLUME(_r, _l) (_l * IGN_PI * std::pow(_r, 2)) +#define GZ_CYLINDER_VOLUME(_r, _l) (_l * GZ_PI * std::pow(_r, 2)) /// \brief Compute box volume /// \param[in] _x X length /// \param[in] _y Y length /// \param[in] _z Z length -#define IGN_BOX_VOLUME(_x, _y, _z) (_x *_y * _z) +#define GZ_BOX_VOLUME(_x, _y, _z) (_x *_y * _z) /// \brief Compute box volume from a vector /// \param[in] _v Vector3d that contains the box's dimensions. -#define IGN_BOX_VOLUME_V(_v) (_v.X() *_v.Y() * _v.Z()) +#define GZ_BOX_VOLUME_V(_v) (_v.X() *_v.Y() * _v.Z()) namespace gz { @@ -87,34 +91,46 @@ namespace gz inline namespace GZ_MATH_VERSION_NAMESPACE { // /// \brief size_t type with a value of 0 - static const size_t IGN_ZERO_SIZE_T = 0u; + static const size_t GZ_ZERO_SIZE_T = 0u; /// \brief size_t type with a value of 1 - static const size_t IGN_ONE_SIZE_T = 1u; + static const size_t GZ_ONE_SIZE_T = 1u; /// \brief size_t type with a value of 2 - static const size_t IGN_TWO_SIZE_T = 2u; + static const size_t GZ_TWO_SIZE_T = 2u; /// \brief size_t type with a value of 3 - static const size_t IGN_THREE_SIZE_T = 3u; + static const size_t GZ_THREE_SIZE_T = 3u; /// \brief size_t type with a value of 4 - static const size_t IGN_FOUR_SIZE_T = 4u; + static const size_t GZ_FOUR_SIZE_T = 4u; /// \brief size_t type with a value of 5 - static const size_t IGN_FIVE_SIZE_T = 5u; + static const size_t GZ_FIVE_SIZE_T = 5u; /// \brief size_t type with a value of 6 - static const size_t IGN_SIX_SIZE_T = 6u; + static const size_t GZ_SIX_SIZE_T = 6u; /// \brief size_t type with a value of 7 - static const size_t IGN_SEVEN_SIZE_T = 7u; + static const size_t GZ_SEVEN_SIZE_T = 7u; /// \brief size_t type with a value of 8 - static const size_t IGN_EIGHT_SIZE_T = 8u; + static const size_t GZ_EIGHT_SIZE_T = 8u; /// \brief size_t type with a value of 9 - static const size_t IGN_NINE_SIZE_T = 9u; + static const size_t GZ_NINE_SIZE_T = 9u; + + // TODO(CH3): Deprecated. Remove on tock. + constexpr auto GZ_DEPRECATED(7) IGN_ZERO_SIZE_T = &GZ_ZERO_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_ONE_SIZE_T = &GZ_ONE_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_TWO_SIZE_T = &GZ_TWO_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_THREE_SIZE_T = &GZ_THREE_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_FOUR_SIZE_T = &GZ_FOUR_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_FIVE_SIZE_T = &GZ_FIVE_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_SIX_SIZE_T = &GZ_SIX_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_SEVEN_SIZE_T = &GZ_SEVEN_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_EIGHT_SIZE_T = &GZ_EIGHT_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_NINE_SIZE_T = &GZ_NINE_SIZE_T; /// \brief Double maximum value. This value will be similar to 1.79769e+308 static const double MAX_D = std::numeric_limits::max(); @@ -153,7 +169,7 @@ namespace gz static const uint16_t MIN_UI16 = std::numeric_limits::min(); /// \brief 16bit unsigned integer lowest value. This is equivalent to - /// IGN_UINT16_MIN, and is defined here for completeness. + /// GZ_UINT16_MIN, and is defined here for completeness. static const uint16_t LOW_UI16 = std::numeric_limits::lowest(); /// \brief 16-bit unsigned integer positive infinite value @@ -166,7 +182,7 @@ namespace gz static const int16_t MIN_I16 = std::numeric_limits::min(); /// \brief 16bit unsigned integer lowest value. This is equivalent to - /// IGN_INT16_MIN, and is defined here for completeness. + /// GZ_INT16_MIN, and is defined here for completeness. static const int16_t LOW_I16 = std::numeric_limits::lowest(); /// \brief 16-bit unsigned integer positive infinite value @@ -179,7 +195,7 @@ namespace gz static const uint32_t MIN_UI32 = std::numeric_limits::min(); /// \brief 32bit unsigned integer lowest value. This is equivalent to - /// IGN_UINT32_MIN, and is defined here for completeness. + /// GZ_UINT32_MIN, and is defined here for completeness. static const uint32_t LOW_UI32 = std::numeric_limits::lowest(); /// \brief 32-bit unsigned integer positive infinite value @@ -192,7 +208,7 @@ namespace gz static const int32_t MIN_I32 = std::numeric_limits::min(); /// \brief 32bit unsigned integer lowest value. This is equivalent to - /// IGN_INT32_MIN, and is defined here for completeness. + /// GZ_INT32_MIN, and is defined here for completeness. static const int32_t LOW_I32 = std::numeric_limits::lowest(); /// \brief 32-bit unsigned integer positive infinite value @@ -205,7 +221,7 @@ namespace gz static const uint64_t MIN_UI64 = std::numeric_limits::min(); /// \brief 64bit unsigned integer lowest value. This is equivalent to - /// IGN_UINT64_MIN, and is defined here for completeness. + /// GZ_UINT64_MIN, and is defined here for completeness. static const uint64_t LOW_UI64 = std::numeric_limits::lowest(); /// \brief 64-bit unsigned integer positive infinite value @@ -218,7 +234,7 @@ namespace gz static const int64_t MIN_I64 = std::numeric_limits::min(); /// \brief 64bit unsigned integer lowest value. This is equivalent to - /// IGN_INT64_MIN, and is defined here for completeness. + /// GZ_INT64_MIN, and is defined here for completeness. static const int64_t LOW_I64 = std::numeric_limits::lowest(); /// \brief 64-bit unsigned integer positive infinite value @@ -381,7 +397,7 @@ namespace gz inline bool equal(const T &_a, const T &_b, const T &_epsilon = T(1e-6)) { - IGN_FP_VOLATILE T diff = std::abs(_a - _b); + GZ_FP_VOLATILE T diff = std::abs(_a - _b); return diff <= _epsilon; } @@ -563,20 +579,20 @@ namespace gz /// \brief Parse string into an integer. /// \param[in] _input The input string. /// \return An integer, or NAN_I if unable to parse the input. - int IGNITION_MATH_VISIBLE parseInt(const std::string &_input); + int GZ_MATH_VISIBLE parseInt(const std::string &_input); /// \brief parse string into float. /// \param [in] _input The string. /// \return A floating point number (can be NaN) or NAN_D if the /// _input could not be parsed. - double IGNITION_MATH_VISIBLE parseFloat(const std::string &_input); + double GZ_MATH_VISIBLE parseFloat(const std::string &_input); /// \brief Convert a std::chrono::steady_clock::time_point to a seconds and /// nanoseconds pair. /// \param[in] _time The time point to convert. /// \return A pair where the first element is the number of seconds and /// the second is the number of nanoseconds. - std::pair IGNITION_MATH_VISIBLE timePointToSecNsec( + std::pair GZ_MATH_VISIBLE timePointToSecNsec( const std::chrono::steady_clock::time_point &_time); /// \brief Convert seconds and nanoseconds to @@ -585,7 +601,7 @@ namespace gz /// \param[in] _nanosec The nanoseconds to convert. /// \return A std::chrono::steady_clock::time_point based on the number of /// seconds and the number of nanoseconds. - std::chrono::steady_clock::time_point IGNITION_MATH_VISIBLE + std::chrono::steady_clock::time_point GZ_MATH_VISIBLE secNsecToTimePoint( const uint64_t &_sec, const uint64_t &_nanosec); @@ -595,7 +611,7 @@ namespace gz /// \param[in] _nanosec The nanoseconds to convert. /// \return A std::chrono::steady_clock::duration based on the number of /// seconds and the number of nanoseconds. - std::chrono::steady_clock::duration IGNITION_MATH_VISIBLE secNsecToDuration( + std::chrono::steady_clock::duration GZ_MATH_VISIBLE secNsecToDuration( const uint64_t &_sec, const uint64_t &_nanosec); /// \brief Convert a std::chrono::steady_clock::duration to a seconds and @@ -603,7 +619,7 @@ namespace gz /// \param[in] _dur The duration to convert. /// \return A pair where the first element is the number of seconds and /// the second is the number of nanoseconds. - std::pair IGNITION_MATH_VISIBLE durationToSecNsec( + std::pair GZ_MATH_VISIBLE durationToSecNsec( const std::chrono::steady_clock::duration &_dur); // TODO(anyone): Replace this with std::chrono::days. diff --git a/include/gz/math/Inertial.hh b/include/gz/math/Inertial.hh index eb24f149f..9b2b5f3b3 100644 --- a/include/gz/math/Inertial.hh +++ b/include/gz/math/Inertial.hh @@ -80,7 +80,7 @@ namespace gz /// /// \return True if the MassMatrix3 is valid. public: bool SetMassMatrix(const MassMatrix3 &_m, - const T _tolerance = IGN_MASSMATRIX3_DEFAULT_TOLERANCE) + const T _tolerance = GZ_MASSMATRIX3_DEFAULT_TOLERANCE) { this->massMatrix = _m; return this->massMatrix.IsValid(_tolerance); diff --git a/include/gz/math/Kmeans.hh b/include/gz/math/Kmeans.hh index ff93ea53d..13c198d56 100644 --- a/include/gz/math/Kmeans.hh +++ b/include/gz/math/Kmeans.hh @@ -76,7 +76,7 @@ namespace gz /// \return The index of the closest centroid to the point _p. private: unsigned int ClosestCentroid(const Vector3d &_p) const; - IGN_UTILS_IMPL_PTR(dataPtr) + GZ_UTILS_IMPL_PTR(dataPtr) }; } } diff --git a/include/gz/math/Line2.hh b/include/gz/math/Line2.hh index 0b2e87b83..40179806e 100644 --- a/include/gz/math/Line2.hh +++ b/include/gz/math/Line2.hh @@ -293,7 +293,7 @@ namespace gz /// is clamped to the range [0, 1] public: math::Vector2 operator[](size_t _index) const { - return this->pts[clamp(_index, IGN_ZERO_SIZE_T, IGN_ONE_SIZE_T)]; + return this->pts[clamp(_index, GZ_ZERO_SIZE_T, GZ_ONE_SIZE_T)]; } /// \brief Stream extraction operator diff --git a/include/gz/math/Line3.hh b/include/gz/math/Line3.hh index 233bb41a6..836047e7b 100644 --- a/include/gz/math/Line3.hh +++ b/include/gz/math/Line3.hh @@ -382,7 +382,7 @@ namespace gz /// parameter is clamped to the range [0, 1]. public: math::Vector3 operator[](const size_t _index) const { - return this->pts[clamp(_index, IGN_ZERO_SIZE_T, IGN_ONE_SIZE_T)]; + return this->pts[clamp(_index, GZ_ZERO_SIZE_T, GZ_ONE_SIZE_T)]; } /// \brief Stream extraction operator diff --git a/include/gz/math/MassMatrix3.hh b/include/gz/math/MassMatrix3.hh index e629a0b0a..d80f47339 100644 --- a/include/gz/math/MassMatrix3.hh +++ b/include/gz/math/MassMatrix3.hh @@ -297,7 +297,7 @@ namespace gz /// \endcode /// public: bool IsNearPositive(const T _tolerance = - IGN_MASSMATRIX3_DEFAULT_TOLERANCE) const + GZ_MASSMATRIX3_DEFAULT_TOLERANCE) const { const T epsilon = this->Epsilon(_tolerance); @@ -330,7 +330,7 @@ namespace gz /// \endcode /// public: bool IsPositive(const T _tolerance = - IGN_MASSMATRIX3_DEFAULT_TOLERANCE) const + GZ_MASSMATRIX3_DEFAULT_TOLERANCE) const { const T epsilon = this->Epsilon(_tolerance); @@ -351,7 +351,7 @@ namespace gz /// A good value is 10, which is also the /// MASSMATRIX3_DEFAULT_TOLERANCE. public: T Epsilon(const T _tolerance = - IGN_MASSMATRIX3_DEFAULT_TOLERANCE) const + GZ_MASSMATRIX3_DEFAULT_TOLERANCE) const { return Epsilon(this->DiagonalMoments(), _tolerance); } @@ -379,7 +379,7 @@ namespace gz /// \endcode public: static T Epsilon(const Vector3 &_moments, const T _tolerance = - IGN_MASSMATRIX3_DEFAULT_TOLERANCE) + GZ_MASSMATRIX3_DEFAULT_TOLERANCE) { // The following was borrowed heavily from: // https://github.com/RobotLocomotion/drake/blob/v0.27.0/multibody/tree/rotational_inertia.h @@ -417,7 +417,7 @@ namespace gz /// \return True if IsNearPositive(_tolerance) and /// ValidMoments(this->PrincipalMoments(), _tolerance) both return true. public: bool IsValid(const T _tolerance = - IGN_MASSMATRIX3_DEFAULT_TOLERANCE) const + GZ_MASSMATRIX3_DEFAULT_TOLERANCE) const { return this->IsNearPositive(_tolerance) && ValidMoments(this->PrincipalMoments(), _tolerance); @@ -444,7 +444,7 @@ namespace gz /// _moments[2] + _moments[0] + epsilon >= _moments[1]; /// \endcode public: static bool ValidMoments(const Vector3 &_moments, - const T _tolerance = IGN_MASSMATRIX3_DEFAULT_TOLERANCE) + const T _tolerance = GZ_MASSMATRIX3_DEFAULT_TOLERANCE) { T epsilon = Epsilon(_moments, _tolerance); @@ -516,8 +516,8 @@ namespace gz // sort the moments from smallest to largest T moment0 = (b + 2*sqrt(p) * cos(delta / 3.0)) / 3.0; - T moment1 = (b + 2*sqrt(p) * cos((delta + 2*IGN_PI)/3.0)) / 3.0; - T moment2 = (b + 2*sqrt(p) * cos((delta - 2*IGN_PI)/3.0)) / 3.0; + T moment1 = (b + 2*sqrt(p) * cos((delta + 2*GZ_PI)/3.0)) / 3.0; + T moment2 = (b + 2*sqrt(p) * cos((delta - 2*GZ_PI)/3.0)) / 3.0; sort3(moment0, moment1, moment2); return Vector3(moment0, moment1, moment2); } @@ -673,7 +673,7 @@ namespace gz // [-1 0 0] // That is equivalent to a 90 degree pitch if (unequalMoment == 0) - result *= Quaternion(0, IGN_PI_2, 0); + result *= Quaternion(0, GZ_PI_2, 0); return result; } @@ -950,7 +950,7 @@ namespace gz { return false; } - T volume = IGN_PI * _radius * _radius * _length; + T volume = GZ_PI * _radius * _radius * _length; return this->SetFromCylinderZ(_mat.Density() * volume, _length, _radius, _rot); } @@ -1020,7 +1020,7 @@ namespace gz return false; } - T volume = (4.0/3.0) * IGN_PI * std::pow(_radius, 3); + T volume = (4.0/3.0) * GZ_PI * std::pow(_radius, 3); return this->SetFromSphere(_mat.Density() * volume, _radius); } diff --git a/include/gz/math/Material.hh b/include/gz/math/Material.hh index e3e2f8ac7..99be5d5e8 100644 --- a/include/gz/math/Material.hh +++ b/include/gz/math/Material.hh @@ -134,7 +134,7 @@ namespace gz public: void SetDensity(const double _density); /// \brief Private data pointer. - IGN_UTILS_IMPL_PTR(dataPtr) + GZ_UTILS_IMPL_PTR(dataPtr) }; } } diff --git a/include/gz/math/Matrix3.hh b/include/gz/math/Matrix3.hh index 2904b2441..761f387a1 100644 --- a/include/gz/math/Matrix3.hh +++ b/include/gz/math/Matrix3.hh @@ -50,7 +50,7 @@ namespace gz /// /// * Ruby /// \code{.rb} - /// # Modify the RUBYLIB environment variable to include the ignition math + /// # Modify the RUBYLIB environment variable to include the Gazebo Math /// # library install path. For example, if you install to /user: /// # /// # $ export RUBYLIB=/usr/lib/ruby:$RUBYLIB @@ -156,8 +156,8 @@ namespace gz /// \param[in] _v New value. public: void Set(size_t _row, size_t _col, T _v) { - this->data[clamp(_row, IGN_ZERO_SIZE_T, IGN_TWO_SIZE_T)] - [clamp(_col, IGN_ZERO_SIZE_T, IGN_TWO_SIZE_T)] = _v; + this->data[clamp(_row, GZ_ZERO_SIZE_T, GZ_TWO_SIZE_T)] + [clamp(_col, GZ_ZERO_SIZE_T, GZ_TWO_SIZE_T)] = _v; } /// \brief Set values. @@ -504,8 +504,8 @@ namespace gz /// \return a pointer to the row public: inline T operator()(size_t _row, size_t _col) const { - return this->data[clamp(_row, IGN_ZERO_SIZE_T, IGN_TWO_SIZE_T)] - [clamp(_col, IGN_ZERO_SIZE_T, IGN_TWO_SIZE_T)]; + return this->data[clamp(_row, GZ_ZERO_SIZE_T, GZ_TWO_SIZE_T)] + [clamp(_col, GZ_ZERO_SIZE_T, GZ_TWO_SIZE_T)]; } /// \brief Array subscript operator. @@ -514,8 +514,8 @@ namespace gz /// \return a pointer to the row public: inline T &operator()(size_t _row, size_t _col) { - return this->data[clamp(_row, IGN_ZERO_SIZE_T, IGN_TWO_SIZE_T)] - [clamp(_col, IGN_ZERO_SIZE_T, IGN_TWO_SIZE_T)]; + return this->data[clamp(_row, GZ_ZERO_SIZE_T, GZ_TWO_SIZE_T)] + [clamp(_col, GZ_ZERO_SIZE_T, GZ_TWO_SIZE_T)]; } /// \brief Return the determinant of the matrix. diff --git a/include/gz/math/Matrix4.hh b/include/gz/math/Matrix4.hh index 13ffc592f..d63393cba 100644 --- a/include/gz/math/Matrix4.hh +++ b/include/gz/math/Matrix4.hh @@ -305,15 +305,15 @@ namespace gz if (m31 < 0.0) { - euler.Y(IGN_PI / 2.0); - euler2.Y(IGN_PI / 2.0); + euler.Y(GZ_PI / 2.0); + euler2.Y(GZ_PI / 2.0); euler.X(atan2(m12, m13)); euler2.X(atan2(m12, m13)); } else { - euler.Y(-IGN_PI / 2.0); - euler2.Y(-IGN_PI / 2.0); + euler.Y(-GZ_PI / 2.0); + euler2.Y(-GZ_PI / 2.0); euler.X(atan2(-m12, -m13)); euler2.X(atan2(-m12, -m13)); } @@ -321,7 +321,7 @@ namespace gz else { euler.Y(-asin(m31)); - euler2.Y(IGN_PI - euler.Y()); + euler2.Y(GZ_PI - euler.Y()); euler.X(atan2(m32 / cos(euler.Y()), m33 / cos(euler.Y()))); euler2.X(atan2(m32 / cos(euler2.Y()), m33 / cos(euler2.Y()))); @@ -686,8 +686,8 @@ namespace gz public: inline const T &operator()(const size_t _row, const size_t _col) const { - return this->data[clamp(_row, IGN_ZERO_SIZE_T, IGN_THREE_SIZE_T)][ - clamp(_col, IGN_ZERO_SIZE_T, IGN_THREE_SIZE_T)]; + return this->data[clamp(_row, GZ_ZERO_SIZE_T, GZ_THREE_SIZE_T)][ + clamp(_col, GZ_ZERO_SIZE_T, GZ_THREE_SIZE_T)]; } /// \brief Get a mutable version the value at the specified row, @@ -699,8 +699,8 @@ namespace gz /// \return The value at the specified index public: inline T &operator()(const size_t _row, const size_t _col) { - return this->data[clamp(_row, IGN_ZERO_SIZE_T, IGN_THREE_SIZE_T)] - [clamp(_col, IGN_ZERO_SIZE_T, IGN_THREE_SIZE_T)]; + return this->data[clamp(_row, GZ_ZERO_SIZE_T, GZ_THREE_SIZE_T)] + [clamp(_col, GZ_ZERO_SIZE_T, GZ_THREE_SIZE_T)]; } /// \brief Equality test with tolerance. diff --git a/include/gz/math/PID.hh b/include/gz/math/PID.hh index 7092cc77f..0b3276b89 100644 --- a/include/gz/math/PID.hh +++ b/include/gz/math/PID.hh @@ -183,7 +183,7 @@ namespace gz public: void Reset(); /// \brief Pointer to private data. - IGN_UTILS_IMPL_PTR(dataPtr) + GZ_UTILS_IMPL_PTR(dataPtr) }; } } diff --git a/include/gz/math/Pose3.hh b/include/gz/math/Pose3.hh index 02b5dc29d..31cb748f7 100644 --- a/include/gz/math/Pose3.hh +++ b/include/gz/math/Pose3.hh @@ -57,7 +57,7 @@ namespace gz /// /// # Construct a pose at position 1, 2, 3 with a yaw of PI radians. /// p1 = Gz::Math::Pose3d.new(1, 2, 3, 0, 0, Math::PI) - /// printf("A pose3d(1, 2, 3, 0, 0, IGN_PI) has the following values\n" + + /// printf("A pose3d(1, 2, 3, 0, 0, GZ_PI) has the following values\n" + /// "%f %f %f %f %f %f\n", p1.Pos().X(), p1.Pos().Y(), p1.Pos().Z(), /// p1.Rot().Euler().X(), p1.Rot().Euler().Y(), p1.Rot().Euler().Z()) /// diff --git a/include/gz/math/Quaternion.hh b/include/gz/math/Quaternion.hh index 3aecf73c2..635e75deb 100644 --- a/include/gz/math/Quaternion.hh +++ b/include/gz/math/Quaternion.hh @@ -51,7 +51,7 @@ namespace gz /// * Ruby /// /// \code{.rb} - /// # Modify the RUBYLIB environment variable to include the ignition math + /// # Modify the RUBYLIB environment variable to include the Gazebo Math /// # library install path. For example, if you install to /user: /// # /// # $ export RUBYLIB=/usr/lib/ruby:$RUBYLIB @@ -447,11 +447,11 @@ namespace gz T sarg = -2 * (copy.qx*copy.qz - copy.qw * copy.qy); if (sarg <= T(-1.0)) { - vec.Y(T(-0.5*IGN_PI)); + vec.Y(T(-0.5*GZ_PI)); } else if (sarg >= T(1.0)) { - vec.Y(T(0.5*IGN_PI)); + vec.Y(T(0.5*GZ_PI)); } else { diff --git a/include/gz/math/RollingMean.hh b/include/gz/math/RollingMean.hh index 6b5ce5865..ac15da710 100644 --- a/include/gz/math/RollingMean.hh +++ b/include/gz/math/RollingMean.hh @@ -65,7 +65,7 @@ namespace gz public: size_t WindowSize() const; /// \brief Private data pointer. - IGN_UTILS_IMPL_PTR(dataPtr) + GZ_UTILS_IMPL_PTR(dataPtr) }; } } diff --git a/include/gz/math/RotationSpline.hh b/include/gz/math/RotationSpline.hh index a45deff91..643280a89 100644 --- a/include/gz/math/RotationSpline.hh +++ b/include/gz/math/RotationSpline.hh @@ -111,7 +111,7 @@ namespace gz public: void RecalcTangents(); /// \brief Private data pointer - IGN_UTILS_IMPL_PTR(dataPtr) + GZ_UTILS_IMPL_PTR(dataPtr) }; } } diff --git a/include/gz/math/SemanticVersion.hh b/include/gz/math/SemanticVersion.hh index a246a114e..3eca0c99e 100644 --- a/include/gz/math/SemanticVersion.hh +++ b/include/gz/math/SemanticVersion.hh @@ -131,7 +131,7 @@ namespace gz return _out; } - IGN_UTILS_IMPL_PTR(dataPtr) + GZ_UTILS_IMPL_PTR(dataPtr) }; } } diff --git a/include/gz/math/SphericalCoordinates.hh b/include/gz/math/SphericalCoordinates.hh index 9b9eb57a3..9fa77f93b 100644 --- a/include/gz/math/SphericalCoordinates.hh +++ b/include/gz/math/SphericalCoordinates.hh @@ -319,7 +319,7 @@ namespace gz public: bool operator!=(const SphericalCoordinates &_sc) const; /// \brief Pointer to the private data - IGN_UTILS_IMPL_PTR(dataPtr) + GZ_UTILS_IMPL_PTR(dataPtr) }; } } diff --git a/include/gz/math/Spline.hh b/include/gz/math/Spline.hh index c9d6650a0..9ae1db47e 100644 --- a/include/gz/math/Spline.hh +++ b/include/gz/math/Spline.hh @@ -255,7 +255,7 @@ namespace gz /// \internal /// \brief Private data pointer - IGN_UTILS_IMPL_PTR(dataPtr) + GZ_UTILS_IMPL_PTR(dataPtr) }; } } diff --git a/include/gz/math/Stopwatch.hh b/include/gz/math/Stopwatch.hh index c52cf1845..9b305e5ac 100644 --- a/include/gz/math/Stopwatch.hh +++ b/include/gz/math/Stopwatch.hh @@ -114,7 +114,7 @@ namespace gz public: bool operator!=(const Stopwatch &_watch) const; /// \brief Private data pointer. - IGN_UTILS_IMPL_PTR(dataPtr) + GZ_UTILS_IMPL_PTR(dataPtr) }; } } diff --git a/include/gz/math/Temperature.hh b/include/gz/math/Temperature.hh index 54a2f7ccc..9d352486b 100644 --- a/include/gz/math/Temperature.hh +++ b/include/gz/math/Temperature.hh @@ -49,7 +49,7 @@ namespace gz /// /// * Ruby /// \code{.cc} - /// # Modify the RUBYLIB environment variable to include the ignition math + /// # Modify the RUBYLIB environment variable to include the Gazebo Math /// # library install path. For example, if you install to /user: /// # /// # $ export RUBYLIB=/usr/lib/ruby:$RUBYLIB @@ -362,7 +362,7 @@ namespace gz return _in; } - IGN_UTILS_IMPL_PTR(dataPtr) + GZ_UTILS_IMPL_PTR(dataPtr) }; } } diff --git a/include/gz/math/Triangle.hh b/include/gz/math/Triangle.hh index 05fecc4a3..15e8d19cf 100644 --- a/include/gz/math/Triangle.hh +++ b/include/gz/math/Triangle.hh @@ -226,7 +226,7 @@ namespace gz /// \return The point specified by _index. public: math::Vector2 operator[](const size_t _index) const { - return this->pts[clamp(_index, IGN_ZERO_SIZE_T, IGN_TWO_SIZE_T)]; + return this->pts[clamp(_index, GZ_ZERO_SIZE_T, GZ_TWO_SIZE_T)]; } /// The points of the triangle diff --git a/include/gz/math/Triangle3.hh b/include/gz/math/Triangle3.hh index 677ae06a0..ae90171eb 100644 --- a/include/gz/math/Triangle3.hh +++ b/include/gz/math/Triangle3.hh @@ -265,7 +265,7 @@ namespace gz /// \return The triangle point at _index. public: Vector3 operator[](const size_t _index) const { - return this->pts[clamp(_index, IGN_ZERO_SIZE_T, IGN_TWO_SIZE_T)]; + return this->pts[clamp(_index, GZ_ZERO_SIZE_T, GZ_TWO_SIZE_T)]; } /// The points of the triangle diff --git a/include/gz/math/Vector2.hh b/include/gz/math/Vector2.hh index 629768f3e..3fef1be5c 100644 --- a/include/gz/math/Vector2.hh +++ b/include/gz/math/Vector2.hh @@ -473,7 +473,7 @@ namespace gz /// The index is clamped to the range [0,1]. public: T &operator[](const std::size_t _index) { - return this->data[clamp(_index, IGN_ZERO_SIZE_T, IGN_ONE_SIZE_T)]; + return this->data[clamp(_index, GZ_ZERO_SIZE_T, GZ_ONE_SIZE_T)]; } /// \brief Const-qualified array subscript operator @@ -481,7 +481,7 @@ namespace gz /// The index is clamped to the range [0,1]. public: T operator[](const std::size_t _index) const { - return this->data[clamp(_index, IGN_ZERO_SIZE_T, IGN_ONE_SIZE_T)]; + return this->data[clamp(_index, GZ_ZERO_SIZE_T, GZ_ONE_SIZE_T)]; } /// \brief Return the x value. diff --git a/include/gz/math/Vector3.hh b/include/gz/math/Vector3.hh index 8ccd50175..2e30191ec 100644 --- a/include/gz/math/Vector3.hh +++ b/include/gz/math/Vector3.hh @@ -619,7 +619,7 @@ namespace gz /// \return The value. public: T &operator[](const std::size_t _index) { - return this->data[clamp(_index, IGN_ZERO_SIZE_T, IGN_TWO_SIZE_T)]; + return this->data[clamp(_index, GZ_ZERO_SIZE_T, GZ_TWO_SIZE_T)]; } /// \brief Const-qualified array subscript operator @@ -628,7 +628,7 @@ namespace gz /// \return The value. public: T operator[](const std::size_t _index) const { - return this->data[clamp(_index, IGN_ZERO_SIZE_T, IGN_TWO_SIZE_T)]; + return this->data[clamp(_index, GZ_ZERO_SIZE_T, GZ_TWO_SIZE_T)]; } /// \brief Round all values to _precision decimal places diff --git a/include/gz/math/Vector3Stats.hh b/include/gz/math/Vector3Stats.hh index bb62c260a..a9b17dbc9 100644 --- a/include/gz/math/Vector3Stats.hh +++ b/include/gz/math/Vector3Stats.hh @@ -97,7 +97,7 @@ namespace gz public: SignalStats &Mag(); /// \brief Pointer to private data. - IGN_UTILS_IMPL_PTR(dataPtr) + GZ_UTILS_IMPL_PTR(dataPtr) }; } } diff --git a/include/gz/math/Vector4.hh b/include/gz/math/Vector4.hh index beae5ab70..4770c2056 100644 --- a/include/gz/math/Vector4.hh +++ b/include/gz/math/Vector4.hh @@ -578,7 +578,7 @@ namespace gz /// \return The value. public: T &operator[](const std::size_t _index) { - return this->data[clamp(_index, IGN_ZERO_SIZE_T, IGN_THREE_SIZE_T)]; + return this->data[clamp(_index, GZ_ZERO_SIZE_T, GZ_THREE_SIZE_T)]; } /// \brief Const-qualified array subscript operator @@ -587,7 +587,7 @@ namespace gz /// \return The value. public: T operator[](const std::size_t _index) const { - return this->data[clamp(_index, IGN_ZERO_SIZE_T, IGN_THREE_SIZE_T)]; + return this->data[clamp(_index, GZ_ZERO_SIZE_T, GZ_THREE_SIZE_T)]; } /// \brief Return a mutable x value. diff --git a/include/gz/math/detail/Capsule.hh b/include/gz/math/detail/Capsule.hh index 8fb0f19ca..8169b2624 100644 --- a/include/gz/math/detail/Capsule.hh +++ b/include/gz/math/detail/Capsule.hh @@ -106,7 +106,7 @@ std::optional< MassMatrix3 > Capsule::MassMatrix() const // mass and moment of inertia of hemisphere about centroid const T r2 = this->radius * this->radius; const T hemisphereMass = this->material.Density() * - 2. / 3. * IGN_PI * r2 * this->radius; + 2. / 3. * GZ_PI * r2 * this->radius; // efunda.com/math/solids/solids_display.cfm?SolidName=Hemisphere const T ixx = 83. / 320. * hemisphereMass * r2; const T izz = 2. / 5. * hemisphereMass * r2; @@ -135,7 +135,7 @@ std::optional< MassMatrix3 > Capsule::MassMatrix() const template T Capsule::Volume() const { - return IGN_PI * std::pow(this->radius, 2) * + return GZ_PI * std::pow(this->radius, 2) * (this->length + 4. / 3. * this->radius); } diff --git a/include/gz/math/detail/Cylinder.hh b/include/gz/math/detail/Cylinder.hh index 8220a50f8..f4db1b335 100644 --- a/include/gz/math/detail/Cylinder.hh +++ b/include/gz/math/detail/Cylinder.hh @@ -120,7 +120,7 @@ bool Cylinder::MassMatrix(MassMatrix3d &_massMat) const template T Cylinder::Volume() const { - return IGN_PI * std::pow(this->radius, 2) * + return GZ_PI * std::pow(this->radius, 2) * this->length; } diff --git a/include/gz/math/detail/Ellipsoid.hh b/include/gz/math/detail/Ellipsoid.hh index 16ba4c8cb..5b9db31a2 100644 --- a/include/gz/math/detail/Ellipsoid.hh +++ b/include/gz/math/detail/Ellipsoid.hh @@ -96,7 +96,7 @@ std::optional< MassMatrix3 > Ellipsoid::MassMatrix() const template T Ellipsoid::Volume() const { - const T kFourThirdsPi = 4. * IGN_PI / 3.; + const T kFourThirdsPi = 4. * GZ_PI / 3.; return kFourThirdsPi * this->radii.X() * this->radii.Y() * this->radii.Z(); } diff --git a/include/gz/math/detail/Sphere.hh b/include/gz/math/detail/Sphere.hh index 04a43be6a..597c76639 100644 --- a/include/gz/math/detail/Sphere.hh +++ b/include/gz/math/detail/Sphere.hh @@ -92,7 +92,7 @@ bool Sphere::MassMatrix(MassMatrix3d &_massMat) const template T Sphere::Volume() const { - return (4.0/3.0) * IGN_PI * std::pow(this->radius, 3); + return (4.0/3.0) * GZ_PI * std::pow(this->radius, 3); } ////////////////////////////////////////////////// @@ -115,7 +115,7 @@ T Sphere::VolumeBelow(const Plane &_plane) const } auto h = r - dist; - return IGN_PI * h * h * (3 * r - h) / 3; + return GZ_PI * h * h * (3 * r - h) / 3; } ////////////////////////////////////////////////// diff --git a/include/ignition/math/Angle.hh b/include/ignition/math/Angle.hh index 1bbb9750e..834fcc6e4 100644 --- a/include/ignition/math/Angle.hh +++ b/include/ignition/math/Angle.hh @@ -17,3 +17,7 @@ #include #include + +#define IGN_RTOD(r) GZ_RTOD(r) +#define IGN_DTOR(d) GZ_DTOR(d) +#define IGN_NORMALIZE(a) GZ_NORMALIZE(a) diff --git a/include/ignition/math/Helpers.hh b/include/ignition/math/Helpers.hh index efd519133..6690ec80e 100644 --- a/include/ignition/math/Helpers.hh +++ b/include/ignition/math/Helpers.hh @@ -17,3 +17,15 @@ #include #include + +#define IGN_PI GZ_PI +#define IGN_PI_2 GZ_PI_2 +#define IGN_PI_4 GZ_PI_4 +#define IGN_SQRT2 GZ_SQRT2 + +#define IGN_FP_VOLATILE GZ_FP_VOLATILE + +#define IGN_SPHERE_VOLUME(_radius) GZ_SPHERE_VOLUME(_radius) +#define IGN_CYLINDER_VOLUME(_r, _l) GZ_CYLINDER_VOLUME(_r, _l) +#define IGN_BOX_VOLUME(_x, _y, _z) GZ_BOX_VOLUME(_x, _y, _z) +#define IGN_BOX_VOLUME_V(_v) GZ_BOX_VOLUME_V(_v) diff --git a/src/Angle.cc b/src/Angle.cc index 29d733b4a..30c1e856c 100644 --- a/src/Angle.cc +++ b/src/Angle.cc @@ -24,9 +24,9 @@ namespace { // Use constexpr storage for the Color constants, to avoid the C++ static // initialization order fiasco. constexpr Angle gZero(0); -constexpr Angle gPi(IGN_PI); -constexpr Angle gHalfPi(IGN_PI_2); -constexpr Angle gTwoPi(IGN_PI * 2.0); +constexpr Angle gPi(GZ_PI); +constexpr Angle gHalfPi(GZ_PI_2); +constexpr Angle gTwoPi(GZ_PI * 2.0); } // namespace @@ -50,13 +50,13 @@ void Angle::SetRadian(double _radian) ////////////////////////////////////////////////// void Angle::Degree(double _degree) { - this->value = _degree * IGN_PI / 180.0; + this->value = _degree * GZ_PI / 180.0; } ////////////////////////////////////////////////// void Angle::SetDegree(double _degree) { - this->value = _degree * IGN_PI / 180.0; + this->value = _degree * GZ_PI / 180.0; } ////////////////////////////////////////////////// @@ -68,7 +68,7 @@ double Angle::Radian() const ////////////////////////////////////////////////// double Angle::Degree() const { - return this->value * 180.0 / IGN_PI; + return this->value * 180.0 / GZ_PI; } ////////////////////////////////////////////////// diff --git a/src/Angle_TEST.cc b/src/Angle_TEST.cc index ba5e53cdb..7e6089b05 100644 --- a/src/Angle_TEST.cc +++ b/src/Angle_TEST.cc @@ -31,13 +31,13 @@ TEST(AngleTest, Angle) EXPECT_TRUE(math::equal(0.0, angle1.Radian())); angle1.SetDegree(90.0); - EXPECT_TRUE(angle1 == IGN_PI_2); + EXPECT_TRUE(angle1 == GZ_PI_2); angle1.SetDegree(180.0); - EXPECT_TRUE(angle1 == IGN_PI); + EXPECT_TRUE(angle1 == GZ_PI); - EXPECT_FALSE(angle1 == IGN_PI + 0.1); - EXPECT_TRUE(angle1 == IGN_PI + 0.0001); - EXPECT_TRUE(angle1 == IGN_PI - 0.0001); + EXPECT_FALSE(angle1 == GZ_PI + 0.1); + EXPECT_TRUE(angle1 == GZ_PI + 0.0001); + EXPECT_TRUE(angle1 == GZ_PI - 0.0001); EXPECT_TRUE(math::Angle(0) == math::Angle(0)); EXPECT_TRUE(math::Angle(0) == math::Angle(0.001)); @@ -47,15 +47,15 @@ TEST(AngleTest, Angle) math::Angle angle(0.5); EXPECT_TRUE(math::equal(0.5, angle.Radian())); - angle.SetRadian(IGN_PI_2); - EXPECT_TRUE(math::equal(IGN_RTOD(IGN_PI_2), angle.Degree())); + angle.SetRadian(GZ_PI_2); + EXPECT_TRUE(math::equal(GZ_RTOD(GZ_PI_2), angle.Degree())); - angle.SetRadian(IGN_PI); - EXPECT_TRUE(math::equal(IGN_RTOD(IGN_PI), angle.Degree())); + angle.SetRadian(GZ_PI); + EXPECT_TRUE(math::equal(GZ_RTOD(GZ_PI), angle.Degree())); math::Angle normalized = angle.Normalized(); angle.Normalize(); - EXPECT_TRUE(math::equal(IGN_RTOD(IGN_PI), angle.Degree())); + EXPECT_TRUE(math::equal(GZ_RTOD(GZ_PI), angle.Degree())); EXPECT_EQ(normalized, angle); angle = math::Angle(0.1) + math::Angle(0.2); diff --git a/src/AxisAlignedBox_TEST.cc b/src/AxisAlignedBox_TEST.cc index 46d3ccc79..360c6d1c3 100644 --- a/src/AxisAlignedBox_TEST.cc +++ b/src/AxisAlignedBox_TEST.cc @@ -409,7 +409,7 @@ TEST(AxisAlignedBoxTest, Intersect) EXPECT_TRUE(intersect); EXPECT_TRUE(b.IntersectCheck(Vector3d(2, 2, 0), Vector3d(-1, -1, 0), 0, 1000)); - EXPECT_DOUBLE_EQ(dist, IGN_SQRT2); + EXPECT_DOUBLE_EQ(dist, GZ_SQRT2); EXPECT_DOUBLE_EQ(std::get<1>(b.IntersectDist(Vector3d(2, 2, 0), Vector3d(-1, -1, 0), 0, 1000)), dist); EXPECT_EQ(pt, Vector3d(1, 1, 0)); @@ -429,7 +429,7 @@ TEST(AxisAlignedBoxTest, Intersect) EXPECT_TRUE(intersect); EXPECT_TRUE(b.IntersectCheck(Vector3d(-1, -2, 0), Vector3d(1, 1, 0), 0, 1000)); - EXPECT_DOUBLE_EQ(dist, 2*IGN_SQRT2); + EXPECT_DOUBLE_EQ(dist, 2*GZ_SQRT2); EXPECT_DOUBLE_EQ(std::get<1>(b.IntersectDist(Vector3d(-1, -2, 0), Vector3d(1, 1, 0), 0, 1000)), dist); EXPECT_EQ(pt, Vector3d(1, 0, 0)); @@ -439,7 +439,7 @@ TEST(AxisAlignedBoxTest, Intersect) EXPECT_TRUE(intersect); EXPECT_TRUE(b.IntersectCheck(Vector3d(2, 1, 0), Vector3d(-1, -1, 0), 0, 1000)); - EXPECT_DOUBLE_EQ(dist, IGN_SQRT2); + EXPECT_DOUBLE_EQ(dist, GZ_SQRT2); EXPECT_DOUBLE_EQ(std::get<1>(b.IntersectDist(Vector3d(2, 1, 0), Vector3d(-1, -1, 0), 0, 1000)), dist); EXPECT_EQ(pt, Vector3d(1, 0, 0)); diff --git a/src/Capsule_TEST.cc b/src/Capsule_TEST.cc index c3547c274..15b8599fc 100644 --- a/src/Capsule_TEST.cc +++ b/src/Capsule_TEST.cc @@ -83,7 +83,7 @@ TEST(CapsuleTest, VolumeAndDensity) { double mass = 1.0; math::Capsuled capsule(1.0, 0.001); - double expectedVolume = (IGN_PI * std::pow(0.001, 2) * (1.0 + 4./3. * 0.001)); + double expectedVolume = (GZ_PI * std::pow(0.001, 2) * (1.0 + 4./3. * 0.001)); EXPECT_DOUBLE_EQ(expectedVolume, capsule.Volume()); double expectedDensity = mass / expectedVolume; @@ -103,8 +103,8 @@ TEST(CapsuleTest, Mass) math::Capsuled capsule(l, r); capsule.SetDensityFromMass(mass); - const double cylinderVolume = IGN_PI * r*r * l; - const double sphereVolume = IGN_PI * 4. / 3. * r*r*r; + const double cylinderVolume = GZ_PI * r*r * l; + const double sphereVolume = GZ_PI * 4. / 3. * r*r*r; const double volume = cylinderVolume + sphereVolume; const double cylinderMass = mass * cylinderVolume / volume; const double sphereMass = mass * sphereVolume / volume; diff --git a/src/Cylinder_TEST.cc b/src/Cylinder_TEST.cc index 4f195f7c5..5730a7fe7 100644 --- a/src/Cylinder_TEST.cc +++ b/src/Cylinder_TEST.cc @@ -105,7 +105,7 @@ TEST(CylinderTest, VolumeAndDensity) { double mass = 1.0; math::Cylinderd cylinder(1.0, 0.001); - double expectedVolume = (IGN_PI * std::pow(0.001, 2) * 1.0); + double expectedVolume = (GZ_PI * std::pow(0.001, 2) * 1.0); EXPECT_DOUBLE_EQ(expectedVolume, cylinder.Volume()); double expectedDensity = mass / expectedVolume; diff --git a/src/DiffDriveOdometry_TEST.cc b/src/DiffDriveOdometry_TEST.cc index a71974423..9194f48cf 100644 --- a/src/DiffDriveOdometry_TEST.cc +++ b/src/DiffDriveOdometry_TEST.cc @@ -36,7 +36,7 @@ TEST(DiffDriveOdometryTest, DiffDriveOdometry) double wheelSeparation = 2.0; double wheelRadius = 0.5; - double wheelCircumference = 2 * IGN_PI * wheelRadius; + double wheelCircumference = 2 * GZ_PI * wheelRadius; // This is the linear distance traveled per degree of wheel rotation. double distPerDegree = wheelCircumference / 360.0; @@ -53,7 +53,7 @@ TEST(DiffDriveOdometryTest, DiffDriveOdometry) // Sleep for a little while, then update the odometry with the new wheel // position. auto time1 = startTime + std::chrono::milliseconds(100); - EXPECT_TRUE(odom.Update(IGN_DTOR(1.0), IGN_DTOR(1.0), time1)); + EXPECT_TRUE(odom.Update(GZ_DTOR(1.0), GZ_DTOR(1.0), time1)); EXPECT_DOUBLE_EQ(0.0, *odom.Heading()); EXPECT_DOUBLE_EQ(distPerDegree, odom.X()); EXPECT_DOUBLE_EQ(0.0, odom.Y()); @@ -65,7 +65,7 @@ TEST(DiffDriveOdometryTest, DiffDriveOdometry) // Sleep again, then update the odometry with the new wheel position. auto time2 = time1 + std::chrono::milliseconds(100); - EXPECT_TRUE(odom.Update(IGN_DTOR(2.0), IGN_DTOR(2.0), time2)); + EXPECT_TRUE(odom.Update(GZ_DTOR(2.0), GZ_DTOR(2.0), time2)); EXPECT_DOUBLE_EQ(0.0, *odom.Heading()); EXPECT_NEAR(distPerDegree * 2.0, odom.X(), 3e-6); EXPECT_DOUBLE_EQ(0.0, odom.Y()); @@ -87,7 +87,7 @@ TEST(DiffDriveOdometryTest, DiffDriveOdometry) // Sleep again, this time move 2 degrees in 100ms. time1 = startTime + std::chrono::milliseconds(100); - EXPECT_TRUE(odom.Update(IGN_DTOR(2.0), IGN_DTOR(2.0), time1)); + EXPECT_TRUE(odom.Update(GZ_DTOR(2.0), GZ_DTOR(2.0), time1)); EXPECT_DOUBLE_EQ(0.0, *odom.Heading()); EXPECT_NEAR(distPerDegree * 2.0, odom.X(), 3e-6); EXPECT_DOUBLE_EQ(0.0, odom.Y()); @@ -100,7 +100,7 @@ TEST(DiffDriveOdometryTest, DiffDriveOdometry) // Sleep again, this time rotate the right wheel by 1 degree. time2 = time1 + std::chrono::milliseconds(100); - EXPECT_TRUE(odom.Update(IGN_DTOR(2.0), IGN_DTOR(3.0), time2)); + EXPECT_TRUE(odom.Update(GZ_DTOR(2.0), GZ_DTOR(3.0), time2)); // The heading should be the arc tangent of the linear distance traveled // by the right wheel (the left wheel was stationary) divided by the // wheel separation. diff --git a/src/Ellipsoid_TEST.cc b/src/Ellipsoid_TEST.cc index 682b9c1e9..c9adb3e03 100644 --- a/src/Ellipsoid_TEST.cc +++ b/src/Ellipsoid_TEST.cc @@ -84,14 +84,14 @@ TEST(EllipsoidTest, VolumeAndDensity) // Basic sphere math::Ellipsoidd ellipsoid(2. * math::Vector3d::One); - double expectedVolume = (4. / 3.) * IGN_PI * std::pow(2.0, 3); + double expectedVolume = (4. / 3.) * GZ_PI * std::pow(2.0, 3); EXPECT_DOUBLE_EQ(expectedVolume, ellipsoid.Volume()); double expectedDensity = mass / expectedVolume; EXPECT_DOUBLE_EQ(expectedDensity, ellipsoid.DensityFromMass(mass)); math::Ellipsoidd ellipsoid2(math::Vector3d(1, 10, 100)); - expectedVolume = (4. / 3.) * IGN_PI * 1. * 10. * 100.; + expectedVolume = (4. / 3.) * GZ_PI * 1. * 10. * 100.; EXPECT_DOUBLE_EQ(expectedVolume, ellipsoid2.Volume()); expectedDensity = mass / expectedVolume; diff --git a/src/Frustum.cc b/src/Frustum.cc index dc9f2f8a8..269cb5291 100644 --- a/src/Frustum.cc +++ b/src/Frustum.cc @@ -45,7 +45,7 @@ class Frustum::Implementation /// The field of view is the angle between the frustum's vertex and the /// edges of the near or far plane. /// This value represents the horizontal angle. - public: math::Angle fov {IGN_DTOR(45)}; + public: math::Angle fov {GZ_DTOR(45)}; /// \brief Aspect ratio of the near and far planes. This is the // width divided by the height. diff --git a/src/Frustum_TEST.cc b/src/Frustum_TEST.cc index 1c9949bed..81e70f418 100644 --- a/src/Frustum_TEST.cc +++ b/src/Frustum_TEST.cc @@ -30,7 +30,7 @@ TEST(FrustumTest, Constructor) EXPECT_DOUBLE_EQ(frustum.Near(), 0.0); EXPECT_DOUBLE_EQ(frustum.Far(), 1.0); - EXPECT_EQ(frustum.FOV(), IGN_DTOR(45)); + EXPECT_EQ(frustum.FOV(), GZ_DTOR(45)); EXPECT_DOUBLE_EQ(frustum.AspectRatio(), 1.0); EXPECT_EQ(frustum.Pose(), Pose3d::Zero); } @@ -45,7 +45,7 @@ TEST(FrustumTest, CopyConstructor) // Far distance 10, // Field of view - Angle(IGN_DTOR(45)), + Angle(GZ_DTOR(45)), // Aspect ratio 320.0/240.0, // Pose @@ -88,11 +88,11 @@ TEST(FrustumTest, AssignmentOperator) // Far distance 10, // Field of view - Angle(IGN_DTOR(45)), + Angle(GZ_DTOR(45)), // Aspect ratio 320.0/240.0, // Pose - Pose3d(0, 0, 0, 0, 0, IGN_DTOR(45))); + Pose3d(0, 0, 0, 0, 0, GZ_DTOR(45))); Frustum frustum2; frustum2 = frustum; @@ -132,7 +132,7 @@ TEST(FrustumTest, PyramidXAxisPos) // Far distance 10, // Field of view - Angle(IGN_DTOR(45)), + Angle(GZ_DTOR(45)), // Aspect ratio 320.0/240.0, // Pose @@ -161,11 +161,11 @@ TEST(FrustumTest, PyramidXAxisNeg) // Far distance 10, // Field of view - Angle(IGN_DTOR(45)), + Angle(GZ_DTOR(45)), // Aspect ratio 320.0/240.0, // Pose - Pose3d(0, 0, 0, 0, 0, IGN_PI)); + Pose3d(0, 0, 0, 0, 0, GZ_PI)); EXPECT_FALSE(frustum.Contains(Vector3d(0, 0, 0))); EXPECT_FALSE(frustum.Contains(Vector3d(-0.5, 0, 0))); @@ -191,11 +191,11 @@ TEST(FrustumTest, PyramidYAxis) // Far distance 5, // Field of view - Angle(IGN_DTOR(45)), + Angle(GZ_DTOR(45)), // Aspect ratio 1.0, // Pose - Pose3d(0, 0, 0, 0, 0, IGN_PI*0.5)); + Pose3d(0, 0, 0, 0, 0, GZ_PI*0.5)); EXPECT_FALSE(frustum.Contains(Vector3d(0, 0, 0))); EXPECT_FALSE(frustum.Contains(Vector3d(1, 0, 0))); @@ -221,11 +221,11 @@ TEST(FrustumTest, PyramidZAxis) // Far distance 10, // Field of view - Angle(IGN_DTOR(45)), + Angle(GZ_DTOR(45)), // Aspect ratio 1.0, // Pose - Pose3d(0, 0, 0, 0, IGN_PI*0.5, 0)); + Pose3d(0, 0, 0, 0, GZ_PI*0.5, 0)); EXPECT_FALSE(frustum.Contains(Vector3d(0, 0, 0))); EXPECT_FALSE(frustum.Contains(Vector3d(0, 0, -0.9))); @@ -252,11 +252,11 @@ TEST(FrustumTest, NearFar) // Far distance 10, // Field of view - Angle(IGN_DTOR(45)), + Angle(GZ_DTOR(45)), // Aspect ratio 1.0, // Pose - Pose3d(0, 0, 0, 0, IGN_PI*0.5, 0)); + Pose3d(0, 0, 0, 0, GZ_PI*0.5, 0)); EXPECT_DOUBLE_EQ(frustum.Near(), 1.0); EXPECT_DOUBLE_EQ(frustum.Far(), 10.0); @@ -277,13 +277,13 @@ TEST(FrustumTest, FOV) // Far distance 10, // Field of view - Angle(IGN_DTOR(45)), + Angle(GZ_DTOR(45)), // Aspect ratio 1.0, // Pose - Pose3d(0, 0, 0, 0, IGN_PI*0.5, 0)); + Pose3d(0, 0, 0, 0, GZ_PI*0.5, 0)); - EXPECT_EQ(frustum.FOV(), math::Angle(IGN_DTOR(45))); + EXPECT_EQ(frustum.FOV(), math::Angle(GZ_DTOR(45))); frustum.SetFOV(1.5707); @@ -299,11 +299,11 @@ TEST(FrustumTest, AspectRatio) // Far distance 10, // Field of view - Angle(IGN_DTOR(45)), + Angle(GZ_DTOR(45)), // Aspect ratio 1.0, // Pose - Pose3d(0, 0, 0, 0, IGN_PI*0.5, 0)); + Pose3d(0, 0, 0, 0, GZ_PI*0.5, 0)); EXPECT_DOUBLE_EQ(frustum.AspectRatio(), 1); @@ -321,17 +321,17 @@ TEST(FrustumTest, Pose) // Far distance 10, // Field of view - Angle(IGN_DTOR(45)), + Angle(GZ_DTOR(45)), // Aspect ratio 1.0, // Pose - Pose3d(0, 0, 0, 0, IGN_PI*0.5, 0)); + Pose3d(0, 0, 0, 0, GZ_PI*0.5, 0)); - EXPECT_EQ(frustum.Pose(), Pose3d(0, 0, 0, 0, IGN_PI*0.5, 0)); + EXPECT_EQ(frustum.Pose(), Pose3d(0, 0, 0, 0, GZ_PI*0.5, 0)); - frustum.SetPose(Pose3d(1, 2, 3, IGN_PI, 0, 0)); + frustum.SetPose(Pose3d(1, 2, 3, GZ_PI, 0, 0)); - EXPECT_EQ(frustum.Pose(), Pose3d(1, 2, 3, IGN_PI, 0, 0)); + EXPECT_EQ(frustum.Pose(), Pose3d(1, 2, 3, GZ_PI, 0, 0)); } ///////////////////////////////////////////////// @@ -343,11 +343,11 @@ TEST(FrustumTest, PoseContains) // Far distance 10, // Field of view - Angle(IGN_DTOR(60)), + Angle(GZ_DTOR(60)), // Aspect ratio 1920.0/1080.0, // Pose - Pose3d(0, -5, 0, 0, 0, IGN_PI*0.5)); + Pose3d(0, -5, 0, 0, 0, GZ_PI*0.5)); // Test the near clip boundary EXPECT_FALSE(frustum.Contains(Vector3d(0, -4.01, 0))); @@ -366,44 +366,44 @@ TEST(FrustumTest, PoseContains) // Compute near clip points Vector3d nearTopLeft( - -tan(IGN_DTOR(30)) + offset, + -tan(GZ_DTOR(30)) + offset, frustum.Pose().Pos().Y() + frustum.Near() + offset, - tan(IGN_DTOR(30)) / frustum.AspectRatio() - offset); + tan(GZ_DTOR(30)) / frustum.AspectRatio() - offset); Vector3d nearTopLeftBad( - -tan(IGN_DTOR(30)) - offset, + -tan(GZ_DTOR(30)) - offset, frustum.Pose().Pos().Y() + frustum.Near() - offset, - tan(IGN_DTOR(30)) / frustum.AspectRatio() + offset); + tan(GZ_DTOR(30)) / frustum.AspectRatio() + offset); Vector3d nearTopRight( - tan(IGN_DTOR(30)) - offset, + tan(GZ_DTOR(30)) - offset, frustum.Pose().Pos().Y() + frustum.Near() + offset, - tan(IGN_DTOR(30)) / frustum.AspectRatio() - offset); + tan(GZ_DTOR(30)) / frustum.AspectRatio() - offset); Vector3d nearTopRightBad( - tan(IGN_DTOR(30)) + offset, + tan(GZ_DTOR(30)) + offset, frustum.Pose().Pos().Y() + frustum.Near() - offset, - tan(IGN_DTOR(30)) / frustum.AspectRatio() + offset); + tan(GZ_DTOR(30)) / frustum.AspectRatio() + offset); Vector3d nearBottomLeft( - -tan(IGN_DTOR(30)) + offset, + -tan(GZ_DTOR(30)) + offset, frustum.Pose().Pos().Y() + frustum.Near() + offset, - -tan(IGN_DTOR(30)) / frustum.AspectRatio() + offset); + -tan(GZ_DTOR(30)) / frustum.AspectRatio() + offset); Vector3d nearBottomLeftBad( - -tan(IGN_DTOR(30)) - offset, + -tan(GZ_DTOR(30)) - offset, frustum.Pose().Pos().Y() + frustum.Near() - offset, - -tan(IGN_DTOR(30)) / frustum.AspectRatio() - offset); + -tan(GZ_DTOR(30)) / frustum.AspectRatio() - offset); Vector3d nearBottomRight( - tan(IGN_DTOR(30)) - offset, + tan(GZ_DTOR(30)) - offset, frustum.Pose().Pos().Y() + frustum.Near() + offset, - -tan(IGN_DTOR(30)) / frustum.AspectRatio() + offset); + -tan(GZ_DTOR(30)) / frustum.AspectRatio() + offset); Vector3d nearBottomRightBad( - tan(IGN_DTOR(30)) + offset, + tan(GZ_DTOR(30)) + offset, frustum.Pose().Pos().Y() + frustum.Near() - offset, - -tan(IGN_DTOR(30)) / frustum.AspectRatio() - offset); + -tan(GZ_DTOR(30)) / frustum.AspectRatio() - offset); // Test near clip corners EXPECT_TRUE(frustum.Contains(nearTopLeft)); @@ -420,44 +420,44 @@ TEST(FrustumTest, PoseContains) // Compute far clip points Vector3d farTopLeft( - -tan(IGN_DTOR(30)) * frustum.Far() + offset, + -tan(GZ_DTOR(30)) * frustum.Far() + offset, frustum.Pose().Pos().Y() + frustum.Far() - offset, - (tan(IGN_DTOR(30)) * frustum.Far()) / frustum.AspectRatio() - offset); + (tan(GZ_DTOR(30)) * frustum.Far()) / frustum.AspectRatio() - offset); Vector3d farTopLeftBad( - -tan(IGN_DTOR(30))*frustum.Far() - offset, + -tan(GZ_DTOR(30))*frustum.Far() - offset, frustum.Pose().Pos().Y() + frustum.Far() + offset, - (tan(IGN_DTOR(30) * frustum.Far())) / frustum.AspectRatio() + offset); + (tan(GZ_DTOR(30) * frustum.Far())) / frustum.AspectRatio() + offset); Vector3d farTopRight( - tan(IGN_DTOR(30))*frustum.Far() - offset, + tan(GZ_DTOR(30))*frustum.Far() - offset, frustum.Pose().Pos().Y() + frustum.Far() - offset, - (tan(IGN_DTOR(30)) * frustum.Far()) / frustum.AspectRatio() - offset); + (tan(GZ_DTOR(30)) * frustum.Far()) / frustum.AspectRatio() - offset); Vector3d farTopRightBad( - tan(IGN_DTOR(30))*frustum.Far() + offset, + tan(GZ_DTOR(30))*frustum.Far() + offset, frustum.Pose().Pos().Y() + frustum.Far() + offset, - (tan(IGN_DTOR(30)) * frustum.Far()) / frustum.AspectRatio() + offset); + (tan(GZ_DTOR(30)) * frustum.Far()) / frustum.AspectRatio() + offset); Vector3d farBottomLeft( - -tan(IGN_DTOR(30))*frustum.Far() + offset, + -tan(GZ_DTOR(30))*frustum.Far() + offset, frustum.Pose().Pos().Y() + frustum.Far() - offset, - (-tan(IGN_DTOR(30)) * frustum.Far()) / frustum.AspectRatio() + offset); + (-tan(GZ_DTOR(30)) * frustum.Far()) / frustum.AspectRatio() + offset); Vector3d farBottomLeftBad( - -tan(IGN_DTOR(30))*frustum.Far() - offset, + -tan(GZ_DTOR(30))*frustum.Far() - offset, frustum.Pose().Pos().Y() + frustum.Far() + offset, - (-tan(IGN_DTOR(30)) * frustum.Far()) / frustum.AspectRatio() - offset); + (-tan(GZ_DTOR(30)) * frustum.Far()) / frustum.AspectRatio() - offset); Vector3d farBottomRight( - tan(IGN_DTOR(30))*frustum.Far() - offset, + tan(GZ_DTOR(30))*frustum.Far() - offset, frustum.Pose().Pos().Y() + frustum.Far() - offset, - (-tan(IGN_DTOR(30)) * frustum.Far()) / frustum.AspectRatio() + offset); + (-tan(GZ_DTOR(30)) * frustum.Far()) / frustum.AspectRatio() + offset); Vector3d farBottomRightBad( - tan(IGN_DTOR(30))*frustum.Far() + offset, + tan(GZ_DTOR(30))*frustum.Far() + offset, frustum.Pose().Pos().Y() + frustum.Far() + offset, - (-tan(IGN_DTOR(30)) * frustum.Far()) / frustum.AspectRatio() - offset); + (-tan(GZ_DTOR(30)) * frustum.Far()) / frustum.AspectRatio() - offset); // Test far clip corners EXPECT_TRUE(frustum.Contains(farTopLeft)); @@ -473,7 +473,7 @@ TEST(FrustumTest, PoseContains) EXPECT_FALSE(frustum.Contains(farBottomRightBad)); // Adjust to 45 degrees rotation - frustum.SetPose(Pose3d(1, 1, 0, 0, 0, -IGN_PI*0.25)); + frustum.SetPose(Pose3d(1, 1, 0, 0, 0, -GZ_PI*0.25)); EXPECT_TRUE(frustum.Contains(Vector3d(2, -1, 0))); EXPECT_FALSE(frustum.Contains(Vector3d(0, 0, 0))); EXPECT_FALSE(frustum.Contains(Vector3d(1, 1, 0))); diff --git a/src/Helpers.i b/src/Helpers.i index dc46cc394..b49db4893 100644 --- a/src/Helpers.i +++ b/src/Helpers.i @@ -25,33 +25,62 @@ #include %} +template +constexpr T GZ_MASSMATRIX3_DEFAULT_TOLERANCE = T(10); + +// TODO(CH3): Deprecated. Remove on tock. template constexpr T IGN_MASSMATRIX3_DEFAULT_TOLERANCE = T(10); -#define IGN_PI 3.14159265358979323846 -#define IGN_PI_2 1.57079632679489661923 -#define IGN_PI_4 0.78539816339744830962 -#define IGN_SQRT2 1.41421356237309504880 +#define GZ_PI 3.14159265358979323846 +#define GZ_PI_2 1.57079632679489661923 +#define GZ_PI_4 0.78539816339744830962 +#define GZ_SQRT2 1.41421356237309504880 + +#define GZ_SPHERE_VOLUME(_radius) (4.0 * GZ_PI * std::pow(_radius, 3)/3.0) +#define GZ_CYLINDER_VOLUME(_r, _l) (_l * GZ_PI * std::pow(_r, 2)) +#define GZ_BOX_VOLUME(_x, _y, _z) (_x *_y * _z) +#define GZ_BOX_VOLUME_V(_v) (_v.X() *_v.Y() * _v.Z()) -#define IGN_SPHERE_VOLUME(_radius) (4.0*IGN_PI*std::pow(_radius, 3)/3.0) -#define IGN_CYLINDER_VOLUME(_r, _l) (_l * IGN_PI * std::pow(_r, 2)) -#define IGN_BOX_VOLUME(_x, _y, _z) (_x *_y * _z) -#define IGN_BOX_VOLUME_V(_v) (_v.X() *_v.Y() * _v.Z()) +// TODO(CH3): Deprecated. Remove on tock. +#define IGN_PI GZ_PI +#define IGN_PI_2 GZ_PI_2 +#define IGN_PI_4 GZ_PI_4 +#define IGN_SQRT2 GZ_SQRT2 + +// TODO(CH3): Deprecated. Remove on tock. +#define IGN_SPHERE_VOLUME(_radius) GZ_SPHERE_VOLUME(_radius) +#define IGN_CYLINDER_VOLUME(_r, _l) GZ_CYLINDER_VOLUME(_r, _l) +#define IGN_BOX_VOLUME(_x, _y, _z) GZ_BOX_VOLUME(_x, _y, _z) +#define IGN_BOX_VOLUME_V(_v) GZ_BOX_VOLUME_V(_v) namespace gz { namespace math { - static const size_t IGN_ZERO_SIZE_T = 0u; - static const size_t IGN_ONE_SIZE_T = 1u; - static const size_t IGN_TWO_SIZE_T = 2u; - static const size_t IGN_THREE_SIZE_T = 3u; - static const size_t IGN_FOUR_SIZE_T = 4u; - static const size_t IGN_FIVE_SIZE_T = 5u; - static const size_t IGN_SIX_SIZE_T = 6u; - static const size_t IGN_SEVEN_SIZE_T = 7u; - static const size_t IGN_EIGHT_SIZE_T = 8u; - static const size_t IGN_NINE_SIZE_T = 9u; + static const size_t GZ_ZERO_SIZE_T = 0u; + static const size_t GZ_ONE_SIZE_T = 1u; + static const size_t GZ_TWO_SIZE_T = 2u; + static const size_t GZ_THREE_SIZE_T = 3u; + static const size_t GZ_FOUR_SIZE_T = 4u; + static const size_t GZ_FIVE_SIZE_T = 5u; + static const size_t GZ_SIX_SIZE_T = 6u; + static const size_t GZ_SEVEN_SIZE_T = 7u; + static const size_t GZ_EIGHT_SIZE_T = 8u; + static const size_t GZ_NINE_SIZE_T = 9u; + + // TODO(CH3): Deprecated. Remove on tock. + constexpr auto GZ_DEPRECATED(7) IGN_ZERO_SIZE_T = &GZ_ZERO_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_ONE_SIZE_T = &GZ_ONE_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_TWO_SIZE_T = &GZ_TWO_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_THREE_SIZE_T = &GZ_THREE_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_FOUR_SIZE_T = &GZ_FOUR_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_FIVE_SIZE_T = &GZ_FIVE_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_SIX_SIZE_T = &GZ_SIX_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_SEVEN_SIZE_T = &GZ_SEVEN_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_EIGHT_SIZE_T = &GZ_EIGHT_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_NINE_SIZE_T = &GZ_NINE_SIZE_T; + static const double MAX_D = std::numeric_limits::max(); static const double MIN_D = std::numeric_limits::min(); static const double LOW_D = std::numeric_limits::lowest(); diff --git a/src/Helpers_TEST.cc b/src/Helpers_TEST.cc index 5b46fb61d..942abb08b 100644 --- a/src/Helpers_TEST.cc +++ b/src/Helpers_TEST.cc @@ -425,16 +425,16 @@ TEST(HelpersTest, Sort) ///////////////////////////////////////////////// TEST(HelpersTest, Volume) { - EXPECT_DOUBLE_EQ(IGN_SPHERE_VOLUME(1.0), 4.0*IGN_PI*std::pow(1, 3)/3.0); - EXPECT_DOUBLE_EQ(IGN_SPHERE_VOLUME(0.1), 4.0*IGN_PI*std::pow(.1, 3)/3.0); - EXPECT_DOUBLE_EQ(IGN_SPHERE_VOLUME(-1.1), 4.0*IGN_PI*std::pow(-1.1, 3)/3.0); + EXPECT_DOUBLE_EQ(GZ_SPHERE_VOLUME(1.0), 4.0*GZ_PI*std::pow(1, 3)/3.0); + EXPECT_DOUBLE_EQ(GZ_SPHERE_VOLUME(0.1), 4.0*GZ_PI*std::pow(.1, 3)/3.0); + EXPECT_DOUBLE_EQ(GZ_SPHERE_VOLUME(-1.1), 4.0*GZ_PI*std::pow(-1.1, 3)/3.0); - EXPECT_DOUBLE_EQ(IGN_CYLINDER_VOLUME(0.5, 2.0), 2 * IGN_PI * std::pow(.5, 2)); - EXPECT_DOUBLE_EQ(IGN_CYLINDER_VOLUME(1, -1), -1 * IGN_PI * std::pow(1, 2)); + EXPECT_DOUBLE_EQ(GZ_CYLINDER_VOLUME(0.5, 2.0), 2 * GZ_PI * std::pow(.5, 2)); + EXPECT_DOUBLE_EQ(GZ_CYLINDER_VOLUME(1, -1), -1 * GZ_PI * std::pow(1, 2)); - EXPECT_DOUBLE_EQ(IGN_BOX_VOLUME(1, 2, 3), 1 * 2 * 3); - EXPECT_DOUBLE_EQ(IGN_BOX_VOLUME(.1, .2, .3), - IGN_BOX_VOLUME_V(math::Vector3d(0.1, 0.2, 0.3))); + EXPECT_DOUBLE_EQ(GZ_BOX_VOLUME(1, 2, 3), 1 * 2 * 3); + EXPECT_DOUBLE_EQ(GZ_BOX_VOLUME(.1, .2, .3), + GZ_BOX_VOLUME_V(math::Vector3d(0.1, 0.2, 0.3))); } ///////////////////////////////////////////////// @@ -985,7 +985,7 @@ TEST(HelpersTest, AppendToStream) { std::ostringstream out; - IGN_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION + GZ_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION // Deprecated in ign-math7 math::appendToStream(out, 0.12345678, 3); EXPECT_EQ(out.str(), "0.123"); @@ -1006,7 +1006,7 @@ TEST(HelpersTest, AppendToStream) EXPECT_EQ(out.str(), "0.123 0 456 0"); out.str(""); - IGN_UTILS_WARN_RESUME__DEPRECATED_DECLARATION + GZ_UTILS_WARN_RESUME__DEPRECATED_DECLARATION math::appendToStream(out, 0.0f); EXPECT_EQ(out.str(), "0"); diff --git a/src/Inertial_TEST.cc b/src/Inertial_TEST.cc index 24bbea8c8..f47d29c88 100644 --- a/src/Inertial_TEST.cc +++ b/src/Inertial_TEST.cc @@ -64,7 +64,7 @@ TEST(Inertiald_Test, ConstructorNonDefaultValues) math::MassMatrix3d m(mass, Ixxyyzz, Ixyxzyz); EXPECT_TRUE(m.IsPositive()); EXPECT_TRUE(m.IsValid()); - const math::Pose3d pose(1, 2, 3, IGN_PI/6, 0, 0); + const math::Pose3d pose(1, 2, 3, GZ_PI/6, 0, 0); math::Inertiald inertial(m, pose); // Should not match simple constructor @@ -117,7 +117,7 @@ TEST(Inertiald_Test, Setters) math::MassMatrix3d m(mass, Ixxyyzz, Ixyxzyz); EXPECT_TRUE(m.IsPositive()); EXPECT_TRUE(m.IsValid()); - const math::Pose3d pose(1, 2, 3, IGN_PI/6, 0, 0); + const math::Pose3d pose(1, 2, 3, GZ_PI/6, 0, 0); math::Inertiald inertial; // Initially valid @@ -154,7 +154,7 @@ TEST(Inertiald_Test, MOI_Diagonal) // 90 deg rotation about X axis, expect different MOI { - const math::Pose3d pose(0, 0, 0, IGN_PI_2, 0, 0); + const math::Pose3d pose(0, 0, 0, GZ_PI_2, 0, 0); const math::Matrix3d expectedMOI(2, 0, 0, 0, 4, 0, 0, 0, 3); math::Inertiald inertial(m, pose); EXPECT_NE(inertial.Moi(), m.Moi()); @@ -163,7 +163,7 @@ TEST(Inertiald_Test, MOI_Diagonal) // 90 deg rotation about Y axis, expect different MOI { - const math::Pose3d pose(0, 0, 0, 0, IGN_PI_2, 0); + const math::Pose3d pose(0, 0, 0, 0, GZ_PI_2, 0); const math::Matrix3d expectedMOI(4, 0, 0, 0, 3, 0, 0, 0, 2); math::Inertiald inertial(m, pose); EXPECT_NE(inertial.Moi(), m.Moi()); @@ -172,7 +172,7 @@ TEST(Inertiald_Test, MOI_Diagonal) // 90 deg rotation about Z axis, expect different MOI { - const math::Pose3d pose(0, 0, 0, 0, 0, IGN_PI_2); + const math::Pose3d pose(0, 0, 0, 0, 0, GZ_PI_2); const math::Matrix3d expectedMOI(3, 0, 0, 0, 2, 0, 0, 0, 4); math::Inertiald inertial(m, pose); EXPECT_NE(inertial.Moi(), m.Moi()); @@ -181,7 +181,7 @@ TEST(Inertiald_Test, MOI_Diagonal) // 45 deg rotation about Z axis, expect different MOI { - const math::Pose3d pose(0, 0, 0, 0, 0, IGN_PI_4); + const math::Pose3d pose(0, 0, 0, 0, 0, GZ_PI_4); const math::Matrix3d expectedMOI(2.5, -0.5, 0, -0.5, 2.5, 0, 0, 0, 4); math::Inertiald inertial(m, pose); EXPECT_NE(inertial.Moi(), m.Moi()); @@ -215,18 +215,18 @@ void SetRotation(const double _mass, const std::vector rotations = { math::Quaterniond::Identity, - math::Quaterniond(IGN_PI, 0, 0), - math::Quaterniond(0, IGN_PI, 0), - math::Quaterniond(0, 0, IGN_PI), - math::Quaterniond(IGN_PI_2, 0, 0), - math::Quaterniond(0, IGN_PI_2, 0), - math::Quaterniond(0, 0, IGN_PI_2), - math::Quaterniond(IGN_PI_4, 0, 0), - math::Quaterniond(0, IGN_PI_4, 0), - math::Quaterniond(0, 0, IGN_PI_4), - math::Quaterniond(IGN_PI/6, 0, 0), - math::Quaterniond(0, IGN_PI/6, 0), - math::Quaterniond(0, 0, IGN_PI/6), + math::Quaterniond(GZ_PI, 0, 0), + math::Quaterniond(0, GZ_PI, 0), + math::Quaterniond(0, 0, GZ_PI), + math::Quaterniond(GZ_PI_2, 0, 0), + math::Quaterniond(0, GZ_PI_2, 0), + math::Quaterniond(0, 0, GZ_PI_2), + math::Quaterniond(GZ_PI_4, 0, 0), + math::Quaterniond(0, GZ_PI_4, 0), + math::Quaterniond(0, 0, GZ_PI_4), + math::Quaterniond(GZ_PI/6, 0, 0), + math::Quaterniond(0, GZ_PI/6, 0), + math::Quaterniond(0, 0, GZ_PI/6), math::Quaterniond(0.1, 0.2, 0.3), math::Quaterniond(-0.1, 0.2, -0.3), math::Quaterniond(0.4, 0.2, 0.5), @@ -447,12 +447,12 @@ TEST(Inertiald_Test, AdditionSubtraction) const math::Vector3d size(1, 1, 1); math::MassMatrix3d cubeMM3; EXPECT_TRUE(cubeMM3.SetFromBox(mass, size)); - const math::Inertiald cube(cubeMM3, math::Pose3d(0, 0, 0, IGN_PI_4, 0, 0)); + const math::Inertiald cube(cubeMM3, math::Pose3d(0, 0, 0, GZ_PI_4, 0, 0)); math::MassMatrix3d half; EXPECT_TRUE(half.SetFromBox(0.5*mass, math::Vector3d(0.5, 1, 1))); - math::Inertiald left(half, math::Pose3d(-0.25, 0, 0, IGN_PI_4, 0, 0)); - math::Inertiald right(half, math::Pose3d(0.25, 0, 0, IGN_PI_4, 0, 0)); + math::Inertiald left(half, math::Pose3d(-0.25, 0, 0, GZ_PI_4, 0, 0)); + math::Inertiald right(half, math::Pose3d(0.25, 0, 0, GZ_PI_4, 0, 0)); // objects won't match exactly // since inertia matrices will all be in base frame @@ -514,12 +514,12 @@ TEST(Inertiald_Test, AdditionSubtraction) EXPECT_TRUE(cubeMM3.SetFromBox(mass, size)); const math::Inertiald sevenCubes = math::Inertiald(cubeMM3, math::Pose3d(-0.5, -0.5, -0.5, 0, 0, 0)) + - math::Inertiald(cubeMM3, math::Pose3d(-0.5, 0.5, -0.5, IGN_PI_2, 0, 0)) + - math::Inertiald(cubeMM3, math::Pose3d(0.5, -0.5, -0.5, 0, IGN_PI_2, 0)) + - math::Inertiald(cubeMM3, math::Pose3d(0.5, 0.5, -0.5, 0, 0, IGN_PI_2)) + - math::Inertiald(cubeMM3, math::Pose3d(-0.5, -0.5, 0.5, IGN_PI, 0, 0)) + - math::Inertiald(cubeMM3, math::Pose3d(-0.5, 0.5, 0.5, 0, IGN_PI, 0)) + - math::Inertiald(cubeMM3, math::Pose3d(0.5, -0.5, 0.5, 0, 0, IGN_PI)); + math::Inertiald(cubeMM3, math::Pose3d(-0.5, 0.5, -0.5, GZ_PI_2, 0, 0)) + + math::Inertiald(cubeMM3, math::Pose3d(0.5, -0.5, -0.5, 0, GZ_PI_2, 0)) + + math::Inertiald(cubeMM3, math::Pose3d(0.5, 0.5, -0.5, 0, 0, GZ_PI_2)) + + math::Inertiald(cubeMM3, math::Pose3d(-0.5, -0.5, 0.5, GZ_PI, 0, 0)) + + math::Inertiald(cubeMM3, math::Pose3d(-0.5, 0.5, 0.5, 0, GZ_PI, 0)) + + math::Inertiald(cubeMM3, math::Pose3d(0.5, -0.5, 0.5, 0, 0, GZ_PI)); const math::Inertiald lastCube = math::Inertiald(cubeMM3, math::Pose3d(0.5, 0.5, 0.5, 0, 0, 0)); const math::Inertiald addedCube = sevenCubes + lastCube; diff --git a/src/Line3_TEST.cc b/src/Line3_TEST.cc index 92c58a15f..98fe4e953 100644 --- a/src/Line3_TEST.cc +++ b/src/Line3_TEST.cc @@ -202,7 +202,7 @@ TEST(Line3Test, Distance) EXPECT_EQ(result, math::Line3d(0, 0.5, 0, 0, 0.5, 0.4)); EXPECT_TRUE(line.Distance(math::Line3d(0, 0.5, 1, 1, 0.5, 0), result)); - EXPECT_NEAR(result.Length(), sin(IGN_PI / 4), 1e-4); + EXPECT_NEAR(result.Length(), sin(GZ_PI / 4), 1e-4); EXPECT_EQ(result, math::Line3d(0, 0.5, 0, 0.5, 0.5, 0.5)); // Expect true when lines are parallel diff --git a/src/MassMatrix3_TEST.cc b/src/MassMatrix3_TEST.cc index 9e9dd144c..c1daef36e 100644 --- a/src/MassMatrix3_TEST.cc +++ b/src/MassMatrix3_TEST.cc @@ -289,7 +289,7 @@ TEST(MassMatrix3dTest, PrincipalMoments) const math::Vector3d Ixxyyzz(2.0, 2.0, 2.0); const math::Vector3d Ixyxzyz(-1.0, 0, -1.0); math::MassMatrix3d m(1.0, Ixxyyzz, Ixyxzyz); - const math::Vector3d Ieigen(2-IGN_SQRT2, 2, 2+IGN_SQRT2); + const math::Vector3d Ieigen(2-GZ_SQRT2, 2, 2+GZ_SQRT2); EXPECT_EQ(m.PrincipalMoments(), Ieigen); EXPECT_TRUE(m.IsPositive()); EXPECT_FALSE(m.IsValid()); @@ -301,7 +301,7 @@ TEST(MassMatrix3dTest, PrincipalMoments) const math::Vector3d Ixxyyzz(4.0, 4.0, 4.0); const math::Vector3d Ixyxzyz(-1.0, 0, -1.0); math::MassMatrix3d m(1.0, Ixxyyzz, Ixyxzyz); - const math::Vector3d Ieigen(4-IGN_SQRT2, 4, 4+IGN_SQRT2); + const math::Vector3d Ieigen(4-GZ_SQRT2, 4, 4+GZ_SQRT2); EXPECT_EQ(m.PrincipalMoments(), Ieigen); EXPECT_TRUE(m.IsPositive()); EXPECT_TRUE(m.IsValid()); @@ -504,56 +504,56 @@ TEST(MassMatrix3dTest, PrincipalAxesOffsetRepeat) // Rotated by [45, 45, 0] degrees VerifyNondiagonalMomentsAndAxes(math::Vector3d(4, 5, 5), math::Vector3d(4.5, 4.75, 4.75), - 0.25*math::Vector3d(-IGN_SQRT2, IGN_SQRT2, 1)); + 0.25*math::Vector3d(-GZ_SQRT2, GZ_SQRT2, 1)); // Rotated by [-45, 45, 0] degrees VerifyNondiagonalMomentsAndAxes(math::Vector3d(4, 5, 5), math::Vector3d(4.5, 4.75, 4.75), - 0.25*math::Vector3d(IGN_SQRT2, IGN_SQRT2, -1)); + 0.25*math::Vector3d(GZ_SQRT2, GZ_SQRT2, -1)); // Rotated by [45, -45, 0] degrees VerifyNondiagonalMomentsAndAxes(math::Vector3d(4, 5, 5), math::Vector3d(4.5, 4.75, 4.75), - 0.25*math::Vector3d(IGN_SQRT2, -IGN_SQRT2, 1)); + 0.25*math::Vector3d(GZ_SQRT2, -GZ_SQRT2, 1)); // Rotated by [-45, -45, 0] degrees VerifyNondiagonalMomentsAndAxes(math::Vector3d(4, 5, 5), math::Vector3d(4.5, 4.75, 4.75), - 0.25*math::Vector3d(-IGN_SQRT2, -IGN_SQRT2, -1)); + 0.25*math::Vector3d(-GZ_SQRT2, -GZ_SQRT2, -1)); // Principal moments: [4, 4, 5] // Rotated by [45, 45, 45] degrees VerifyNondiagonalMomentsAndAxes(math::Vector3d(4, 4, 5), math::Vector3d(4.5, 4.25, 4.25), - 0.25*math::Vector3d(-IGN_SQRT2, IGN_SQRT2, -1)); + 0.25*math::Vector3d(-GZ_SQRT2, GZ_SQRT2, -1)); // different rotation VerifyNondiagonalMomentsAndAxes(math::Vector3d(4, 4, 5), math::Vector3d(4.5, 4.25, 4.25), - 0.25*math::Vector3d(IGN_SQRT2, IGN_SQRT2, 1)); + 0.25*math::Vector3d(GZ_SQRT2, GZ_SQRT2, 1)); // different rotation VerifyNondiagonalMomentsAndAxes(math::Vector3d(4, 4, 5), math::Vector3d(4.5, 4.25, 4.25), - 0.25*math::Vector3d(-IGN_SQRT2, -IGN_SQRT2, 1)); + 0.25*math::Vector3d(-GZ_SQRT2, -GZ_SQRT2, 1)); // different rotation VerifyNondiagonalMomentsAndAxes(math::Vector3d(4, 4, 5), math::Vector3d(4.5, 4.25, 4.25), - 0.25*math::Vector3d(IGN_SQRT2, -IGN_SQRT2, -1)); + 0.25*math::Vector3d(GZ_SQRT2, -GZ_SQRT2, -1)); // Principal moments [4e-9, 4e-9, 5e-9] // Rotated by [45, 45, 45] degrees // use tolerance of 1e-15 VerifyNondiagonalMomentsAndAxes(1e-9 * math::Vector3d(4, 4, 5), 1e-9 * math::Vector3d(4.5, 4.25, 4.25), - 0.25e-9*math::Vector3d(-IGN_SQRT2, IGN_SQRT2, -1), 1e-15); + 0.25e-9*math::Vector3d(-GZ_SQRT2, GZ_SQRT2, -1), 1e-15); // different rotation VerifyNondiagonalMomentsAndAxes(1e-9 * math::Vector3d(4, 4, 5), 1e-9 * math::Vector3d(4.5, 4.25, 4.25), - 0.25e-9*math::Vector3d(IGN_SQRT2, IGN_SQRT2, 1)); + 0.25e-9*math::Vector3d(GZ_SQRT2, GZ_SQRT2, 1)); // different rotation VerifyNondiagonalMomentsAndAxes(1e-9 * math::Vector3d(4, 4, 5), 1e-9 * math::Vector3d(4.5, 4.25, 4.25), - 0.25e-9*math::Vector3d(-IGN_SQRT2, -IGN_SQRT2, 1)); + 0.25e-9*math::Vector3d(-GZ_SQRT2, -GZ_SQRT2, 1)); // different rotation VerifyNondiagonalMomentsAndAxes(1e-9 * math::Vector3d(4, 4, 5), 1e-9 * math::Vector3d(4.5, 4.25, 4.25), - 0.25e-9*math::Vector3d(IGN_SQRT2, -IGN_SQRT2, -1), 1e-15); + 0.25e-9*math::Vector3d(GZ_SQRT2, -GZ_SQRT2, -1), 1e-15); // Principal moments [4, 4, 6] // rotate by 30, 60, 0 degrees @@ -616,12 +616,12 @@ TEST(MassMatrix3dTest, PrincipalAxesOffsetNoRepeat) math::Vector3d(0.0, 0, -0.5)); // Tri-diagonal matrix with identical diagonal terms - VerifyNondiagonalMomentsAndAxes(math::Vector3d(4-IGN_SQRT2, 4, 4+IGN_SQRT2), + VerifyNondiagonalMomentsAndAxes(math::Vector3d(4-GZ_SQRT2, 4, 4+GZ_SQRT2), math::Vector3d(4.0, 4.0, 4.0), math::Vector3d(-1.0, 0, -1.0)); // small magnitude, use tolerance of 1e-15 VerifyNondiagonalMomentsAndAxes( - 1e-9 * math::Vector3d(4-IGN_SQRT2, 4, 4+IGN_SQRT2), + 1e-9 * math::Vector3d(4-GZ_SQRT2, 4, 4+GZ_SQRT2), 1e-9 * math::Vector3d(4.0, 4.0, 4.0), 1e-9 * math::Vector3d(-1.0, 0, -1.0), 1e-15); @@ -750,7 +750,7 @@ TEST(MassMatrix3dTest, EquivalentBox) math::Quaterniond rot; EXPECT_TRUE(m.EquivalentBox(size, rot, -1e-6)); EXPECT_EQ(size, math::Vector3d(9, 4, 1)); - EXPECT_EQ(rot, math::Quaterniond(0, 0, IGN_PI/2)); + EXPECT_EQ(rot, math::Quaterniond(0, 0, GZ_PI/2)); math::MassMatrix3d m2; EXPECT_TRUE(m2.SetFromBox(mass, size, rot)); @@ -768,8 +768,8 @@ TEST(MassMatrix3dTest, EquivalentBox) EXPECT_TRUE(m.EquivalentBox(size, rot)); EXPECT_EQ(size, math::Vector3d(9, 4, 1)); // There are multiple correct rotations due to box symmetry - EXPECT_TRUE(rot == math::Quaterniond(0, 0, IGN_PI/4) || - rot == math::Quaterniond(IGN_PI, 0, IGN_PI/4)); + EXPECT_TRUE(rot == math::Quaterniond(0, 0, GZ_PI/4) || + rot == math::Quaterniond(GZ_PI, 0, GZ_PI/4)); math::MassMatrix3d m2; EXPECT_TRUE(m2.SetFromBox(mass, size, rot)); @@ -829,7 +829,7 @@ TEST(MassMatrix3dTest, SetFromCylinderZ) EXPECT_EQ(m.DiagonalMoments(), ixxyyzz); EXPECT_EQ(m.OffDiagonalMoments(), math::Vector3d::Zero); - double density = mass / (IGN_PI * radius * radius * length); + double density = mass / (GZ_PI * radius * radius * length); math::Material mat(density); EXPECT_DOUBLE_EQ(density, mat.Density()); math::MassMatrix3d m1; @@ -873,7 +873,7 @@ TEST(MassMatrix3dTest, SetFromSphere) EXPECT_EQ(m.DiagonalMoments(), ixxyyzz); EXPECT_EQ(m.OffDiagonalMoments(), math::Vector3d::Zero); - double density = mass / ((4.0/3.0) * IGN_PI * std::pow(radius, 3)); + double density = mass / ((4.0/3.0) * GZ_PI * std::pow(radius, 3)); math::Material mat(density); EXPECT_DOUBLE_EQ(density, mat.Density()); math::MassMatrix3d m1; diff --git a/src/Matrix3_TEST.cc b/src/Matrix3_TEST.cc index f04824b44..22d2b0fa4 100644 --- a/src/Matrix3_TEST.cc +++ b/src/Matrix3_TEST.cc @@ -49,7 +49,7 @@ TEST(Matrix3dTest, Matrix3d) math::Vector3d(3, 3, 3)); EXPECT_TRUE(matrix == math::Matrix3d(1, 2, 3, 1, 2, 3, 1, 2, 3)); - matrix.SetFromAxisAngle(math::Vector3d(1, 1, 1), IGN_PI); + matrix.SetFromAxisAngle(math::Vector3d(1, 1, 1), GZ_PI); EXPECT_TRUE(matrix == math::Matrix3d(1, 2, 2, 2, 1, 2, 2, 2, 1)); matrix.SetCol(0, math::Vector3d(3, 4, 5)); diff --git a/src/Matrix4_TEST.cc b/src/Matrix4_TEST.cc index a15c35afd..d5fdef8ee 100644 --- a/src/Matrix4_TEST.cc +++ b/src/Matrix4_TEST.cc @@ -125,7 +125,7 @@ TEST(Matrix4dTest, ConstructFromPose3d) // Rotate pitch by pi/2 so yaw coincides with roll causing a gimbal lock { math::Vector3d trans(3, 2, 1); - math::Quaterniond qt(0, IGN_PI / 2, 0); + math::Quaterniond qt(0, GZ_PI / 2, 0); math::Pose3d pose(trans, qt); math::Matrix4d mat(pose); @@ -137,9 +137,9 @@ TEST(Matrix4dTest, ConstructFromPose3d) { // setup a ZXZ rotation to ensure non-commutative rotations - math::Pose3d pose1(1, -2, 3, 0, 0, IGN_PI / 4); - math::Pose3d pose2(0, 1, -1, -IGN_PI / 4, 0, 0); - math::Pose3d pose3(-1, 0, 0, 0, 0, -IGN_PI / 4); + math::Pose3d pose1(1, -2, 3, 0, 0, GZ_PI / 4); + math::Pose3d pose2(0, 1, -1, -GZ_PI / 4, 0, 0); + math::Pose3d pose3(-1, 0, 0, 0, 0, -GZ_PI / 4); math::Matrix4d m1(pose1); math::Matrix4d m2(pose2); @@ -675,17 +675,17 @@ TEST(Matrix4dTest, LookAt) EXPECT_EQ(math::Matrix4d::LookAt(math::Vector3d(3, 2, 0), math::Vector3d(0, 2, 0)) .Pose(), - math::Pose3d(3, 2, 0, 0, 0, IGN_PI)); + math::Pose3d(3, 2, 0, 0, 0, GZ_PI)); EXPECT_EQ(math::Matrix4d::LookAt(math::Vector3d(1, 6, 1), math::Vector3d::One) .Pose(), - math::Pose3d(1, 6, 1, 0, 0, -IGN_PI_2)); + math::Pose3d(1, 6, 1, 0, 0, -GZ_PI_2)); EXPECT_EQ(math::Matrix4d::LookAt(math::Vector3d(-1, -1, 0), math::Vector3d(1, 1, 0)) .Pose(), - math::Pose3d(-1, -1, 0, 0, 0, IGN_PI_4)); + math::Pose3d(-1, -1, 0, 0, 0, GZ_PI_4)); // Default up is Z EXPECT_EQ(math::Matrix4d::LookAt(math::Vector3d(0.1, -5, 222), @@ -733,11 +733,11 @@ TEST(Matrix4dTest, LookAt) math::Vector3d(0, 1, 1), math::Vector3d::UnitY) .Pose(), - math::Pose3d(1, 1, 1, IGN_PI_2, 0, IGN_PI)); + math::Pose3d(1, 1, 1, GZ_PI_2, 0, GZ_PI)); EXPECT_EQ(math::Matrix4d::LookAt(math::Vector3d::One, math::Vector3d(0, 1, 1), math::Vector3d(0, 1, 1)) .Pose(), - math::Pose3d(1, 1, 1, IGN_PI_4, 0, IGN_PI)); + math::Pose3d(1, 1, 1, GZ_PI_4, 0, GZ_PI)); } diff --git a/src/OrientedBox_TEST.cc b/src/OrientedBox_TEST.cc index 19d681d56..70688bd48 100644 --- a/src/OrientedBox_TEST.cc +++ b/src/OrientedBox_TEST.cc @@ -256,7 +256,7 @@ TEST(OrientedBoxTest, ContainsOrientedPosition) TEST(OrientedBoxTest, ContainsOrientedRotation) { // Rotate PI/2 about +x: swap Z and Y - OrientedBoxd box(Vector3d(1, 2, 3), Pose3d(0, 0, 0, IGN_PI*0.5, 0, 0)); + OrientedBoxd box(Vector3d(1, 2, 3), Pose3d(0, 0, 0, GZ_PI*0.5, 0, 0)); // Doesn't contain non-rotated vertices EXPECT_FALSE(box.Contains(Vector3d(-0.5, -1.0, -1.5))); diff --git a/src/Pose_TEST.cc b/src/Pose_TEST.cc index 1f20dc8cf..8ffdbe4e3 100644 --- a/src/Pose_TEST.cc +++ b/src/Pose_TEST.cc @@ -64,17 +64,17 @@ TEST(PoseTest, Pose) // B is the transform from P to Q specified in frame P // then, A * B is the transform from O to Q specified in frame O math::Pose3d A(math::Vector3d(1, 0, 0), - math::Quaterniond(0, 0, IGN_PI/4.0)); + math::Quaterniond(0, 0, GZ_PI/4.0)); math::Pose3d B(math::Vector3d(1, 0, 0), - math::Quaterniond(0, 0, IGN_PI/2.0)); + math::Quaterniond(0, 0, GZ_PI/2.0)); EXPECT_TRUE(math::equal((A * B).Pos().X(), 1.0 + 1.0/sqrt(2))); EXPECT_TRUE(math::equal((A * B).Pos().Y(), 1.0/sqrt(2))); EXPECT_TRUE(math::equal((A * B).Pos().Z(), 0.0)); EXPECT_TRUE(math::equal((A * B).Rot().Euler().X(), 0.0)); EXPECT_TRUE(math::equal((A * B).Rot().Euler().Y(), 0.0)); - EXPECT_TRUE(math::equal((A * B).Rot().Euler().Z(), 3.0*IGN_PI/4.0)); + EXPECT_TRUE(math::equal((A * B).Rot().Euler().Z(), 3.0*GZ_PI/4.0)); - IGN_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION + GZ_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION // Coverage for + operator EXPECT_EQ(A * B, B + A); EXPECT_NE(A * B, A + B); @@ -83,7 +83,7 @@ TEST(PoseTest, Pose) math::Pose3d C(B); C += A; EXPECT_EQ(C, A * B); - IGN_UTILS_WARN_RESUME__DEPRECATED_DECLARATION + GZ_UTILS_WARN_RESUME__DEPRECATED_DECLARATION } { // If: @@ -91,7 +91,7 @@ TEST(PoseTest, Pose) // B is the transform from O to Q in frame O // then -A is transform from P to O specified in frame P math::Pose3d A(math::Vector3d(1, 0, 0), - math::Quaterniond(0, 0, IGN_PI/4.0)); + math::Quaterniond(0, 0, GZ_PI/4.0)); EXPECT_TRUE(math::equal( (A.Inverse() * math::Pose3d()).Pos().X(), -1.0/sqrt(2))); EXPECT_TRUE(math::equal( @@ -103,9 +103,9 @@ TEST(PoseTest, Pose) EXPECT_TRUE(math::equal( (A.Inverse() * math::Pose3d()).Rot().Euler().Y(), 0.0)); EXPECT_TRUE(math::equal( - (A.Inverse() * math::Pose3d()).Rot().Euler().Z(), -IGN_PI/4)); + (A.Inverse() * math::Pose3d()).Rot().Euler().Z(), -GZ_PI/4)); - IGN_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION + GZ_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION // Coverage for unitary - operator // test negation operator EXPECT_TRUE(math::equal((-A).Pos().X(), -1.0/sqrt(2))); @@ -113,8 +113,8 @@ TEST(PoseTest, Pose) EXPECT_TRUE(math::equal((-A).Pos().Z(), 0.0)); EXPECT_TRUE(math::equal((-A).Rot().Euler().X(), 0.0)); EXPECT_TRUE(math::equal((-A).Rot().Euler().Y(), 0.0)); - EXPECT_TRUE(math::equal((-A).Rot().Euler().Z(), -IGN_PI/4.0)); - IGN_UTILS_WARN_RESUME__DEPRECATED_DECLARATION + EXPECT_TRUE(math::equal((-A).Rot().Euler().Z(), -GZ_PI/4.0)); + GZ_UTILS_WARN_RESUME__DEPRECATED_DECLARATION } { // If: @@ -122,17 +122,17 @@ TEST(PoseTest, Pose) // B is the transform from O to Q in frame O // B - A is the transform from P to Q in frame P math::Pose3d A(math::Vector3d(1, 0, 0), - math::Quaterniond(0, 0, IGN_PI/4.0)); + math::Quaterniond(0, 0, GZ_PI/4.0)); math::Pose3d B(math::Vector3d(1, 1, 0), - math::Quaterniond(0, 0, IGN_PI/2.0)); + math::Quaterniond(0, 0, GZ_PI/2.0)); EXPECT_TRUE(math::equal((A.Inverse() * B).Pos().X(), 1.0/sqrt(2))); EXPECT_TRUE(math::equal((A.Inverse() * B).Pos().Y(), 1.0/sqrt(2))); EXPECT_TRUE(math::equal((A.Inverse() * B).Pos().Z(), 0.0)); EXPECT_TRUE(math::equal((A.Inverse() * B).Rot().Euler().X(), 0.0)); EXPECT_TRUE(math::equal((A.Inverse() * B).Rot().Euler().Y(), 0.0)); - EXPECT_TRUE(math::equal((A.Inverse() * B).Rot().Euler().Z(), IGN_PI/4.0)); + EXPECT_TRUE(math::equal((A.Inverse() * B).Rot().Euler().Z(), GZ_PI/4.0)); - IGN_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION + GZ_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION // Coverage for - operator EXPECT_EQ(A.Inverse() * B, B - A); @@ -140,7 +140,7 @@ TEST(PoseTest, Pose) math::Pose3d C(B); C -= A; EXPECT_EQ(C, A.Inverse() * B); - IGN_UTILS_WARN_RESUME__DEPRECATED_DECLARATION + GZ_UTILS_WARN_RESUME__DEPRECATED_DECLARATION } { math::Pose3d pose; diff --git a/src/Quaternion_TEST.cc b/src/Quaternion_TEST.cc index fe72f8ee8..917b9e537 100644 --- a/src/Quaternion_TEST.cc +++ b/src/Quaternion_TEST.cc @@ -128,11 +128,11 @@ TEST(QuaternionTest, ConstructEuler) // There are an infinite number of equivalent Euler angle // representations when pitch = PI/2, so rather than comparing Euler // angles, we will compare quaternions. - for (double pitch : { -IGN_PI_2, IGN_PI_2 }) + for (double pitch : { -GZ_PI_2, GZ_PI_2 }) { - for (double roll = 0; roll < 2 * IGN_PI + 0.1; roll += IGN_PI_4) + for (double roll = 0; roll < 2 * GZ_PI + 0.1; roll += GZ_PI_4) { - for (double yaw = 0; yaw < 2 * IGN_PI + 0.1; yaw += IGN_PI_4) + for (double yaw = 0; yaw < 2 * GZ_PI + 0.1; yaw += GZ_PI_4) { math::Quaterniond q_orig(roll, pitch, yaw); math::Quaterniond q_derived(q_orig.Euler()); @@ -145,7 +145,7 @@ TEST(QuaternionTest, ConstructEuler) ///////////////////////////////////////////////// TEST(QuaternionTest, ConstructAxisAngle) { - math::Quaterniond q1(math::Vector3d(0, 0, 1), IGN_PI); + math::Quaterniond q1(math::Vector3d(0, 0, 1), GZ_PI); EXPECT_TRUE(math::equal(q1.X(), 0.0)); EXPECT_TRUE(math::equal(q1.Y(), 0.0)); EXPECT_TRUE(math::equal(q1.Z(), 1.0)); @@ -273,7 +273,7 @@ TEST(QuaternionTest, Integrate) // expect no change. { const math::Quaterniond q(0.5, 0.5, 0.5, 0.5); - const double fourPi = 4 * IGN_PI; + const double fourPi = 4 * GZ_PI; math::Quaterniond qX = q.Integrate(math::Vector3d::UnitX, fourPi); math::Quaterniond qY = q.Integrate(math::Vector3d::UnitY, fourPi); math::Quaterniond qZ = q.Integrate(math::Vector3d::UnitZ, fourPi); @@ -286,7 +286,7 @@ TEST(QuaternionTest, Integrate) ///////////////////////////////////////////////// TEST(QuaternionTest, MathLog) { - math::Quaterniond q(IGN_PI*0.1, IGN_PI*0.5, IGN_PI); + math::Quaterniond q(GZ_PI*0.1, GZ_PI*0.5, GZ_PI); EXPECT_EQ(q.Log(), math::Quaterniond(0, -1.02593, 0.162491, 1.02593)); @@ -298,7 +298,7 @@ TEST(QuaternionTest, MathLog) ///////////////////////////////////////////////// TEST(QuaternionTest, MathExp) { - math::Quaterniond q(IGN_PI*0.1, IGN_PI*0.5, IGN_PI); + math::Quaterniond q(GZ_PI*0.1, GZ_PI*0.5, GZ_PI); EXPECT_EQ(q.Exp(), math::Quaterniond(0.545456, -0.588972, 0.093284, 0.588972)); @@ -314,7 +314,7 @@ TEST(QuaternionTest, MathExp) ///////////////////////////////////////////////// TEST(QuaternionTest, MathInvert) { - math::Quaterniond q(IGN_PI*0.1, IGN_PI*0.5, IGN_PI); + math::Quaterniond q(GZ_PI*0.1, GZ_PI*0.5, GZ_PI); q.Invert(); EXPECT_EQ(q, math::Quaterniond(0.110616, 0.698401, -0.110616, -0.698401)); @@ -323,29 +323,29 @@ TEST(QuaternionTest, MathInvert) ///////////////////////////////////////////////// TEST(QuaternionTest, MathAxis) { - math::Quaterniond q(IGN_PI*0.1, IGN_PI*0.5, IGN_PI); + math::Quaterniond q(GZ_PI*0.1, GZ_PI*0.5, GZ_PI); -IGN_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION +GZ_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION // Deprecated in ign-math7 - q.Axis(0, 1, 0, IGN_PI); + q.Axis(0, 1, 0, GZ_PI); EXPECT_EQ(q, math::Quaterniond(6.12303e-17, 0, 1, 0)); // Deprecated in ign-math7 - q.Axis(1, 0, 0, IGN_PI); + q.Axis(1, 0, 0, GZ_PI); EXPECT_EQ(q, math::Quaterniond(0, 1, 0, 0)); -IGN_UTILS_WARN_RESUME__DEPRECATED_DECLARATION +GZ_UTILS_WARN_RESUME__DEPRECATED_DECLARATION - q.SetFromAxisAngle(0, 1, 0, IGN_PI); + q.SetFromAxisAngle(0, 1, 0, GZ_PI); EXPECT_EQ(q, math::Quaterniond(6.12303e-17, 0, 1, 0)); - q.SetFromAxisAngle(math::Vector3d(1, 0, 0), IGN_PI); + q.SetFromAxisAngle(math::Vector3d(1, 0, 0), GZ_PI); EXPECT_EQ(q, math::Quaterniond(0, 1, 0, 0)); } ///////////////////////////////////////////////// TEST(QuaternionTest, MathSet) { - math::Quaterniond q(IGN_PI*0.1, IGN_PI*0.5, IGN_PI); + math::Quaterniond q(GZ_PI*0.1, GZ_PI*0.5, GZ_PI); q.Set(1, 2, 3, 4); EXPECT_TRUE(math::equal(q.W(), 1.0)); @@ -375,7 +375,7 @@ TEST(QuaternionTest, MathNormalize) ///////////////////////////////////////////////// TEST(QuaternionTest, Math) { - math::Quaterniond q(IGN_PI*0.1, IGN_PI*0.5, IGN_PI); + math::Quaterniond q(GZ_PI*0.1, GZ_PI*0.5, GZ_PI); EXPECT_TRUE(q == math::Quaterniond(0.110616, -0.698401, 0.110616, 0.698401)); q.Set(1, 2, 3, 4); @@ -455,7 +455,7 @@ TEST(QuaternionTest, Math) EXPECT_TRUE(math::equal(angle, 0.0, 1e-3)); { // simple 180 rotation about yaw, should result in x and y flipping signs - q = math::Quaterniond(0, 0, IGN_PI); + q = math::Quaterniond(0, 0, GZ_PI); math::Vector3d v = math::Vector3d(1, 2, 3); math::Vector3d r1 = q.RotateVector(v); math::Vector3d r2 = q.RotateVectorReverse(v); @@ -470,7 +470,7 @@ TEST(QuaternionTest, Math) { // simple 90 rotation about yaw, should map x to y, y to -x // simple -90 rotation about yaw, should map x to -y, y to x - q = math::Quaterniond(0, 0, 0.5*IGN_PI); + q = math::Quaterniond(0, 0, 0.5*GZ_PI); math::Vector3d v = math::Vector3d(1, 2, 3); math::Vector3d r1 = q.RotateVector(v); math::Vector3d r2 = q.RotateVectorReverse(v); @@ -491,7 +491,7 @@ TEST(QuaternionTest, Math) // Test RPY fixed-body-frame convention: // Rotate each unit vector in roll and pitch { - q = math::Quaterniond(IGN_PI/2.0, IGN_PI/2.0, 0); + q = math::Quaterniond(GZ_PI/2.0, GZ_PI/2.0, 0); math::Vector3d v1(1, 0, 0); math::Vector3d r1 = q.RotateVector(v1); // 90 degrees about X does nothing, @@ -514,7 +514,7 @@ TEST(QuaternionTest, Math) { // now try a harder case (axis[1,2,3], rotation[0.3*pi]) // verified with octave - q.SetFromAxisAngle(math::Vector3d(1, 2, 3), 0.3*IGN_PI); + q.SetFromAxisAngle(math::Vector3d(1, 2, 3), 0.3*GZ_PI); std::cout << "[" << q.W() << ", " << q.X() << ", " << q.Y() << ", " << q.Z() << "]\n"; std::cout << " x [" << q.Inverse().XAxis() << "]\n"; diff --git a/src/Sphere_TEST.cc b/src/Sphere_TEST.cc index 2d4a2800c..6faacbfba 100644 --- a/src/Sphere_TEST.cc +++ b/src/Sphere_TEST.cc @@ -96,7 +96,7 @@ TEST(SphereTest, VolumeAndDensity) { double mass = 1.0; math::Sphered sphere(0.001); - double expectedVolume = (4.0/3.0) * IGN_PI * std::pow(0.001, 3); + double expectedVolume = (4.0/3.0) * GZ_PI * std::pow(0.001, 3); EXPECT_DOUBLE_EQ(expectedVolume, sphere.Volume()); double expectedDensity = mass / expectedVolume; diff --git a/src/SphericalCoordinates.cc b/src/SphericalCoordinates.cc index a73e0ef87..50d96ad21 100644 --- a/src/SphericalCoordinates.cc +++ b/src/SphericalCoordinates.cc @@ -398,8 +398,8 @@ gz::math::Vector3d SphericalCoordinates::SphericalFromLocalPosition( { gz::math::Vector3d result = this->PositionTransform(_xyz, LOCAL, SPHERICAL); - result.X(IGN_RTOD(result.X())); - result.Y(IGN_RTOD(result.Y())); + result.X(GZ_RTOD(result.X())); + result.Y(GZ_RTOD(result.Y())); return result; } @@ -408,8 +408,8 @@ gz::math::Vector3d SphericalCoordinates::LocalFromSphericalPosition( const gz::math::Vector3d &_xyz) const { gz::math::Vector3d result = _xyz; - result.X(IGN_DTOR(result.X())); - result.Y(IGN_DTOR(result.Y())); + result.X(GZ_DTOR(result.X())); + result.Y(GZ_DTOR(result.Y())); return this->PositionTransform(result, SPHERICAL, LOCAL); } diff --git a/src/SphericalCoordinates_TEST.cc b/src/SphericalCoordinates_TEST.cc index f1fa97c61..303545acc 100644 --- a/src/SphericalCoordinates_TEST.cc +++ b/src/SphericalCoordinates_TEST.cc @@ -535,8 +535,8 @@ TEST(SphericalCoordinatesTest, NoHeading) { // Default heading auto st = math::SphericalCoordinates::EARTH_WGS84; - math::Angle lat(IGN_DTOR(-22.9)); - math::Angle lon(IGN_DTOR(-43.2)); + math::Angle lat(GZ_DTOR(-22.9)); + math::Angle lon(GZ_DTOR(-43.2)); math::Angle heading(0.0); double elev = 0; math::SphericalCoordinates sc(st, lat, lon, elev, heading); @@ -643,9 +643,9 @@ TEST(SphericalCoordinatesTest, WithHeading) { // Heading 90 deg: X == North, Y == West , Z == Up auto st = math::SphericalCoordinates::EARTH_WGS84; - math::Angle lat(IGN_DTOR(-22.9)); - math::Angle lon(IGN_DTOR(-43.2)); - math::Angle heading(IGN_DTOR(90.0)); + math::Angle lat(GZ_DTOR(-22.9)); + math::Angle lon(GZ_DTOR(-43.2)); + math::Angle heading(GZ_DTOR(90.0)); double elev = 0; math::SphericalCoordinates sc(st, lat, lon, elev, heading); diff --git a/src/Vector2_TEST.cc b/src/Vector2_TEST.cc index d5eaa8c3d..2644f4b1c 100644 --- a/src/Vector2_TEST.cc +++ b/src/Vector2_TEST.cc @@ -441,7 +441,7 @@ TEST(Vector2Test, Length) EXPECT_DOUBLE_EQ(math::Vector2d::Zero.SquaredLength(), 0.0); // One vector - EXPECT_NEAR(math::Vector2d::One.Length(), IGN_SQRT2, 1e-10); + EXPECT_NEAR(math::Vector2d::One.Length(), GZ_SQRT2, 1e-10); EXPECT_DOUBLE_EQ(math::Vector2d::One.SquaredLength(), 2.0); // Arbitrary vector diff --git a/src/python_pybind11/src/Angle.cc b/src/python_pybind11/src/Angle.cc index b04760b35..4964af3e3 100644 --- a/src/python_pybind11/src/Angle.cc +++ b/src/python_pybind11/src/Angle.cc @@ -80,9 +80,9 @@ void defineMathAngle(py::module &m, const std::string &typestr) .def(py::self > py::self) .def(py::self >= py::self) .def_readonly_static("ZERO", &Class::Zero, "math::Angle(0)") - .def_readonly_static("PI", &Class::Pi, "math::Angle(IGN_PI)") - .def_readonly_static("HALF_PI", &Class::HalfPi, "math::Angle(IGN_PI * 0.5)") - .def_readonly_static("TWO_PI", &Class::TwoPi, "math::Angle(IGN_PI * 2)") + .def_readonly_static("PI", &Class::Pi, "math::Angle(GZ_PI)") + .def_readonly_static("HALF_PI", &Class::HalfPi, "math::Angle(GZ_PI * 0.5)") + .def_readonly_static("TWO_PI", &Class::TwoPi, "math::Angle(GZ_PI * 2)") .def("__copy__", [](const Class &self) { return Class(self); }) diff --git a/src/python_pybind11/src/Helpers.cc b/src/python_pybind11/src/Helpers.cc index 947bee33c..7ebe98986 100644 --- a/src/python_pybind11/src/Helpers.cc +++ b/src/python_pybind11/src/Helpers.cc @@ -15,6 +15,7 @@ * */ #include +#include #include @@ -37,7 +38,7 @@ class Helpers /// \return sphere volume float SphereVolume(const float _radius) { - return IGN_SPHERE_VOLUME(_radius); + return GZ_SPHERE_VOLUME(_radius); } /// \brief Compute cylinder volume @@ -46,7 +47,7 @@ float SphereVolume(const float _radius) /// \return cylinder volume float CylinderVolume(const float _r, const float _l) { - return IGN_CYLINDER_VOLUME(_r, _l); + return GZ_CYLINDER_VOLUME(_r, _l); } /// \brief Compute box volume @@ -56,7 +57,7 @@ float CylinderVolume(const float _r, const float _l) /// \return box volume float BoxVolume(const float _x, const float _y, const float _z) { - return IGN_BOX_VOLUME(_x, _y, _z); + return GZ_BOX_VOLUME(_x, _y, _z); } /// \brief Compute box volume from a vector @@ -64,7 +65,40 @@ float BoxVolume(const float _x, const float _y, const float _z) /// \return box volume from a vector float BoxVolumeV(const gz::math::Vector3d &_v) { - return IGN_BOX_VOLUME_V(_v); + return GZ_BOX_VOLUME_V(_v); +} + +// TODO(CH3): Deprecated. Remove on tock. +float SphereVolumeDeprecated(const float _radius) +{ + std::cerr << "ign_sphere_volume is deprecated. " + << "Please use gz_sphere_volume instead" + << std::endl; + return SphereVolume(_radius); +} + +float CylinderVolumeDeprecated(const float _r, const float _l) +{ + std::cerr << "ign_cylinder_volume is deprecated. " + << "Please use gz_cylinder_volume instead" + << std::endl; + return CylinderVolume(_r, _l); +} + +float BoxVolumeDeprecated(const float _x, const float _y, const float _z) +{ + std::cerr << "ign_box_volume is deprecated. " + << "Please use gz_box_volume instead" + << std::endl; + return BoxVolume(_x, _y, _z); +} + +float BoxVolumeVDeprecated(const gz::math::Vector3d &_v) +{ + std::cerr << "ign_box_volume_v is deprecated. " + << "Please use gz_box_volume_v instead" + << std::endl; + return BoxVolumeV(_v); } /// \brief Sort two numbers, such that _a <= _b @@ -164,32 +198,60 @@ void defineMathHelpers(py::module &m) .def("parse_float", &gz::math::parseFloat, "parse string into an float") - .def("ign_sphere_volume", + .def("gz_sphere_volume", &SphereVolume, "Compute sphere volume") - .def("ign_cylinder_volume", + .def("gz_cylinder_volume", &CylinderVolume, "Compute cylinder volume") - .def("ign_box_volume", + .def("gz_box_volume", &BoxVolume, "Compute box volume") - .def("ign_box_volume_v", + .def("gz_box_volume_v", &BoxVolumeV, - "Compute box volume from vector"); + "Compute box volume from vector") + + // TODO(CH3): Deprecated. Remove on tock. + .def("ign_sphere_volume", + &SphereVolumeDeprecated, + "[Deprecated] Compute sphere volume") + .def("ign_cylinder_volume", + &CylinderVolumeDeprecated, + "[Deprecated] Compute cylinder volume") + .def("ign_box_volume", + &BoxVolumeDeprecated, + "[Deprecated] Compute box volume") + .def("ign_box_volume_v", + &BoxVolumeVDeprecated, + "[Deprecated] Compute box volume from vector"); + py::class_(m, "Helpers", py::buffer_protocol(), py::dynamic_attr()) - .def_readonly_static("IGNZEROSIZET", &IGN_ZERO_SIZE_T, "IGN_PI") - .def_readonly_static("IGN_ONE_SIZE_T", &IGN_ONE_SIZE_T) - .def_readonly_static("IGN_TWO_SIZE_T", &IGN_TWO_SIZE_T) - .def_readonly_static("IGN_THREE_SIZE_T", &IGN_THREE_SIZE_T) - .def_readonly_static("IGN_FOUR_SIZE_T", &IGN_FOUR_SIZE_T) - .def_readonly_static("IGN_FIVE_SIZE_T", &IGN_FIVE_SIZE_T) - .def_readonly_static("IGN_SIX_SIZE_T", &IGN_SIX_SIZE_T) - .def_readonly_static("IGN_SEVEN_SIZE_T", &IGN_SEVEN_SIZE_T) - .def_readonly_static("IGN_EIGHT_SIZE_T", &IGN_EIGHT_SIZE_T) - .def_readonly_static("IGN_NINE_SIZE_T", &IGN_NINE_SIZE_T) + .def_readonly_static("GZZEROSIZET", &GZ_ZERO_SIZE_T, "GZ_PI") + .def_readonly_static("GZ_ONE_SIZE_T", &GZ_ONE_SIZE_T) + .def_readonly_static("GZ_TWO_SIZE_T", &GZ_TWO_SIZE_T) + .def_readonly_static("GZ_THREE_SIZE_T", &GZ_THREE_SIZE_T) + .def_readonly_static("GZ_FOUR_SIZE_T", &GZ_FOUR_SIZE_T) + .def_readonly_static("GZ_FIVE_SIZE_T", &GZ_FIVE_SIZE_T) + .def_readonly_static("GZ_SIX_SIZE_T", &GZ_SIX_SIZE_T) + .def_readonly_static("GZ_SEVEN_SIZE_T", &GZ_SEVEN_SIZE_T) + .def_readonly_static("GZ_EIGHT_SIZE_T", &GZ_EIGHT_SIZE_T) + .def_readonly_static("GZ_NINE_SIZE_T", &GZ_NINE_SIZE_T) + + // TODO(CH3): Deprecated. Remove on tock. + .def_readonly_static("IGNZEROSIZET", &GZ_ZERO_SIZE_T, "GZ_PI") + .def_readonly_static("IGN_ONE_SIZE_T", &GZ_ONE_SIZE_T) + .def_readonly_static("IGN_TWO_SIZE_T", &GZ_TWO_SIZE_T) + .def_readonly_static("IGN_THREE_SIZE_T", &GZ_THREE_SIZE_T) + .def_readonly_static("IGN_FOUR_SIZE_T", &GZ_FOUR_SIZE_T) + .def_readonly_static("IGN_FIVE_SIZE_T", &GZ_FIVE_SIZE_T) + .def_readonly_static("IGN_SIX_SIZE_T", &GZ_SIX_SIZE_T) + .def_readonly_static("IGN_SEVEN_SIZE_T", &GZ_SEVEN_SIZE_T) + .def_readonly_static("IGN_EIGHT_SIZE_T", &GZ_EIGHT_SIZE_T) + .def_readonly_static("IGN_NINE_SIZE_T", &GZ_NINE_SIZE_T) + .def_readonly_static("MAX_D", &MAX_D) .def_readonly_static("MIN_D", &MIN_D) .def_readonly_static("LOW_D", &LOW_D) diff --git a/src/python_pybind11/src/Inertial.hh b/src/python_pybind11/src/Inertial.hh index 7661ce70f..b92b924c5 100644 --- a/src/python_pybind11/src/Inertial.hh +++ b/src/python_pybind11/src/Inertial.hh @@ -63,7 +63,7 @@ void defineMathInertial(py::module &m, const std::string &typestr) .def("set_mass_matrix", &Class::SetMassMatrix, py::arg("_m") = gz::math::MassMatrix3(), - py::arg("_tolerance") = IGN_MASSMATRIX3_DEFAULT_TOLERANCE, + py::arg("_tolerance") = GZ_MASSMATRIX3_DEFAULT_TOLERANCE, "Set the mass and inertia matrix.") .def("mass_matrix", &Class::MassMatrix, diff --git a/src/python_pybind11/src/MassMatrix3.hh b/src/python_pybind11/src/MassMatrix3.hh index 0b7b42815..e4d87da34 100644 --- a/src/python_pybind11/src/MassMatrix3.hh +++ b/src/python_pybind11/src/MassMatrix3.hh @@ -178,24 +178,24 @@ void helpDefineMathMassMatrix3(py::module &m, const std::string &typestr) "Verify that principal moments are positive") .def("is_valid", &Class::IsValid, - py::arg("_tolerance") = IGN_MASSMATRIX3_DEFAULT_TOLERANCE, + py::arg("_tolerance") = GZ_MASSMATRIX3_DEFAULT_TOLERANCE, "Verify that inertia values are positive semi-definite " "and satisfy the triangle inequality.") .def("epsilon", py::overload_cast&, const T> (&Class::Epsilon), - py::arg("_tolerance") = IGN_MASSMATRIX3_DEFAULT_TOLERANCE, + py::arg("_tolerance") = GZ_MASSMATRIX3_DEFAULT_TOLERANCE, "Get an epsilon value that represents the amount of " "acceptable error in a MassMatrix3. The epsilon value " "is related to machine precision multiplied by the largest possible " "moment of inertia.") .def("is_positive", &Class::IsPositive, - py::arg("_tolerance") = IGN_MASSMATRIX3_DEFAULT_TOLERANCE, + py::arg("_tolerance") = GZ_MASSMATRIX3_DEFAULT_TOLERANCE, "Verify that inertia values are positive definite") .def("is_near_positive", &Class::IsNearPositive, - py::arg("_tolerance") = IGN_MASSMATRIX3_DEFAULT_TOLERANCE, + py::arg("_tolerance") = GZ_MASSMATRIX3_DEFAULT_TOLERANCE, "Verify that inertia values are positive semidefinite") .def(py::self != py::self) .def(py::self == py::self); diff --git a/src/python_pybind11/test/Helpers_TEST.py b/src/python_pybind11/test/Helpers_TEST.py index 685e05881..2bbadef9e 100644 --- a/src/python_pybind11/test/Helpers_TEST.py +++ b/src/python_pybind11/test/Helpers_TEST.py @@ -15,8 +15,8 @@ import math import unittest -from ignition.math import (Helpers, ign_box_volume, ign_box_volume_v, ign_cylinder_volume, - ign_sphere_volume, Vector3d, equal, fixnan, +from ignition.math import (Helpers, gz_box_volume, gz_box_volume_v, gz_cylinder_volume, + gz_sphere_volume, Vector3d, equal, fixnan, greater_or_near_equal, is_even, is_odd, is_power_of_two, isnan, less_or_near_equal, max, mean, min, parse_float, parse_int, precision, round_up_multiple, @@ -243,31 +243,31 @@ def test_sort(self): def test_volume(self): self.assertAlmostEqual( - ign_sphere_volume(1.0), + gz_sphere_volume(1.0), 4.0*math.pi*math.pow(1, 3)/3.0, 6) self.assertAlmostEqual( - ign_sphere_volume(0.1), + gz_sphere_volume(0.1), 4.0*math.pi*math.pow(.1, 3)/3.0, 6) self.assertAlmostEqual( - ign_sphere_volume(-1.1), + gz_sphere_volume(-1.1), 4.0*math.pi*math.pow(-1.1, 3)/3.0, 6) self.assertAlmostEqual( - ign_cylinder_volume(0.5, 2.0), + gz_cylinder_volume(0.5, 2.0), 2 * math.pi * math.pow(.5, 2), 6) self.assertAlmostEqual( - ign_cylinder_volume(1, -1), + gz_cylinder_volume(1, -1), -1 * math.pi * math.pow(1, 2), 6) - self.assertEqual(ign_box_volume(1, 2, 3), 1 * 2 * 3) + self.assertEqual(gz_box_volume(1, 2, 3), 1 * 2 * 3) self.assertAlmostEqual( - ign_box_volume(.1, .2, .3), - ign_box_volume_v(Vector3d(0.1, 0.2, 0.3)), + gz_box_volume(.1, .2, .3), + gz_box_volume_v(Vector3d(0.1, 0.2, 0.3)), 6) def test_round_up_multiple(self): diff --git a/src/python_pybind11/test/MassMatrix3_TEST.py b/src/python_pybind11/test/MassMatrix3_TEST.py index 85f1af53d..9a8314648 100644 --- a/src/python_pybind11/test/MassMatrix3_TEST.py +++ b/src/python_pybind11/test/MassMatrix3_TEST.py @@ -23,10 +23,10 @@ from ignition.math import Matrix3d from ignition.math import Quaterniond -IGN_PI = 3.14159265358979323846 -IGN_PI_2 = 1.57079632679489661923 -IGN_PI_4 = 0.78539816339744830962 -IGN_SQRT2 = 1.41421356237309504880 +GZ_PI = 3.14159265358979323846 +GZ_PI_2 = 1.57079632679489661923 +GZ_PI_4 = 0.78539816339744830962 +GZ_SQRT2 = 1.41421356237309504880 def equal(a, b, error): @@ -254,7 +254,7 @@ def test_principal_moments(self): Ixxyyzz = Vector3d(2.0, 2.0, 2.0) Ixyxzyz = Vector3d(-1.0, 0, -1.0) m = MassMatrix3d(1.0, Ixxyyzz, Ixyxzyz) - Ieigen = Vector3d(2-IGN_SQRT2, 2, 2+IGN_SQRT2) + Ieigen = Vector3d(2-GZ_SQRT2, 2, 2+GZ_SQRT2) self.assertEqual(m.principal_moments(), Ieigen) self.assertTrue(m.is_positive()) self.assertFalse(m.is_valid()) @@ -264,7 +264,7 @@ def test_principal_moments(self): Ixxyyzz = Vector3d(4.0, 4.0, 4.0) Ixyxzyz = Vector3d(-1.0, 0, -1.0) m = MassMatrix3d(1.0, Ixxyyzz, Ixyxzyz) - Ieigen = Vector3d(4-IGN_SQRT2, 4, 4+IGN_SQRT2) + Ieigen = Vector3d(4-GZ_SQRT2, 4, 4+GZ_SQRT2) self.assertEqual(m.principal_moments(), Ieigen) self.assertTrue(m.is_positive()) self.assertTrue(m.is_valid()) @@ -453,44 +453,44 @@ def test_principal_axes_offset_repeat(self): self.verify_non_diagonal_moments_and_axes( Vector3d(4, 5, 5), Vector3d(4.5, 4.75, 4.75), - Vector3d(-IGN_SQRT2, IGN_SQRT2, 1) * 0.25) + Vector3d(-GZ_SQRT2, GZ_SQRT2, 1) * 0.25) # Rotated by [-45, 45, 0] degrees self.verify_non_diagonal_moments_and_axes( Vector3d(4, 5, 5), Vector3d(4.5, 4.75, 4.75), - Vector3d(IGN_SQRT2, IGN_SQRT2, -1) * 0.25) + Vector3d(GZ_SQRT2, GZ_SQRT2, -1) * 0.25) # Rotated by [45, -45, 0] degrees self.verify_non_diagonal_moments_and_axes( Vector3d(4, 5, 5), Vector3d(4.5, 4.75, 4.75), - Vector3d(IGN_SQRT2, -IGN_SQRT2, 1) * 0.25) + Vector3d(GZ_SQRT2, -GZ_SQRT2, 1) * 0.25) # Rotated by [-45, -45, 0] degrees self.verify_non_diagonal_moments_and_axes( Vector3d(4, 5, 5), Vector3d(4.5, 4.75, 4.75), - Vector3d(-IGN_SQRT2, -IGN_SQRT2, -1) * 0.25) + Vector3d(-GZ_SQRT2, -GZ_SQRT2, -1) * 0.25) # Principal moments: [4, 4, 5] # Rotated by [45, 45, 45] degrees self.verify_non_diagonal_moments_and_axes( Vector3d(4, 4, 5), Vector3d(4.5, 4.25, 4.25), - Vector3d(-IGN_SQRT2, IGN_SQRT2, -1) * 0.25) + Vector3d(-GZ_SQRT2, GZ_SQRT2, -1) * 0.25) # different rotation self.verify_non_diagonal_moments_and_axes( Vector3d(4, 4, 5), Vector3d(4.5, 4.25, 4.25), - Vector3d(IGN_SQRT2, IGN_SQRT2, 1) * 0.25) + Vector3d(GZ_SQRT2, GZ_SQRT2, 1) * 0.25) # different rotation self.verify_non_diagonal_moments_and_axes( Vector3d(4, 4, 5), Vector3d(4.5, 4.25, 4.25), - Vector3d(-IGN_SQRT2, -IGN_SQRT2, 1) * 0.25) + Vector3d(-GZ_SQRT2, -GZ_SQRT2, 1) * 0.25) # different rotation self.verify_non_diagonal_moments_and_axes( Vector3d(4, 4, 5), Vector3d(4.5, 4.25, 4.25), - Vector3d(IGN_SQRT2, -IGN_SQRT2, -1) * 0.25) + Vector3d(GZ_SQRT2, -GZ_SQRT2, -1) * 0.25) # Principal moments [4e-9, 4e-9, 5e-9] # Rotated by [45, 45, 45] degrees @@ -498,22 +498,22 @@ def test_principal_axes_offset_repeat(self): self.verify_non_diagonal_moments_and_axes( Vector3d(4, 4, 5) * 1e-9, Vector3d(4.5, 4.25, 4.25) * 1e-9, - Vector3d(-IGN_SQRT2, IGN_SQRT2, -1) * 0.25e-9, 1e-15) + Vector3d(-GZ_SQRT2, GZ_SQRT2, -1) * 0.25e-9, 1e-15) # different rotation self.verify_non_diagonal_moments_and_axes( Vector3d(4, 4, 5) * 1e-9, Vector3d(4.5, 4.25, 4.25) * 1e-9, - Vector3d(IGN_SQRT2, IGN_SQRT2, 1) * 0.25e-9) + Vector3d(GZ_SQRT2, GZ_SQRT2, 1) * 0.25e-9) # different rotation self.verify_non_diagonal_moments_and_axes( Vector3d(4, 4, 5) * 1e-9, Vector3d(4.5, 4.25, 4.25) * 1e-9, - Vector3d(-IGN_SQRT2, -IGN_SQRT2, 1) * 0.25e-9) + Vector3d(-GZ_SQRT2, -GZ_SQRT2, 1) * 0.25e-9) # different rotation self.verify_non_diagonal_moments_and_axes( Vector3d(4, 4, 5) * 1e-9, Vector3d(4.5, 4.25, 4.25) * 1e-9, - Vector3d(IGN_SQRT2, -IGN_SQRT2, -1) * 0.25e-9, 1e-15) + Vector3d(GZ_SQRT2, -GZ_SQRT2, -1) * 0.25e-9, 1e-15) # Principal moments [4, 4, 6] # rotate by 30, 60, 0 degrees @@ -587,12 +587,12 @@ def test_principal_axes_offset_no_repeat(self): # Tri-diagonal matrix with identical diagonal terms self.verify_non_diagonal_moments_and_axes( - Vector3d(4-IGN_SQRT2, 4, 4+IGN_SQRT2), + Vector3d(4-GZ_SQRT2, 4, 4+GZ_SQRT2), Vector3d(4.0, 4.0, 4.0), Vector3d(-1.0, 0, -1.0)) # small magnitude, use tolerance of 1e-15 self.verify_non_diagonal_moments_and_axes( - Vector3d(4-IGN_SQRT2, 4, 4+IGN_SQRT2) * 1e-9, + Vector3d(4-GZ_SQRT2, 4, 4+GZ_SQRT2) * 1e-9, Vector3d(4.0, 4.0, 4.0) * 1e-9, Vector3d(-1.0, 0, -1.0) * 1e-9, 1e-15) @@ -710,7 +710,7 @@ def test_equivalent_box(self): rot = Quaterniond() self.assertTrue(m.equivalent_box(size, rot, -1e-6)) self.assertEqual(size, Vector3d(9, 4, 1)) - self.assertEqual(rot, Quaterniond(0, 0, IGN_PI/2)) + self.assertEqual(rot, Quaterniond(0, 0, GZ_PI/2)) m2 = MassMatrix3d() self.assertTrue(m2.set_from_box(mass, size, rot)) @@ -726,8 +726,8 @@ def test_equivalent_box(self): self.assertTrue(m.equivalent_box(size, rot)) self.assertEqual(size, Vector3d(9, 4, 1)) # There are multiple correct rotations due to box symmetry - self.assertTrue(rot == Quaterniond(0, 0, IGN_PI/4) or - rot == Quaterniond(IGN_PI, 0, IGN_PI/4)) + self.assertTrue(rot == Quaterniond(0, 0, GZ_PI/4) or + rot == Quaterniond(GZ_PI, 0, GZ_PI/4)) m2 = MassMatrix3d() self.assertTrue(m2.set_from_box(mass, size, rot)) @@ -778,7 +778,7 @@ def test_set_from_cylinderZ(self): self.assertEqual(m.diagonal_moments(), ixxyyzz) self.assertEqual(m.off_diagonal_moments(), Vector3d.ZERO) - density = mass / (IGN_PI * radius * radius * length) + density = mass / (GZ_PI * radius * radius * length) mat = Material(density) self.assertEqual(density, mat.density()) m1 = MassMatrix3d() @@ -813,7 +813,7 @@ def test_set_from_sphere(self): self.assertEqual(m.diagonal_moments(), ixxyyzz) self.assertEqual(m.off_diagonal_moments(), Vector3d.ZERO) - density = mass / ((4.0/3.0) * IGN_PI * math.pow(radius, 3)) + density = mass / ((4.0/3.0) * GZ_PI * math.pow(radius, 3)) mat = Material(density) self.assertEqual(density, mat.density()) m1 = MassMatrix3d() diff --git a/src/ruby/Helpers.i b/src/ruby/Helpers.i index 7aabfbb17..8abbb6567 100644 --- a/src/ruby/Helpers.i +++ b/src/ruby/Helpers.i @@ -23,20 +23,25 @@ %include "std_string.i" %include "std_vector.i" -/// \brief Define IGN_PI, IGN_PI_2, and IGN_PI_4. +/// \brief Define GZ_PI, GZ_PI_2, and GZ_PI_4. /// This was put here for Windows support. #ifdef M_PI -#define IGN_PI M_PI -#define IGN_PI_2 M_PI_2 -#define IGN_PI_4 M_PI_4 -#define IGN_SQRT2 M_SQRT2 +#define GZ_PI M_PI +#define GZ_PI_2 M_PI_2 +#define GZ_PI_4 M_PI_4 +#define GZ_SQRT2 M_SQRT2 #else -#define IGN_PI 3.14159265358979323846 -#define IGN_PI_2 1.57079632679489661923 -#define IGN_PI_4 0.78539816339744830962 -#define IGN_SQRT2 1.41421356237309504880 +#define GZ_PI 3.14159265358979323846 +#define GZ_PI_2 1.57079632679489661923 +#define GZ_PI_4 0.78539816339744830962 +#define GZ_SQRT2 1.41421356237309504880 #endif +// TODO(CH3): Deprecated. Remove on tock. +#define IGN_PI GZ_PI +#define IGN_PI_2 GZ_PI_2 +#define IGN_PI_4 GZ_PI_4 +#define IGN_SQRT2 GZ_SQRT2 // The uppercase functions in the pythoncode block are defined with `#define` in cpp // but in python this may generate some issues. A workaround is to create a Python function. @@ -45,17 +50,33 @@ %pythoncode %{ import math +def gz_sphere_volume(_radius): + return (4.0*GZ_PI*math.pow(_radius, 3)/3.0) + +def gz_cylinder_volume(_r, _l): + return (_l * GZ_PI * math.pow(_r, 2)) + +def gz_box_volume(_x, _y, _z): + return (_x *_y * _z) + +def gz_box_volume_v(_v): + return (_v.x() *_v.y() * _v.z()) + +# TODO(CH3): Deprecated. Remove on tock. def ign_sphere_volume(_radius): - return (4.0*IGN_PI*math.pow(_radius, 3)/3.0) + return gz_sphere_volume(_radius) +# TODO(CH3): Deprecated. Remove on tock. def ign_cylinder_volume(_r, _l): - return (_l * IGN_PI * math.pow(_r, 2)) + return gz_cylinder_volume(_r, _l) +# TODO(CH3): Deprecated. Remove on tock. def ign_box_volume(_x, _y, _z): - return (_x *_y * _z) + return gz_box_volume(_x, _y, _z) +# TODO(CH3): Deprecated. Remove on tock. def ign_box_volume_v(_v): - return (_v.x() *_v.y() * _v.z()) + return gz_box_volume_v(_v) def sort2(_a, _b): def swap(s1, s2): @@ -162,25 +183,37 @@ namespace gz { %rename("%(undercase)s", %$isfunction, notregexmatch$name="^[A-Z]*$") ""; - static const size_t IGN_ZERO_SIZE_T = 0u; + static const size_t GZ_ZERO_SIZE_T = 0u; + + static const size_t GZ_ONE_SIZE_T = 1u; - static const size_t IGN_ONE_SIZE_T = 1u; + static const size_t GZ_TWO_SIZE_T = 2u; - static const size_t IGN_TWO_SIZE_T = 2u; + static const size_t GZ_THREE_SIZE_T = 3u; - static const size_t IGN_THREE_SIZE_T = 3u; + static const size_t GZ_FOUR_SIZE_T = 4u; - static const size_t IGN_FOUR_SIZE_T = 4u; + static const size_t GZ_FIVE_SIZE_T = 5u; - static const size_t IGN_FIVE_SIZE_T = 5u; + static const size_t GZ_SIX_SIZE_T = 6u; - static const size_t IGN_SIX_SIZE_T = 6u; + static const size_t GZ_SEVEN_SIZE_T = 7u; - static const size_t IGN_SEVEN_SIZE_T = 7u; + static const size_t GZ_EIGHT_SIZE_T = 8u; - static const size_t IGN_EIGHT_SIZE_T = 8u; + static const size_t GZ_NINE_SIZE_T = 9u; - static const size_t IGN_NINE_SIZE_T = 9u; + // TODO(CH3): Deprecated. Remove on tock. + constexpr auto GZ_DEPRECATED(7) IGN_ZERO_SIZE_T = &GZ_ZERO_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_ONE_SIZE_T = &GZ_ONE_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_TWO_SIZE_T = &GZ_TWO_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_THREE_SIZE_T = &GZ_THREE_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_FOUR_SIZE_T = &GZ_FOUR_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_FIVE_SIZE_T = &GZ_FIVE_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_SIX_SIZE_T = &GZ_SIX_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_SEVEN_SIZE_T = &GZ_SEVEN_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_EIGHT_SIZE_T = &GZ_EIGHT_SIZE_T; + constexpr auto GZ_DEPRECATED(7) IGN_NINE_SIZE_T = &GZ_NINE_SIZE_T; static const double MAX_D = std::numeric_limits::max(); diff --git a/src/ruby/Inertial.i b/src/ruby/Inertial.i index 49b4c34d5..bc7e385c6 100644 --- a/src/ruby/Inertial.i +++ b/src/ruby/Inertial.i @@ -40,7 +40,7 @@ namespace gz public: ~Inertial() = default; public: bool SetMassMatrix(const MassMatrix3 &_m, - const T _tolerance = IGN_MASSMATRIX3_DEFAULT_TOLERANCE); + const T _tolerance = GZ_MASSMATRIX3_DEFAULT_TOLERANCE); public: const MassMatrix3 &MassMatrix() const; diff --git a/src/ruby/MassMatrix3.i b/src/ruby/MassMatrix3.i index 32c02a8cd..4e13f035b 100644 --- a/src/ruby/MassMatrix3.i +++ b/src/ruby/MassMatrix3.i @@ -67,18 +67,18 @@ namespace gz public: bool operator==(const MassMatrix3 &_m) const; public: bool operator!=(const MassMatrix3 &_m) const; public: bool IsNearPositive(const T _tolerance = - IGN_MASSMATRIX3_DEFAULT_TOLERANCE) const; + GZ_MASSMATRIX3_DEFAULT_TOLERANCE) const; public: bool IsPositive(const T _tolerance = - IGN_MASSMATRIX3_DEFAULT_TOLERANCE) const; + GZ_MASSMATRIX3_DEFAULT_TOLERANCE) const; public: T Epsilon(const T _tolerance = - IGN_MASSMATRIX3_DEFAULT_TOLERANCE) const; + GZ_MASSMATRIX3_DEFAULT_TOLERANCE) const; public: static T Epsilon(const Vector3 &_moments, const T _tolerance = - IGN_MASSMATRIX3_DEFAULT_TOLERANCE); + GZ_MASSMATRIX3_DEFAULT_TOLERANCE); public: bool IsValid(const T _tolerance = - IGN_MASSMATRIX3_DEFAULT_TOLERANCE) const; + GZ_MASSMATRIX3_DEFAULT_TOLERANCE) const; public: static bool ValidMoments(const Vector3 &_moments, - const T _tolerance = IGN_MASSMATRIX3_DEFAULT_TOLERANCE); + const T _tolerance = GZ_MASSMATRIX3_DEFAULT_TOLERANCE); public: Vector3 PrincipalMoments(const T _tol = 1e-6) const; public: Quaternion PrincipalAxesOffset(const T _tol = 1e-6) const; public: bool EquivalentBox(Vector3 &_size, From 9e756fe1eb3fb2f0bc5f6e78ead3ea8eb905086f Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Tue, 21 Jun 2022 16:21:59 -0500 Subject: [PATCH 19/25] Suppress warnings (#444) * Suppress zero variadic macro args message * Remove unused clang flag, suppress ruby warnings Signed-off-by: Michael Carroll --- src/python_pybind11/src/Filter.hh | 2 +- src/python_pybind11/src/SignalStats.cc | 2 +- src/ruby/CMakeLists.txt | 4 ++-- test/integration/deprecated_TEST.cc | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/python_pybind11/src/Filter.hh b/src/python_pybind11/src/Filter.hh index 01c10549b..3c6ed2d32 100644 --- a/src/python_pybind11/src/Filter.hh +++ b/src/python_pybind11/src/Filter.hh @@ -66,7 +66,7 @@ public: PYBIND11_OVERLOAD_PURE( const T&, // Return type (ret_type) Filter, // Parent class (cname) - Value // Name of function in C++ (must match Python name) + Value, // Name of function in C++ (must match Python name) ); } }; diff --git a/src/python_pybind11/src/SignalStats.cc b/src/python_pybind11/src/SignalStats.cc index 6013df9b6..1dc256041 100644 --- a/src/python_pybind11/src/SignalStats.cc +++ b/src/python_pybind11/src/SignalStats.cc @@ -436,7 +436,7 @@ class SignalRootMeanSquareTrampoline : std::string, // Return type (ret_type) gz::math::SignalStatistic, // Parent class (cname) // Name of function in C++ (must match Python name) (fn) - ShortName + ShortName, ); } // Trampoline (need one for each virtual function) diff --git a/src/ruby/CMakeLists.txt b/src/ruby/CMakeLists.txt index ddf609768..5f0c20488 100644 --- a/src/ruby/CMakeLists.txt +++ b/src/ruby/CMakeLists.txt @@ -53,7 +53,7 @@ if (RUBY_FOUND) # Suppress warnings on SWIG-generated files target_compile_options(${SWIG_RB_LIB} PRIVATE $<$:-Wno-pedantic -Wno-shadow -Wno-maybe-uninitialized -Wno-unused-parameter> - $<$:-Wno-shadow -Wno-maybe-uninitialized -Wno-unused-parameter> + $<$:-Wno-shadow -Wno-unused-parameter -Wno-deprecated-declarations> $<$:-Wno-shadow -Wno-maybe-uninitialized -Wno-unused-parameter> ) target_include_directories(${SWIG_RB_LIB} SYSTEM PUBLIC ${RUBY_INCLUDE_DIRS}) @@ -86,7 +86,7 @@ if (RUBY_FOUND) foreach (test ${ruby_tests}) add_test(NAME ${test}.rb COMMAND ruby -I${FAKE_INSTALL_PREFIX}/lib/ruby/ignition ${CMAKE_SOURCE_DIR}/src/ruby/${test}.rb - --gtest_output=xml:${CMAKE_BINARY_DIR}/test_results/${test}rb.xml) + --gtest_output=xml:${CMAKE_BINARY_DIR}/test_results/${test}rb.xml) set_tests_properties(${test}.rb PROPERTIES ENVIRONMENT "${_env_vars}") endforeach() diff --git a/test/integration/deprecated_TEST.cc b/test/integration/deprecated_TEST.cc index 9407ad9bf..91b7cd226 100644 --- a/test/integration/deprecated_TEST.cc +++ b/test/integration/deprecated_TEST.cc @@ -27,6 +27,7 @@ TEST(Deprecated, IgnitionNamespace) { ignition::math::Angle angle; + (void) angle; } #undef SUPPRESS_IGNITION_HEADER_DEPRECATION From 2a7c853f99787059fa6cd136f4e9d425e388f041 Mon Sep 17 00:00:00 2001 From: Aditya Date: Wed, 22 Jun 2022 14:48:18 -0700 Subject: [PATCH 20/25] Updated comments, added radius check in tests Signed-off-by: Aditya --- include/gz/math/SphericalCoordinates.hh | 5 +++-- src/SphericalCoordinates.cc | 6 ++++++ src/SphericalCoordinates_TEST.cc | 24 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/include/gz/math/SphericalCoordinates.hh b/include/gz/math/SphericalCoordinates.hh index 9fa77f93b..ac787d5dc 100644 --- a/include/gz/math/SphericalCoordinates.hh +++ b/include/gz/math/SphericalCoordinates.hh @@ -185,8 +185,8 @@ namespace gz /// latitude and longitude. It assumes that both points are at sea level. /// Example: _latA = 38.0016667 and _lonA = -123.0016667) represents /// the point with latitude 38d 0'6.00"N and longitude 123d 0'6.00"W. - /// This is different from the static Distance() method as it takes into - /// account the surface type. + /// This is different from the deprecated static Distance() method as it + /// takes into account the set surface's radius. /// \param[in] _latA Latitude of point A. /// \param[in] _lonA Longitude of point A. /// \param[in] _latB Latitude of point B. @@ -243,6 +243,7 @@ namespace gz /// \brief Set SurfaceType for planetary surface model with /// custom ellipsoid properties. /// \param[in] _type SurfaceType value. + /// \param[in] _radius Radius of the surface. /// \param[in] _axisEquatorial Equatorial axis of the surface. /// \param[in] _axisPolar Polar axis of the surface. /// \param[in] _flattening Falttening parameter of the surface. diff --git a/src/SphericalCoordinates.cc b/src/SphericalCoordinates.cc index 50d96ad21..cd98f0ede 100644 --- a/src/SphericalCoordinates.cc +++ b/src/SphericalCoordinates.cc @@ -283,6 +283,12 @@ void SphericalCoordinates::SetSurface(const SurfaceType &_type) break; } + case CUSTOM_SURFACE: + { + std::cerr << "For custom surfaces, use SetSurface(type, radius," + "axisEquatorial, axisPolar, flattening)" << std::endl; + break; + } default: { std::cerr << "Unknown surface type[" diff --git a/src/SphericalCoordinates_TEST.cc b/src/SphericalCoordinates_TEST.cc index 303545acc..2b39eb838 100644 --- a/src/SphericalCoordinates_TEST.cc +++ b/src/SphericalCoordinates_TEST.cc @@ -113,6 +113,14 @@ TEST(SphericalCoordinatesTest, SetFunctions) EXPECT_EQ(sc.LongitudeReference(), gz::math::Angle()); EXPECT_EQ(sc.HeadingOffset(), gz::math::Angle()); EXPECT_NEAR(sc.ElevationReference(), 0.0, 1e-6); + EXPECT_NEAR(sc.SurfaceRadius(), + 6371000.0, 1e-3); + EXPECT_NEAR(sc.SurfaceAxisEquatorial(), + 6378137.0, 1e-3); + EXPECT_NEAR(sc.SurfaceAxisPolar(), + 6356752.314245, 1e-3); + EXPECT_NEAR(sc.SurfaceFlattening(), + 1.0/298.257223563, 1e-5); { gz::math::Angle lat(0.3), lon(-1.2), heading(0.5); @@ -128,6 +136,14 @@ TEST(SphericalCoordinatesTest, SetFunctions) EXPECT_EQ(sc.LongitudeReference(), lon); EXPECT_EQ(sc.HeadingOffset(), heading); EXPECT_NEAR(sc.ElevationReference(), elev, 1e-6); + EXPECT_NEAR(sc.SurfaceRadius(), + 6371000.0, 1e-3); + EXPECT_NEAR(sc.SurfaceAxisEquatorial(), + 6378137.0, 1e-3); + EXPECT_NEAR(sc.SurfaceAxisPolar(), + 6356752.314245, 1e-3); + EXPECT_NEAR(sc.SurfaceFlattening(), + 1.0/298.257223563, 1e-5); } // Moon surface type @@ -135,6 +151,14 @@ TEST(SphericalCoordinatesTest, SetFunctions) math::SphericalCoordinates moonSC(st); moonSC.SetSurface(st); EXPECT_EQ(moonSC.Surface(), st); + EXPECT_NEAR(moonSC.SurfaceRadius(), + 1737400.0, 1e-3); + EXPECT_NEAR(moonSC.SurfaceAxisEquatorial(), + 1738100.0, 1e-3); + EXPECT_NEAR(moonSC.SurfaceAxisPolar(), + 1736000.0, 1e-3); + EXPECT_NEAR(moonSC.SurfaceFlattening(), + 0.0012, 1e-5); } ////////////////////////////////////////////////// From 1fa3f5a1d8fbfa82363f366c61b66dece04b9bc0 Mon Sep 17 00:00:00 2001 From: Aditya Date: Wed, 29 Jun 2022 12:09:51 -0700 Subject: [PATCH 21/25] Updated python tests Signed-off-by: Aditya --- src/SphericalCoordinates_TEST.cc | 2 +- .../src/SphericalCoordinates.cc | 8 +- .../test/SphericalCoordinates_TEST.py | 116 +++++++++++++++++- 3 files changed, 116 insertions(+), 10 deletions(-) diff --git a/src/SphericalCoordinates_TEST.cc b/src/SphericalCoordinates_TEST.cc index 2b39eb838..693bfe4ae 100644 --- a/src/SphericalCoordinates_TEST.cc +++ b/src/SphericalCoordinates_TEST.cc @@ -422,7 +422,7 @@ TEST(SphericalCoordinatesTest, Distance) // Using a custom surface. // For custom surfaces, the surface properties need to be set. - // THis one will throw an error. + // This one will throw an error. auto invalidCustomSC = math::SphericalCoordinates( math::SphericalCoordinates::CUSTOM_SURFACE); // This one should be accepted. diff --git a/src/python_pybind11/src/SphericalCoordinates.cc b/src/python_pybind11/src/SphericalCoordinates.cc index 23deff49a..4891f282c 100644 --- a/src/python_pybind11/src/SphericalCoordinates.cc +++ b/src/python_pybind11/src/SphericalCoordinates.cc @@ -75,16 +75,16 @@ void defineMathSphericalCoordinates(py::module &m, const std::string &typestr) .def("surface", &Class::Surface, "Get SurfaceType currently in use.") - .def("get_surface_radius", + .def("surface_radius", &Class::SurfaceRadius, "Get the radius of the surface.") - .def("get_surface_axis_equatorial", + .def("surface_axis_equatorial", &Class::SurfaceAxisEquatorial, "Get the major of the surface.") - .def("get_surface_axis_polar", + .def("surface_axis_polar", &Class::SurfaceAxisPolar, "Get the minor axis of the surface.") - .def("get_surface_flattening", + .def("surface_flattening", &Class::SurfaceFlattening, "Get the flattening parameter of the surface.") .def("latitude_reference", diff --git a/src/python_pybind11/test/SphericalCoordinates_TEST.py b/src/python_pybind11/test/SphericalCoordinates_TEST.py index baffa1bf9..51008b368 100644 --- a/src/python_pybind11/test/SphericalCoordinates_TEST.py +++ b/src/python_pybind11/test/SphericalCoordinates_TEST.py @@ -67,6 +67,18 @@ def test_convert(self): self.assertEqual("EARTH_WGS84", SphericalCoordinates.convert(st)) + # For Moon surface type + st = SphericalCoordinates.MOON_SCS + self.assertEqual(SphericalCoordinates.convert("MOON_SCS"), st) + self.assertEqual("MOON_SCS", SphericalCoordinates.convert(st)) + + # For custom surface type + st = SphericalCoordinates.CUSTOM_SURFACE + self.assertEqual(SphericalCoordinates.convert("CUSTOM_SURFACE"), + st) + self.assertEqual("CUSTOM_SURFACE", + SphericalCoordinates.convert(st)) + def test_set_functions(self): # Default surface type st = SphericalCoordinates.EARTH_WGS84 @@ -78,6 +90,13 @@ def test_set_functions(self): self.assertEqual(sc.longitude_reference(), Angle()) self.assertEqual(sc.heading_offset(), Angle()) self.assertAlmostEqual(sc.elevation_reference(), 0.0, delta=1e-6) + self.assertAlmostEqual(sc.surface_radius(), 6371000.0, delta=1e-3) + self.assertAlmostEqual(sc.surface_axis_equatorial(), + 6378137.0, delta=1e-3) + self.assertAlmostEqual(sc.surface_axis_polar(), + 6356752.314245, delta=1e-3) + self.assertAlmostEqual(sc.surface_flattening(), + 1.0/298.257223563, delta=1e-5) lat = Angle(0.3) lon = Angle(-1.2) @@ -94,6 +113,63 @@ def test_set_functions(self): self.assertEqual(sc.longitude_reference(), lon) self.assertEqual(sc.heading_offset(), heading) self.assertAlmostEqual(sc.elevation_reference(), elev, delta=1e-6) + self.assertAlmostEqual(sc.surface_radius(), 6371000.0, delta=1e-3) + self.assertAlmostEqual(sc.surface_axis_equatorial(), + 6378137.0, delta=1e-3) + self.assertAlmostEqual(sc.surface_axis_polar(), + 6356752.314245, delta=1e-3) + self.assertAlmostEqual(sc.surface_flattening(), + 1.0/298.257223563, delta=1e-5) + + # Moon surface type + st = SphericalCoordinates.MOON_SCS + sc = SphericalCoordinates(st) + sc.set_surface(st) + self.assertAlmostEqual(sc.surface_radius(), 1737400.0, + delta=1e-3) + self.assertAlmostEqual(sc.surface_axis_equatorial(), + 1738100.0, delta=1e-3) + self.assertAlmostEqual(sc.surface_axis_polar(), + 1736000.0, delta=1e-3) + self.assertAlmostEqual(sc.surface_flattening(), + 0.0012, delta=1e-5) + + def test_invalid_parameters(self): + # Earth's constants + g_EarthWGS84AxisEquatorial = 6378137.0; + g_EarthWGS84AxisPolar = 6356752.314245; + g_EarthWGS84Flattening = 1.0/298.257223563; + g_EarthRadius = 6371000.0; + + # Create a custom surface with invalid parameters + sc_invalid = SphericalCoordinates( + SphericalCoordinates.CUSTOM_SURFACE, + -1, -1, -1, -1) + + # These should be rejected and default to Earth's parameters + self.assertAlmostEqual(sc_invalid.surface_radius(), + g_EarthRadius, delta=1e-3) + self.assertAlmostEqual(sc_invalid.surface_axis_equatorial(), + g_EarthWGS84AxisEquatorial, delta=1e-3) + self.assertAlmostEqual(sc_invalid.surface_axis_polar(), + g_EarthWGS84AxisPolar, delta=1e-3) + self.assertAlmostEqual(sc_invalid.surface_flattening(), + g_EarthWGS84Flattening, delta=1e-3) + + # Creating a custom surface with valid parameters + sc_valid = SphericalCoordinates( + SphericalCoordinates.CUSTOM_SURFACE, + 100, 100, 100, 0) + + # These should be accepted + self.assertAlmostEqual(sc_valid.surface_radius(), + 100, delta=1e-3) + self.assertAlmostEqual(sc_valid.surface_axis_equatorial(), + 100, delta=1e-3) + self.assertAlmostEqual(sc_valid.surface_axis_polar(), + 100, delta=1e-3) + self.assertAlmostEqual(sc_valid.surface_flattening(), + 0, delta=1e-3) def test_coordinate_transforms(self): # Default surface type @@ -263,14 +339,44 @@ def test_distance(self): longA.set_degree(-122.249972) latB.set_degree(46.124953) longB.set_degree(-122.251683) - d = SphericalCoordinates.distance_WGS84(latA, longA, latB, longB) - - self.assertAlmostEqual(14002, d, delta=20) + d1 = SphericalCoordinates.distance_WGS84(latA, longA, latB, longB) + + self.assertAlmostEqual(14002, d1, delta=20) + + # Using the non static method. The default surface is EARTH_WGS84. + earth_sc = SphericalCoordinates() + d2 = earth_sc.distance_between_points(latA, longA, latB, longB) + self.assertAlmostEqual(d1, d2, delta=0.1) + + earth_sc = SphericalCoordinates(SphericalCoordinates.EARTH_WGS84) + d3 = earth_sc.distance_between_points(latA, longA, latB, longB) + self.assertAlmostEqual(d2, d3, delta=0.1) + + # Using the surface type as Moon. + moon_sc = SphericalCoordinates(SphericalCoordinates.MOON_SCS) + d4 = moon_sc.distance_between_points(latA, longA, latB, longB) + self.assertAlmostEqual(3820, d4, delta=5) + + # Using a custom surface + # For custom surfaces, the surface properties need to be set. + # This line should throw an error. + invalid_custom_sc = SphericalCoordinates( + SphericalCoordinates.CUSTOM_SURFACE) + # This one should be accepted. + valid_custom_sc = SphericalCoordinates( + SphericalCoordinates.CUSTOM_SURFACE, + 6371000.0, + 6378137.0, + 6356752.314245, + 1.0/298.25722); + + self.assertAlmostEqual(valid_custom_sc.distance_between_points(latA, longA, latB, longB), + d1, delta=0.1) def test_bad_set_surface(self): sc = SphericalCoordinates() - sc.set_surface(SphericalCoordinates.SurfaceType(2)) - self.assertEqual(sc.surface(), SphericalCoordinates.SurfaceType(2)) + sc.set_surface(SphericalCoordinates.SurfaceType(3)) + self.assertEqual(sc.surface(), SphericalCoordinates.SurfaceType(3)) def test_transform(self): sc = SphericalCoordinates() From ea26be048c5fce7a143c48ff304f46c2f5a76e18 Mon Sep 17 00:00:00 2001 From: Aditya Date: Wed, 29 Jun 2022 12:28:55 -0700 Subject: [PATCH 22/25] pybind export enums Signed-off-by: Aditya --- src/python_pybind11/src/SphericalCoordinates.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/python_pybind11/src/SphericalCoordinates.cc b/src/python_pybind11/src/SphericalCoordinates.cc index 4891f282c..bbcd91263 100644 --- a/src/python_pybind11/src/SphericalCoordinates.cc +++ b/src/python_pybind11/src/SphericalCoordinates.cc @@ -152,6 +152,12 @@ void defineMathSphericalCoordinates(py::module &m, const std::string &typestr) py::enum_(sphericalCoordinates, "SurfaceType") .value("EARTH_WGS84", Class::SurfaceType::EARTH_WGS84) .export_values(); + py::enum_(sphericalCoordinates, "SurfaceType") + .value("MOON_SCS", Class::SurfaceType::MOON_SCS) + .export_values(); + py::enum_(sphericalCoordinates, "SurfaceType") + .value("CUSTOM_SURFACE", Class::SurfaceType::CUSTOM_SURFACE) + .export_values(); } } // namespace python } // namespace math From d3b3a1f4ba4647eb41e5602feb6534ede19c5383 Mon Sep 17 00:00:00 2001 From: Aditya Date: Wed, 29 Jun 2022 13:02:53 -0700 Subject: [PATCH 23/25] pybind fix Signed-off-by: Aditya --- src/python_pybind11/src/SphericalCoordinates.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/python_pybind11/src/SphericalCoordinates.cc b/src/python_pybind11/src/SphericalCoordinates.cc index bbcd91263..452ab1fcd 100644 --- a/src/python_pybind11/src/SphericalCoordinates.cc +++ b/src/python_pybind11/src/SphericalCoordinates.cc @@ -151,11 +151,7 @@ void defineMathSphericalCoordinates(py::module &m, const std::string &typestr) .export_values(); py::enum_(sphericalCoordinates, "SurfaceType") .value("EARTH_WGS84", Class::SurfaceType::EARTH_WGS84) - .export_values(); - py::enum_(sphericalCoordinates, "SurfaceType") .value("MOON_SCS", Class::SurfaceType::MOON_SCS) - .export_values(); - py::enum_(sphericalCoordinates, "SurfaceType") .value("CUSTOM_SURFACE", Class::SurfaceType::CUSTOM_SURFACE) .export_values(); } From e0525a6c09647dfbfea54c2287d2fcf522527315 Mon Sep 17 00:00:00 2001 From: Aditya Date: Thu, 30 Jun 2022 12:42:59 -0700 Subject: [PATCH 24/25] Deduce flattening parameter from equatorial and polar axes Signed-off-by: Aditya --- include/gz/math/SphericalCoordinates.hh | 9 +-- src/SphericalCoordinates.cc | 56 ++++++------------- src/SphericalCoordinates_TEST.cc | 9 ++- .../src/SphericalCoordinates.cc | 4 +- .../test/SphericalCoordinates_TEST.py | 7 +-- 5 files changed, 27 insertions(+), 58 deletions(-) diff --git a/include/gz/math/SphericalCoordinates.hh b/include/gz/math/SphericalCoordinates.hh index ac787d5dc..ede47127d 100644 --- a/include/gz/math/SphericalCoordinates.hh +++ b/include/gz/math/SphericalCoordinates.hh @@ -87,14 +87,11 @@ namespace gz /// \param[in] _radius Radius of the surface. /// \param[in] _axisEquatorial Semi major axis of the surface. /// \param[in] _axisPolar Semi minor axis of the surface. - /// \param[in] _axisPolar Flattening parameter of the surface. public: SphericalCoordinates( const SurfaceType _type, const double _radius, const double _axisEquatorial, - const double _axisPolar, - const double _flattening - ); + const double _axisPolar); /// \brief Constructor with surface type, angle, and elevation inputs. /// \param[in] _type SurfaceType specification. @@ -246,13 +243,11 @@ namespace gz /// \param[in] _radius Radius of the surface. /// \param[in] _axisEquatorial Equatorial axis of the surface. /// \param[in] _axisPolar Polar axis of the surface. - /// \param[in] _flattening Falttening parameter of the surface. public: void SetSurface( const SurfaceType &_type, const double _radius, const double _axisEquatorial, - const double _axisPolar, - const double _flattening); + const double _axisPolar); /// \brief Set reference geodetic latitude. /// \param[in] _angle Reference geodetic latitude. diff --git a/src/SphericalCoordinates.cc b/src/SphericalCoordinates.cc index cd98f0ede..3ac487b20 100644 --- a/src/SphericalCoordinates.cc +++ b/src/SphericalCoordinates.cc @@ -160,13 +160,12 @@ SphericalCoordinates::SphericalCoordinates( const SurfaceType _type, const double _radius, const double _axisEquatorial, - const double _axisPolar, - const double _flattening) + const double _axisPolar) : SphericalCoordinates() { // Set properties this->SetSurface(_type, _radius, _axisEquatorial, - _axisPolar, _flattening); + _axisPolar); this->SetElevationReference(0.0); } @@ -286,7 +285,7 @@ void SphericalCoordinates::SetSurface(const SurfaceType &_type) case CUSTOM_SURFACE: { std::cerr << "For custom surfaces, use SetSurface(type, radius," - "axisEquatorial, axisPolar, flattening)" << std::endl; + "axisEquatorial, axisPolar)" << std::endl; break; } default: @@ -303,8 +302,7 @@ void SphericalCoordinates::SetSurface( const SurfaceType &_type, const double _radius, const double _axisEquatorial, - const double _axisPolar, - const double _flattening) + const double _axisPolar) { if ((_type != EARTH_WGS84) && (_type != MOON_SCS) && @@ -316,48 +314,26 @@ void SphericalCoordinates::SetSurface( } this->dataPtr->surfaceType = _type; - if (_axisEquatorial > 0) - { - this->dataPtr->ellA = _axisEquatorial; - } - else - { - std::cerr << "Value of _axisEquatorial should be greater than zero " - " defaulting to Earth's equatorial radius." << std::endl; - this->dataPtr->ellA = g_EarthWGS84AxisEquatorial; - } - if (_axisPolar > 0) + if ((_axisEquatorial > 0) + && (_axisPolar > 0) + && (_axisPolar <= _axisEquatorial) + && (_radius > 0)) { + this->dataPtr->ellA = _axisEquatorial; this->dataPtr->ellB = _axisPolar; + this->dataPtr->ellF = + (_axisEquatorial - _axisPolar) / _axisEquatorial; + this->dataPtr->surfaceRadius = _radius; } else { - std::cerr << "Value of _axisPolar should be greater than zero " - " defaulting to Earth's polar radius." << std::endl; - this->dataPtr->ellB = g_EarthWGS84AxisPolar; - } + std::cerr << "Invalid parameters found, defaulting to " + "Earth's parameters" << std::endl; - if (_flattening >= 0) - { - this->dataPtr->ellF = _flattening; - } - else - { - std::cerr << "Value of _flattening should be greater than " - " or equal to zero, defaulting to Earth's flattening value." - << std::endl; + this->dataPtr->ellA = g_EarthWGS84AxisEquatorial; + this->dataPtr->ellB = g_EarthWGS84AxisPolar; this->dataPtr->ellF = g_EarthWGS84Flattening; - } - - if (_radius > 0) - { - this->dataPtr->surfaceRadius = _radius; - } - else - { - std::cerr << "Value of _radius should be greater than zero " - " defaulting to Earth's radius."<< std::endl; this->dataPtr->surfaceRadius = g_EarthRadius; } diff --git a/src/SphericalCoordinates_TEST.cc b/src/SphericalCoordinates_TEST.cc index 693bfe4ae..50ab79289 100644 --- a/src/SphericalCoordinates_TEST.cc +++ b/src/SphericalCoordinates_TEST.cc @@ -174,7 +174,7 @@ TEST(SphericalCoordinatesTest, InvalidParameters) // Create a custom surface with invalid parameters. math::SphericalCoordinates scInvalid( math::SphericalCoordinates::CUSTOM_SURFACE, - -1, -1, -1, -1); + -1, -1, -1); // These should be rejected and default to Earth's // parameters. @@ -190,7 +190,7 @@ TEST(SphericalCoordinatesTest, InvalidParameters) // Create a custom surface with valid parameters. math::SphericalCoordinates scValid( math::SphericalCoordinates::CUSTOM_SURFACE, - 100, 100, 100, 0); + 100, 100, 100); // These should be accepted EXPECT_NEAR(scValid.SurfaceRadius(), 100, @@ -430,8 +430,7 @@ TEST(SphericalCoordinatesTest, Distance) math::SphericalCoordinates::SurfaceType::CUSTOM_SURFACE, 6371000.0, 6378137.0, - 6356752.314245, - 1.0/298.25722); + 6356752.314245); EXPECT_NEAR(customSC.DistanceBetweenPoints(latA, longA, latB, longB), d1, 0.1); @@ -442,7 +441,7 @@ TEST(SphericalCoordinatesTest, BadSetSurface) { math::SphericalCoordinates sc; sc.SetSurface(static_cast(3), - 10, 10, 10, 0); + 10, 10, 10); sc.SetSurface(static_cast(3)); EXPECT_EQ(sc.Surface(), 3); } diff --git a/src/python_pybind11/src/SphericalCoordinates.cc b/src/python_pybind11/src/SphericalCoordinates.cc index 452ab1fcd..8876edc0b 100644 --- a/src/python_pybind11/src/SphericalCoordinates.cc +++ b/src/python_pybind11/src/SphericalCoordinates.cc @@ -43,7 +43,7 @@ void defineMathSphericalCoordinates(py::module &m, const std::string &typestr) const gz::math::Angle &, const double, const gz::math::Angle &>()) .def(py::init()) + const double, const double>()) .def(py::self != py::self) .def(py::self == py::self) .def("spherical_from_local_position", @@ -107,7 +107,7 @@ void defineMathSphericalCoordinates(py::module &m, const std::string &typestr) .def("set_surface", py::overload_cast(&Class::SetSurface), + const double>(&Class::SetSurface), "Set SurfaceType for planetary surface model.") .def("set_latitude_reference", &Class::SetLatitudeReference, diff --git a/src/python_pybind11/test/SphericalCoordinates_TEST.py b/src/python_pybind11/test/SphericalCoordinates_TEST.py index 51008b368..f49a178dd 100644 --- a/src/python_pybind11/test/SphericalCoordinates_TEST.py +++ b/src/python_pybind11/test/SphericalCoordinates_TEST.py @@ -144,7 +144,7 @@ def test_invalid_parameters(self): # Create a custom surface with invalid parameters sc_invalid = SphericalCoordinates( SphericalCoordinates.CUSTOM_SURFACE, - -1, -1, -1, -1) + -1, -1, -1) # These should be rejected and default to Earth's parameters self.assertAlmostEqual(sc_invalid.surface_radius(), @@ -159,7 +159,7 @@ def test_invalid_parameters(self): # Creating a custom surface with valid parameters sc_valid = SphericalCoordinates( SphericalCoordinates.CUSTOM_SURFACE, - 100, 100, 100, 0) + 100, 100, 100) # These should be accepted self.assertAlmostEqual(sc_valid.surface_radius(), @@ -367,8 +367,7 @@ def test_distance(self): SphericalCoordinates.CUSTOM_SURFACE, 6371000.0, 6378137.0, - 6356752.314245, - 1.0/298.25722); + 6356752.314245); self.assertAlmostEqual(valid_custom_sc.distance_between_points(latA, longA, latB, longB), d1, delta=0.1) From b8c488711b0b2b15d3283019ff937d9ebcd7886e Mon Sep 17 00:00:00 2001 From: Aditya Date: Thu, 30 Jun 2022 13:12:36 -0700 Subject: [PATCH 25/25] Calculate radius from eq and polar axes Signed-off-by: Aditya --- include/gz/math/SphericalCoordinates.hh | 4 ---- src/SphericalCoordinates.cc | 11 +++++------ src/SphericalCoordinates_TEST.cc | 7 +++---- src/python_pybind11/src/SphericalCoordinates.cc | 6 +++--- src/python_pybind11/test/SphericalCoordinates_TEST.py | 5 ++--- 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/include/gz/math/SphericalCoordinates.hh b/include/gz/math/SphericalCoordinates.hh index ede47127d..546939646 100644 --- a/include/gz/math/SphericalCoordinates.hh +++ b/include/gz/math/SphericalCoordinates.hh @@ -84,12 +84,10 @@ namespace gz /// \brief Constructor with surface type input and properties /// input. To be used for CUSTOM_SURFACE. /// \param[in] _type SurfaceType specification. - /// \param[in] _radius Radius of the surface. /// \param[in] _axisEquatorial Semi major axis of the surface. /// \param[in] _axisPolar Semi minor axis of the surface. public: SphericalCoordinates( const SurfaceType _type, - const double _radius, const double _axisEquatorial, const double _axisPolar); @@ -240,12 +238,10 @@ namespace gz /// \brief Set SurfaceType for planetary surface model with /// custom ellipsoid properties. /// \param[in] _type SurfaceType value. - /// \param[in] _radius Radius of the surface. /// \param[in] _axisEquatorial Equatorial axis of the surface. /// \param[in] _axisPolar Polar axis of the surface. public: void SetSurface( const SurfaceType &_type, - const double _radius, const double _axisEquatorial, const double _axisPolar); diff --git a/src/SphericalCoordinates.cc b/src/SphericalCoordinates.cc index 3ac487b20..87934ee36 100644 --- a/src/SphericalCoordinates.cc +++ b/src/SphericalCoordinates.cc @@ -158,13 +158,12 @@ SphericalCoordinates::SphericalCoordinates(const SurfaceType _type) ////////////////////////////////////////////////// SphericalCoordinates::SphericalCoordinates( const SurfaceType _type, - const double _radius, const double _axisEquatorial, const double _axisPolar) : SphericalCoordinates() { // Set properties - this->SetSurface(_type, _radius, _axisEquatorial, + this->SetSurface(_type, _axisEquatorial, _axisPolar); this->SetElevationReference(0.0); @@ -300,7 +299,6 @@ void SphericalCoordinates::SetSurface(const SurfaceType &_type) ////////////////////////////////////////////////// void SphericalCoordinates::SetSurface( const SurfaceType &_type, - const double _radius, const double _axisEquatorial, const double _axisPolar) { @@ -317,14 +315,15 @@ void SphericalCoordinates::SetSurface( if ((_axisEquatorial > 0) && (_axisPolar > 0) - && (_axisPolar <= _axisEquatorial) - && (_radius > 0)) + && (_axisPolar <= _axisEquatorial)) { this->dataPtr->ellA = _axisEquatorial; this->dataPtr->ellB = _axisPolar; this->dataPtr->ellF = (_axisEquatorial - _axisPolar) / _axisEquatorial; - this->dataPtr->surfaceRadius = _radius; + // Arithmetic mean radius + this->dataPtr->surfaceRadius = + (2 * _axisEquatorial + _axisPolar) / 3.0; } else { diff --git a/src/SphericalCoordinates_TEST.cc b/src/SphericalCoordinates_TEST.cc index 50ab79289..26eee5552 100644 --- a/src/SphericalCoordinates_TEST.cc +++ b/src/SphericalCoordinates_TEST.cc @@ -174,7 +174,7 @@ TEST(SphericalCoordinatesTest, InvalidParameters) // Create a custom surface with invalid parameters. math::SphericalCoordinates scInvalid( math::SphericalCoordinates::CUSTOM_SURFACE, - -1, -1, -1); + -1, -1); // These should be rejected and default to Earth's // parameters. @@ -190,7 +190,7 @@ TEST(SphericalCoordinatesTest, InvalidParameters) // Create a custom surface with valid parameters. math::SphericalCoordinates scValid( math::SphericalCoordinates::CUSTOM_SURFACE, - 100, 100, 100); + 100, 100); // These should be accepted EXPECT_NEAR(scValid.SurfaceRadius(), 100, @@ -428,7 +428,6 @@ TEST(SphericalCoordinatesTest, Distance) // This one should be accepted. auto customSC = math::SphericalCoordinates( math::SphericalCoordinates::SurfaceType::CUSTOM_SURFACE, - 6371000.0, 6378137.0, 6356752.314245); @@ -441,7 +440,7 @@ TEST(SphericalCoordinatesTest, BadSetSurface) { math::SphericalCoordinates sc; sc.SetSurface(static_cast(3), - 10, 10, 10); + 10, 10); sc.SetSurface(static_cast(3)); EXPECT_EQ(sc.Surface(), 3); } diff --git a/src/python_pybind11/src/SphericalCoordinates.cc b/src/python_pybind11/src/SphericalCoordinates.cc index 8876edc0b..f2d27ed2e 100644 --- a/src/python_pybind11/src/SphericalCoordinates.cc +++ b/src/python_pybind11/src/SphericalCoordinates.cc @@ -43,7 +43,7 @@ void defineMathSphericalCoordinates(py::module &m, const std::string &typestr) const gz::math::Angle &, const double, const gz::math::Angle &>()) .def(py::init()) + const double>()) .def(py::self != py::self) .def(py::self == py::self) .def("spherical_from_local_position", @@ -106,8 +106,8 @@ void defineMathSphericalCoordinates(py::module &m, const std::string &typestr) "Set SurfaceType for planetary surface model.") .def("set_surface", py::overload_cast(&Class::SetSurface), + const double, const double + >(&Class::SetSurface), "Set SurfaceType for planetary surface model.") .def("set_latitude_reference", &Class::SetLatitudeReference, diff --git a/src/python_pybind11/test/SphericalCoordinates_TEST.py b/src/python_pybind11/test/SphericalCoordinates_TEST.py index f49a178dd..72f8d8a53 100644 --- a/src/python_pybind11/test/SphericalCoordinates_TEST.py +++ b/src/python_pybind11/test/SphericalCoordinates_TEST.py @@ -144,7 +144,7 @@ def test_invalid_parameters(self): # Create a custom surface with invalid parameters sc_invalid = SphericalCoordinates( SphericalCoordinates.CUSTOM_SURFACE, - -1, -1, -1) + -1, -1) # These should be rejected and default to Earth's parameters self.assertAlmostEqual(sc_invalid.surface_radius(), @@ -159,7 +159,7 @@ def test_invalid_parameters(self): # Creating a custom surface with valid parameters sc_valid = SphericalCoordinates( SphericalCoordinates.CUSTOM_SURFACE, - 100, 100, 100) + 100, 100) # These should be accepted self.assertAlmostEqual(sc_valid.surface_radius(), @@ -365,7 +365,6 @@ def test_distance(self): # This one should be accepted. valid_custom_sc = SphericalCoordinates( SphericalCoordinates.CUSTOM_SURFACE, - 6371000.0, 6378137.0, 6356752.314245);