Gazebo Math

API Reference

6.15.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 ignition
30 {
31  namespace math
32  {
33  // Inline bracket to help doxygen filtering.
34  inline namespace IGNITION_MATH_VERSION_NAMESPACE {
35  //
50  template <typename T>
51  class Region3
52  {
54  public: static const Region3<T> &Unbounded;
55 
57  public: Region3() = default;
58 
63  public: constexpr Region3(
64  Interval<T> _ix, Interval<T> _iy, Interval<T> _iz)
65  : ix(std::move(_ix)), iy(std::move(_iy)), iz(std::move(_iz))
66  {
67  }
68 
78  public: static constexpr Region3<T> Open(
79  T _xLeft, T _yLeft, T _zLeft,
80  T _xRight, T _yRight, T _zRight)
81  {
82  return Region3<T>(Interval<T>::Open(_xLeft, _xRight),
83  Interval<T>::Open(_yLeft, _yRight),
84  Interval<T>::Open(_zLeft, _zRight));
85  }
86 
96  public: static constexpr Region3<T> Closed(
97  T _xLeft, T _yLeft, T _zLeft,
98  T _xRight, T _yRight, T _zRight)
99  {
100  return Region3<T>(Interval<T>::Closed(_xLeft, _xRight),
101  Interval<T>::Closed(_yLeft, _yRight),
102  Interval<T>::Closed(_zLeft, _zRight));
103  }
104 
107  public: const Interval<T> &Ix() const { return this->ix; }
108 
111  public: const Interval<T> &Iy() const { return this->iy; }
112 
115  public: const Interval<T> &Iz() const { return this->iz; }
116 
121  public: bool Empty() const
122  {
123  return this->ix.Empty() || this->iy.Empty() || this->iz.Empty();
124  }
125 
129  public: bool Contains(const Vector3<T> &_point) const
130  {
131  return (this->ix.Contains(_point.X()) &&
132  this->iy.Contains(_point.Y()) &&
133  this->iz.Contains(_point.Z()));
134  }
135 
139  public: bool Contains(const Region3<T> &_other) const
140  {
141  return (this->ix.Contains(_other.ix) &&
142  this->iy.Contains(_other.iy) &&
143  this->iz.Contains(_other.iz));
144  }
145 
149  public: bool Intersects(const Region3<T>& _other) const
150  {
151  return (this->ix.Intersects(_other.ix) &&
152  this->iy.Intersects(_other.iy) &&
153  this->iz.Intersects(_other.iz));
154  }
155 
159  public: bool operator==(const Region3<T> &_other) const
160  {
161  return this->Contains(_other) && _other.Contains(*this);
162  }
163 
167  public: bool operator!=(const Region3<T> &_other) const
168  {
169  return !this->Contains(_other) || !_other.Contains(*this);
170  }
171 
176  public: friend std::ostream &operator<<(
177  std::ostream &_out, const gz::math::Region3<T> &_r)
178  {
179  return _out <<_r.ix << " x " << _r.iy << " x " << _r.iz;
180  }
181 
183  private: Interval<T> ix;
185  private: Interval<T> iy;
187  private: Interval<T> iz;
188  };
189 
190  namespace detail {
191  template<typename T>
192  constexpr Region3<T> gUnboundedRegion3(
199  }
200  template<typename T>
201  const Region3<T> &Region3<T>::Unbounded = detail::gUnboundedRegion3<T>;
202 
205  }
206  }
207 }
208 
209 #endif
const Interval< T > & Iy() const
Get the y-axis interval for the region.
Definition: gz/math/Region3.hh:111
static constexpr Interval< T > Open(T _leftValue, T _rightValue)
Make an open interval (_leftValue, _rightValue)
Definition: gz/math/Interval.hh:74
Definition: gz/math/AdditivelySeparableScalarField3.hh:27
friend std::ostream & operator<<(std::ostream &_out, const Region3< T > &_r)
Stream insertion operator.
Definition: gz/math/Region3.hh:176
The Interval class represents a range of real numbers. Intervals may be open (a, b),...
Definition: gz/math/Interval.hh:44
bool operator==(const Region3< T > &_other) const
Equality test operator.
Definition: gz/math/Region3.hh:159
T X() const
Get the x value.
Definition: gz/math/Vector3.hh:654
The Region3 class represents the cartesian product of intervals Ix ✕ Iy ✕ Iz, one per axis,...
Definition: gz/math/Region3.hh:51
Region3()=default
Constructor.
static const Region3< T > & Unbounded
An unbounded region (-∞, ∞) ✕ (-∞, ∞) ✕ (-∞, ∞)
Definition: gz/math/Region3.hh:54
const Interval< T > & Ix() const
Get the x-axis interval for the region.
Definition: gz/math/Region3.hh:107
T Z() const
Get the z value.
Definition: gz/math/Vector3.hh:668
STL class.
The Vector3 class represents the generic vector containing 3 elements. Since it's commonly used to ke...
Definition: gz/math/Vector3.hh:41
static constexpr Region3< T > Open(T _xLeft, T _yLeft, T _zLeft, T _xRight, T _yRight, T _zRight)
Make an open region.
Definition: gz/math/Region3.hh:78
static constexpr Region3< T > Closed(T _xLeft, T _yLeft, T _zLeft, T _xRight, T _yRight, T _zRight)
Make a closed region.
Definition: gz/math/Region3.hh:96
bool Contains(const Region3< T > &_other) const
Check if the region contains _other region.
Definition: gz/math/Region3.hh:139
const Interval< T > & Iz() const
Get the z-axis interval for the region.
Definition: gz/math/Region3.hh:115
STL namespace.
bool Empty() const
Check if the region is empty A region is empty if any of the intervals it is defined with (i....
Definition: gz/math/Region3.hh:121
constexpr Region3(Interval< T > _ix, Interval< T > _iy, Interval< T > _iz)
Constructor.
Definition: gz/math/Region3.hh:63
bool Contains(const Vector3< T > &_point) const
Check if the region contains _point
Definition: gz/math/Region3.hh:129
bool operator!=(const Region3< T > &_other) const
Inequality test operator.
Definition: gz/math/Region3.hh:167
T Y() const
Get the y value.
Definition: gz/math/Vector3.hh:661
bool Intersects(const Region3< T > &_other) const
Check if the region intersects _other region.
Definition: gz/math/Region3.hh:149