00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #ifndef MLN_WIN_RECTANGLE2D_HH
00027 # define MLN_WIN_RECTANGLE2D_HH
00028 
00034 
00035 # include <mln/core/internal/classical_window_base.hh>
00036 # include <mln/core/alias/dpoint2d.hh>
00037 # include <mln/core/def/coord.hh>
00038 
00039 
00040 namespace mln
00041 {
00042 
00043   mln_internal_add_classical_window_trait(rectangle2d);
00044 
00045 
00046   namespace win
00047   {
00048 
00064     struct rectangle2d : public internal::classical_window_base< dpoint2d, rectangle2d >
00065     {
00073       rectangle2d(unsigned height, unsigned width);
00074 
00075 
00077       unsigned height() const;
00078 
00080       unsigned width() const;
00081 
00083       unsigned area() const;
00084 
00088       unsigned delta_() const;
00089 
00090 
00092       const std::vector<dpoint2d>& std_vector() const;
00093 
00094       void print_(std::ostream& ostr) const;
00095 
00096     protected:
00097 
00098       unsigned height_, width_;
00099     };
00100 
00101 
00102 
00103 # ifndef MLN_INCLUDE_ONLY
00104 
00105     inline
00106     rectangle2d::rectangle2d(unsigned height, unsigned width)
00107       : height_(height),
00108         width_(width)
00109     {
00110       mln_precondition(height % 2 == 1 && width % 2 == 1);
00111       const def::coord  drow = (def::coord) (height / 2);
00112       const def::coord dcol = (def::coord) (width / 2);
00113 
00114       for (def::coord row = (def::coord) -drow; row <= drow; ++row)
00115         for (def::coord col = (def::coord) -dcol; col <= dcol; ++col)
00116           this->insert(dpoint2d(row, col));
00117     }
00118 
00119     inline
00120     unsigned rectangle2d::height() const
00121     {
00122       return height_;
00123     }
00124 
00125     inline
00126     unsigned rectangle2d::width() const
00127     {
00128       return width_;
00129     }
00130 
00131     inline
00132     unsigned rectangle2d::area() const
00133     {
00134       return width_ * height_;
00135     }
00136 
00137     inline
00138     unsigned rectangle2d::delta_() const
00139     {
00140       return width_ > height_ ? width_ / 2 : height_ / 2;
00141     }
00142 
00143     inline
00144     const std::vector<dpoint2d>&
00145     rectangle2d::std_vector() const
00146     {
00147       return win_.std_vector();
00148     }
00149 
00150     inline
00151     void
00152     rectangle2d::print_(std::ostream& ostr) const
00153     {
00154       ostr << "[rectangle2d: width=" << width_ << ", height=" << height_ << ']';
00155     }
00156 
00157 # endif // ! MLN_INCLUDE_ONLY
00158 
00159   } 
00160 
00161 } 
00162 
00163 
00164 
00165 
00166 # include <mln/win/hline2d.hh>
00167 # include <mln/win/vline2d.hh>
00168 
00169 
00170 #endif // ! MLN_WIN_RECTANGLE2D_HH