Gazebo Math

API Reference

7.5.1
gz/math/Region3.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef GZ_MATH_REGION3_HH_
18 #define GZ_MATH_REGION3_HH_
19 
20 #include <cmath>
21 #include <limits>
22 #include <ostream>
23 #include <utility>
24 
25 #include <gz/math/Interval.hh>
26 #include <gz/math/Vector3.hh>
27 #include <gz/math/config.hh>
28 
29 namespace gz::math
30 {
31  // Inline bracket to help doxygen filtering.
32  inline namespace GZ_MATH_VERSION_NAMESPACE {
33  //
48  template <typename T>
49  class Region3
50  {
52  public: static const Region3<T> &Unbounded;
53 
55  public: Region3() = default;
56 
61  public: constexpr Region3(
62  Interval<T> _ix, Interval<T> _iy, Interval<T> _iz)
63  : ix(std::move(_ix)), iy(std::move(_iy)), iz(std::move(_iz))
64  {
65  }
66 
76  public: static constexpr Region3<T> Open(
77  T _xLeft, T _yLeft, T _zLeft,
78  T _xRight, T _yRight, T _zRight)
79  {
80  return Region3<T>(Interval<T>::Open(_xLeft, _xRight),
81  Interval<T>::Open(_yLeft, _yRight),
82  Interval<T>::Open(_zLeft, _zRight));
83  }
84 
94  public: static constexpr Region3<T> Closed(
95  T _xLeft, T _yLeft, T _zLeft,
96  T _xRight, T _yRight, T _zRight)
97  {
98  return Region3<T>(Interval<T>::Closed(_xLeft, _xRight),
99  Interval<T>::Closed(_yLeft, _yRight),
100  Interval<T>::Closed(_zLeft, _zRight));
101  }
102 
105  public: const Interval<T> &Ix() const { return this->ix; }
106 
109  public: const Interval<T> &Iy() const { return this->iy; }
110 
113  public: const Interval<T> &Iz() const { return this->iz; }
114 
119  public: bool Empty() const
120  {
121  return this->ix.Empty() || this->iy.Empty() || this->iz.Empty();
122  }
123 
127  public: bool Contains(const Vector3<T> &_point) const
128  {
129  return (this->ix.Contains(_point.X()) &&
130  this->iy.Contains(_point.Y()) &&
131  this->iz.Contains(_point.Z()));
132  }
133 
137  public: bool Contains(const Region3<T> &_other) const
138  {
139  return (this->ix.Contains(_other.ix) &&
140  this->iy.Contains(_other.iy) &&
141  this->iz.Contains(_other.iz));
142  }
143 
147  public: bool Intersects(const Region3<T>& _other) const
148  {
149  return (this->ix.Intersects(_other.ix) &&
150  this->iy.Intersects(_other.iy) &&
151  this->iz.Intersects(_other.iz));
152  }
153 
157  public: bool operator==(const Region3<T> &_other) const
158  {
159  return this->Contains(_other) && _other.Contains(*this);
160  }
161 
165  public: bool operator!=(const Region3<T> &_other) const
166  {
167  return !this->Contains(_other) || !_other.Contains(*this);
168  }
169 
174  public: friend std::ostream &operator<<(
175  std::ostream &_out, const gz::math::Region3<T> &_r)
176  {
177  return _out <<_r.ix << " x " << _r.iy << " x " << _r.iz;
178  }
179 
181  private: Interval<T> ix;
183  private: Interval<T> iy;
185  private: Interval<T> iz;
186  };
187 
188  namespace detail {
189  template<typename T>
190  constexpr Region3<T> gUnboundedRegion3(
197  }
198  template<typename T>
199  const Region3<T> &Region3<T>::Unbounded = detail::gUnboundedRegion3<T>;
200 
203  } // namespace GZ_MATH_VERSION_NAMESPACE
204 } // namespace gz::math
205 #endif // GZ_MATH_REGION3_HH_