/home/fwph/code/wurde/rde/core/Rectangle.H

Go to the documentation of this file.
00001 #ifndef Rectangle_H
00002 #define Rectangle_H
00003 
00023 #include <iostream>
00024 #include <Geometry.H>
00025 #include <Subspace.H>
00026 
00039 class Rectangle : public RnSubspace {
00040 
00045         friend
00046         std::ostream &operator<<(std::ostream &out, const Rectangle &rectangle) {
00047                 out << rectangle.minBound() << '\n' << rectangle.maxBound();
00048                 return out;}
00049 
00050 public:
00053         explicit Rectangle(const int dimension)
00054                 : RnSubspace(dimension),
00055                         m_min_bound(dimension),
00056                         m_max_bound(dimension) {}
00057 
00061         Rectangle(const RnPoint min_bound,
00062                                                 const RnPoint max_bound)
00063                 : RnSubspace(min_bound.n()),
00064                         m_min_bound(min_bound),
00065                         m_max_bound(max_bound) {
00066                 for(int i(0); i < this->n(); ++i)
00067                         if(m_min_bound[i] > m_max_bound[i])
00068                                 m_max_bound[i] = m_min_bound[i];
00069         }
00070 
00073         Rectangle(const Rectangle &rectangle)
00074                 : RnSubspace(rectangle),
00075                         m_min_bound(rectangle.minBound()),
00076                         m_max_bound(rectangle.maxBound()) {}
00077 
00079         virtual ~Rectangle() {}
00080 
00084         Rectangle &operator=(const Rectangle &rectangle) {
00085                 assert(rectangle.n() == this->n());
00086                 RnSubspace::operator=(rectangle);
00087                 m_min_bound = rectangle.minBound();
00088                 m_max_bound = rectangle.maxBound();
00089                 return *this;
00090         }
00091 
00095         bool operator==(const Rectangle &rectangle) const {
00096                 return (RnSubspace::operator==(rectangle)
00097                                                 && (m_min_bound == rectangle.minBound())
00098                                                 && (m_max_bound == rectangle.maxBound()));
00099         }
00100 
00102 
00103 
00104         RnPoint &minBound() {return m_min_bound;}
00106         RnPoint &maxBound() {return m_max_bound;}
00107 
00109         const RnPoint &minBound() const {return m_min_bound;}
00111         const RnPoint &maxBound() const {return m_max_bound;}
00112 
00114         double volume() const {
00115                 double v(1.0);
00116                 for(int d(0); d < n(); ++d) v *= maxBound()[d] - minBound()[d];
00117                 return v;}
00119 
00123         bool valid() const {
00124                 for(int i(0); i < this->n(); ++i)
00125                         if(m_max_bound[i] < m_min_bound[i]) return false;
00126                 return true;
00127         }
00128 
00130 
00131 
00134   bool interior(const RnPoint &point) const {
00135                 assert(this->n() == point.n());
00136                 for(int i(0); i < this->n(); ++i)
00137                         if((point[i] <= m_min_bound[i]) || (point[i] >= m_max_bound[i]))
00138                                 return false;
00139                 return true;
00140         }
00141 
00145         bool boundary(const RnPoint &point) const {
00146                 assert(this->n() == point.n());
00147                 bool frontier(false);
00148                 for(int i(0); i < this->n(); ++i) {
00149                         if((point[i] == m_min_bound[i]) || (point[i] == m_max_bound[i]))
00150                                 frontier = true;
00151                         if((point[i] < m_min_bound[i]) || (point[i] > m_max_bound[i]))
00152                                 return false;
00153                 }
00154                 return frontier;
00155         }
00156 
00160         bool closure(const RnPoint &point) const {
00161                 assert(this->n() == point.n());
00162                 for(int i(0); i < this->n(); ++i)
00163                         if((point[i] < m_min_bound[i]) || (point[i] > m_max_bound[i]))
00164                                 return false;
00165                 return true;
00166         }
00168 
00173         virtual void drawGnuplot(std::ostream &out,
00174                                                                                                          const int di = 0,
00175                                                                                                          const int dj = 1) const {
00176                 out << m_min_bound[di] << ' ' << m_min_bound[dj] << '\n'
00177                                 << m_min_bound[di] << ' ' << m_max_bound[dj] << '\n'
00178                                 << m_max_bound[di] << ' ' << m_max_bound[dj] << '\n'
00179                                 << m_max_bound[di] << ' ' << m_min_bound[dj] << '\n'
00180                                 << m_min_bound[di] << ' ' << m_min_bound[dj] << '\n';
00181         }
00182 
00183 private:
00185         RnPoint m_min_bound;
00186 
00188         RnPoint m_max_bound;
00189 };
00190 
00191 #endif // Rectangle_H

Generated on Thu Feb 1 15:31:54 2007 for WURDE by  doxygen 1.5.1