Milena (Olena)
User documentation 2.0a Id
|
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_OCTAGON2D_HH 00027 # define MLN_WIN_OCTAGON2D_HH 00028 00032 00033 # include <mln/core/internal/classical_window_base.hh> 00034 # include <mln/core/alias/dpoint2d.hh> 00035 00036 00037 namespace mln 00038 { 00039 00040 mln_internal_add_classical_window_trait(octagon2d); 00041 00042 00043 namespace win 00044 { 00045 00067 struct octagon2d : public internal::classical_window_base< dpoint2d, octagon2d > 00068 { 00075 octagon2d(unsigned length); 00076 00079 unsigned length() const; 00080 00084 unsigned delta_() const; 00085 00088 unsigned area() const; 00089 00090 void print_(std::ostream& ostr) const; 00091 00092 protected: 00093 unsigned length_; 00094 }; 00095 00096 00097 00098 # ifndef MLN_INCLUDE_ONLY 00099 00100 inline 00101 octagon2d::octagon2d(unsigned length) 00102 : length_(length) 00103 { 00104 mln_precondition(length % 6 == 1); 00105 const def::coord 00106 y = static_cast<def::coord>(length / 6), 00107 x = static_cast<def::coord>(y * 2), 00108 z = static_cast<def::coord>(y + x); 00109 insert(dpoint2d(0, 0)); 00110 for (def::coord a = 1; a <= x; ++a) 00111 for (def::coord b = 0; b <= x; ++b) 00112 { 00113 def::coord 00114 _a = static_cast<def::coord>(-a), 00115 _b = static_cast<def::coord>(-b); 00116 insert(dpoint2d(a, b)); 00117 insert(dpoint2d(_b, a)); 00118 insert(dpoint2d(b, _a)); 00119 insert(dpoint2d(_a, _b)); 00120 } 00121 const def::coord a_min = static_cast<def::coord>(x + 1); 00122 for (def::coord a = a_min; a <= z; ++a) 00123 { 00124 const def::coord 00125 b_min = static_cast<def::coord>(-2 * x + a), 00126 b_max = static_cast<def::coord>(2 * x - a); 00127 for (def::coord b = b_min; b <= b_max; ++b) 00128 { 00129 def::coord 00130 _a = static_cast<def::coord>(-a), 00131 _b = static_cast<def::coord>(-b); 00132 insert(dpoint2d(a, b)); 00133 insert(dpoint2d(a, _b)); 00134 insert(dpoint2d(_a, b)); 00135 insert(dpoint2d(_a, _b)); 00136 insert(dpoint2d(b, a)); 00137 insert(dpoint2d(b, _a)); 00138 insert(dpoint2d(_b, a)); 00139 insert(dpoint2d(_b, _a)); 00140 } 00141 } 00142 } 00143 00144 inline 00145 unsigned octagon2d::length() const 00146 { 00147 return length_; 00148 } 00149 00150 inline 00151 unsigned octagon2d::delta_() const 00152 { 00153 return length_ / 2; 00154 } 00155 00156 inline 00157 unsigned octagon2d::area() const 00158 { 00159 unsigned l = (length_ - 1) / 6; 00160 return l * (28 * l + 8) + 4; 00161 } 00162 00163 inline 00164 void octagon2d::print_(std::ostream& ostr) const 00165 { 00166 ostr << "[octagon2d: length=" << length_ << ']'; 00167 } 00168 00169 # endif // ! MLN_INCLUDE_ONLY 00170 00171 } // end of namespace mln::win 00172 00173 } // end of namespace mln 00174 00175 00176 00177 // When rectangle2d is involved, one surely also wants: 00178 # include <mln/win/hline2d.hh> 00179 # include <mln/win/vline2d.hh> 00180 # include <mln/win/diag2d.hh> 00181 # include <mln/win/backdiag2d.hh> 00182 00183 #endif // ! MLN_WIN_OCTAGON2D_HH