• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

rectangle2d.hh

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
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   } // end of namespace mln::win
00160 
00161 } // end of namespace mln
00162 
00163 
00164 
00165 // When rectangle2d is involved, one surely also wants:
00166 # include <mln/win/hline2d.hh>
00167 # include <mln/win/vline2d.hh>
00168 
00169 
00170 #endif // ! MLN_WIN_RECTANGLE2D_HH

Generated on Tue Oct 4 2011 15:24:21 for Milena (Olena) by  doxygen 1.7.1