From 907686b0b1e3f431c511e81c1787afb54bb5e2aa Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Fri, 25 Mar 2022 16:17:36 -0300 Subject: [PATCH 1/2] Make Interval construction constexpr Signed-off-by: Michel Hidalgo --- include/ignition/math/Interval.hh | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/include/ignition/math/Interval.hh b/include/ignition/math/Interval.hh index fb0229b10..115db95dc 100644 --- a/include/ignition/math/Interval.hh +++ b/include/ignition/math/Interval.hh @@ -51,11 +51,14 @@ namespace ignition /// \brief Constructor /// \param[in] _leftValue leftmost interval value - /// \param[in] _leftClosed whether the interval is left-closed or not + /// \param[in] _leftClosed whether the interval is + /// left-closed or not /// \param[in] _rightValue rightmost interval value - /// \param[in] _rightClosed whether the interval is right-closed or not - public: Interval(T _leftValue, bool _leftClosed, - T _rightValue, bool _rightClosed) + /// \param[in] _rightClosed whether the interval + /// is right-closed or not + public: constexpr Interval( + T _leftValue, bool _leftClosed, + T _rightValue, bool _rightClosed) : leftValue(std::move(_leftValue)), rightValue(std::move(_rightValue)), leftClosed(_leftClosed), @@ -67,7 +70,8 @@ namespace ignition /// \param[in] _leftValue leftmost interval value /// \param[in] _rightValue rightmost interval value /// \return the open interval - public: static Interval Open(T _leftValue, T _rightValue) + public: static constexpr Interval + Open(T _leftValue, T _rightValue) { return Interval( std::move(_leftValue), false, @@ -78,7 +82,8 @@ namespace ignition /// \param[in] _leftValue leftmost interval value /// \param[in] _rightValue rightmost interval value /// \return the left-closed interval - public: static Interval LeftClosed(T _leftValue, T _rightValue) + public: static constexpr Interval + LeftClosed(T _leftValue, T _rightValue) { return Interval( std::move(_leftValue), true, @@ -89,7 +94,8 @@ namespace ignition /// \param[in] _leftValue leftmost interval value /// \param[in] _rightValue rightmost interval value /// \return the left-closed interval - public: static Interval RightClosed(T _leftValue, T _rightValue) + public: static constexpr Interval + RightClosed(T _leftValue, T _rightValue) { return Interval( std::move(_leftValue), false, @@ -100,7 +106,8 @@ namespace ignition /// \param[in] _leftValue leftmost interval value /// \param[in] _rightValue rightmost interval value /// \return the closed interval - public: static Interval Closed(T _leftValue, T _rightValue) + public: static constexpr Interval + Closed(T _leftValue, T _rightValue) { return Interval{ std::move(_leftValue), true, @@ -276,7 +283,7 @@ namespace ignition namespace detail { template - const Interval gUnboundedInterval = + constexpr Interval gUnboundedInterval = Interval::Open(-std::numeric_limits::infinity(), std::numeric_limits::infinity()); } // namespace detail From 71c1140f60bb41e7c8c33f08e56f48cefbd922f7 Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Fri, 25 Mar 2022 16:18:11 -0300 Subject: [PATCH 2/2] Make Region3 construction constexpr Signed-off-by: Michel Hidalgo --- include/ignition/math/Region3.hh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/ignition/math/Region3.hh b/include/ignition/math/Region3.hh index 5d5bb4f8d..339a9d91b 100644 --- a/include/ignition/math/Region3.hh +++ b/include/ignition/math/Region3.hh @@ -60,7 +60,8 @@ namespace ignition /// \param[in] _ix x-axis interval /// \param[in] _iy y-axis interval /// \param[in] _iz z-axis interval - public: Region3(Interval _ix, Interval _iy, Interval _iz) + public: constexpr Region3( + Interval _ix, Interval _iy, Interval _iz) : ix(std::move(_ix)), iy(std::move(_iy)), iz(std::move(_iz)) { } @@ -74,7 +75,7 @@ namespace ignition /// \param[in] _zRight righmost z-axis interval value /// \return the (`_xLeft`, `_xRight`) ✕ (`_yLeft`, `_yRight`) /// ✕ (`_zLeft`, `_zRight`) open region - public: static Region3 Open( + public: static constexpr Region3 Open( T _xLeft, T _yLeft, T _zLeft, T _xRight, T _yRight, T _zRight) { @@ -92,7 +93,7 @@ namespace ignition /// \param[in] _zRight righmost z-axis interval value /// \return the [`_xLeft`, `_xRight`] ✕ [`_yLeft`, `_yRight`] /// ✕ [`_zLeft`, `_zRight`] closed region - public: static Region3 Closed( + public: static constexpr Region3 Closed( T _xLeft, T _yLeft, T _zLeft, T _xRight, T _yRight, T _zRight) { @@ -188,7 +189,7 @@ namespace ignition namespace detail { template - const Region3 gUnboundedRegion3( + constexpr Region3 gUnboundedRegion3( Interval::Open(-std::numeric_limits::infinity(), std::numeric_limits::infinity()), Interval::Open(-std::numeric_limits::infinity(),