Skip to content

Commit

Permalink
Fix unsafe globals in Interval and Region3 (#396)
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <[email protected]>
  • Loading branch information
hidmic authored Mar 30, 2022
1 parent dcde2c0 commit 120806b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
25 changes: 16 additions & 9 deletions include/ignition/math/Interval.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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<T> Open(T _leftValue, T _rightValue)
public: static constexpr Interval<T>
Open(T _leftValue, T _rightValue)
{
return Interval<T>(
std::move(_leftValue), false,
Expand All @@ -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<T> LeftClosed(T _leftValue, T _rightValue)
public: static constexpr Interval<T>
LeftClosed(T _leftValue, T _rightValue)
{
return Interval<T>(
std::move(_leftValue), true,
Expand All @@ -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<T> RightClosed(T _leftValue, T _rightValue)
public: static constexpr Interval<T>
RightClosed(T _leftValue, T _rightValue)
{
return Interval<T>(
std::move(_leftValue), false,
Expand All @@ -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<T> Closed(T _leftValue, T _rightValue)
public: static constexpr Interval<T>
Closed(T _leftValue, T _rightValue)
{
return Interval<T>{
std::move(_leftValue), true,
Expand Down Expand Up @@ -276,7 +283,7 @@ namespace ignition

namespace detail {
template<typename T>
const Interval<T> gUnboundedInterval =
constexpr Interval<T> gUnboundedInterval =
Interval<T>::Open(-std::numeric_limits<T>::infinity(),
std::numeric_limits<T>::infinity());
} // namespace detail
Expand Down
9 changes: 5 additions & 4 deletions include/ignition/math/Region3.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> _ix, Interval<T> _iy, Interval<T> _iz)
public: constexpr Region3(
Interval<T> _ix, Interval<T> _iy, Interval<T> _iz)
: ix(std::move(_ix)), iy(std::move(_iy)), iz(std::move(_iz))
{
}
Expand All @@ -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<T> Open(
public: static constexpr Region3<T> Open(
T _xLeft, T _yLeft, T _zLeft,
T _xRight, T _yRight, T _zRight)
{
Expand All @@ -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<T> Closed(
public: static constexpr Region3<T> Closed(
T _xLeft, T _yLeft, T _zLeft,
T _xRight, T _yRight, T _zRight)
{
Expand Down Expand Up @@ -188,7 +189,7 @@ namespace ignition

namespace detail {
template<typename T>
const Region3<T> gUnboundedRegion3(
constexpr Region3<T> gUnboundedRegion3(
Interval<T>::Open(-std::numeric_limits<T>::infinity(),
std::numeric_limits<T>::infinity()),
Interval<T>::Open(-std::numeric_limits<T>::infinity(),
Expand Down

0 comments on commit 120806b

Please sign in to comment.