Parasol Planning Library (PPL)
NBox.h
Go to the documentation of this file.
1 #ifndef PMPL_N_BOX_H_
2 #define PMPL_N_BOX_H_
3 
4 #include <cstddef>
5 #include <iostream>
6 #include <vector>
7 
9 
10 
14 class NBox {
15 
16  public:
17 
20 
23  explicit NBox(const size_t _n);
24 
28  explicit NBox(const std::vector<double>& _center);
29 
30  virtual ~NBox() noexcept;
31 
35 
37  size_t GetDimension() const noexcept;
38 
40  void SetCenter(const std::vector<double>& _c) noexcept;
41 
43  const std::vector<double>& GetCenter() const noexcept;
44 
48  const Range<double>& GetRange(const size_t _i) const noexcept;
49 
51  const std::vector<Range<double>>& GetRanges() const noexcept;
52 
56  void SetRange(const size_t _i, const Range<double>& _r) noexcept;
57  void SetRange(const size_t _i, Range<double>&& _r) noexcept;
58 
63  void SetRange(const size_t _i, const double _min, const double _max) noexcept;
64 
69  void Translate(const std::vector<double>& _v) noexcept;
70 
72  double GetVolume() const noexcept;
73 
79 
83  bool Contains(const std::vector<double>& _p) const noexcept;
84 
90  double Clearance(const std::vector<double>& _p) const noexcept;
91 
95  std::vector<double> ClearancePoint(std::vector<double> _p) const noexcept;
96 
100 
102  std::vector<double> Sample() const;
103 
105 
106  private:
107 
110 
111  std::vector<double> m_center;
112  std::vector<Range<double>> m_range;
113 
115 
116  friend std::istream& operator>>(std::istream& _is, NBox& _box);
117 };
118 
119 /*----------------------------------- I/O ------------------------------------*/
120 
121 std::istream&
122 operator>>(std::istream& _is, NBox& _box);
123 
124 std::ostream&
125 operator<<(std::ostream& _os, const NBox& _box);
126 
127 /*----------------------------------------------------------------------------*/
128 
129 #endif
An axis-aligned rectangular prism in n dimensions.
Definition: NBox.h:14
void SetRange(const size_t _i, const Range< double > &_r) noexcept
Definition: NBox.cpp:74
size_t GetDimension() const noexcept
Get the dimension of this box.
Definition: NBox.cpp:33
std::vector< double > ClearancePoint(std::vector< double > _p) const noexcept
Definition: NBox.cpp:153
void SetCenter(const std::vector< double > &_c) noexcept
Set the center point.
Definition: NBox.cpp:40
const Range< double > & GetRange(const size_t _i) const noexcept
Definition: NBox.cpp:60
const std::vector< double > & GetCenter() const noexcept
Get the center point.
Definition: NBox.cpp:53
virtual ~NBox() noexcept
bool Contains(const std::vector< double > &_p) const noexcept
Definition: NBox.cpp:121
std::vector< double > Sample() const
Sample a random point in the box with uniform probability.
Definition: NBox.cpp:197
void Translate(const std::vector< double > &_v) noexcept
Definition: NBox.cpp:98
NBox(const size_t _n)
Definition: NBox.cpp:13
double GetVolume() const noexcept
Compute the (hyper)volume or Lebesgue measure.
Definition: NBox.cpp:110
double Clearance(const std::vector< double > &_p) const noexcept
Definition: NBox.cpp:132
const std::vector< Range< double > > & GetRanges() const noexcept
Get all of the ranges.
Definition: NBox.cpp:67
A range of numeric values.
Definition: Range.h:17