$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
point2d.hh
1 // Copyright (C) 2007, 2008, 2009, 2012, 2013 EPITA Research and
2 // Development Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_CORE_ALIAS_POINT2D_HH
28 # define MLN_CORE_ALIAS_POINT2D_HH
29 
34 
35 # include <mln/core/def/coord.hh>
36 # include <mln/core/def/coordf.hh>
37 # include <mln/core/point.hh>
38 // For site_const_impl and site_mutable_impl.
39 # include <mln/core/concept/site_proxy.hh>
40 # include <mln/core/internal/force_exact.hh>
41 
42 
43 namespace mln
44 {
45 
53 
54  typedef point<mln::grid::square, mln::def::coord> point2d;
56 
57 
65 
66  typedef point<mln::grid::square, mln::def::coordf> point2df;
68 
69 
70  namespace internal
71  {
72 
73  // Specialization.
74 
76  template <typename C, typename E>
77  struct subject_impl< const point<grid::square, C>, E >
78  {
79  typedef C coord;
80  enum { dim = 2 };
81 
82  typedef const C& row_t;
83  const C& row() const;
84 
85  typedef const C& col_t;
86  const C& col() const;
87 
88  const C& operator[](unsigned i) const;
89  const C& last_coord() const;
90  private:
91  const E& exact_() const;
92  };
93 
94 
95  // Specialization for point<M,C>.
96 
98  template <typename C, typename E>
99  struct subject_impl< point<grid::square, C>, E > :
100  subject_impl< const point<grid::square, C>, E >
101  {
102  private:
103  typedef subject_impl< const point<grid::square, C>, E > super_;
104  E& exact_();
105  public:
106  using super_::row;
107  C& row();
108  using super_::col;
109  C& col();
110  using super_::operator[];
111  C& operator[](unsigned i);
112  };
113 
114 
115 # ifndef MLN_INCLUDE_ONLY
116 
117  // subject_impl
118 
119  template <typename C, typename E>
120  inline
121  const C&
123  {
124  return exact_().get_subject().row();
125  }
126 
127  template <typename C, typename E>
128  inline
129  const C&
131  {
132  return exact_().get_subject().col();
133  }
134 
135  template <typename C, typename E>
136  inline
137  const C&
138  subject_impl< const point<grid::square, C>, E >::operator[](unsigned i) const
139  {
140  mln_precondition(i < 2);
141  return exact_().get_subject()[i];
142  }
143 
144  template <typename C, typename E>
145  inline
146  const C&
147  subject_impl< const point<grid::square, C>, E >::last_coord() const
148  {
149  return this->col();
150  }
151 
152  template <typename C, typename E>
153  inline
154  const E&
155  subject_impl< const point<grid::square, C>, E >::exact_() const
156  {
157  return internal::force_exact<const E>(*this);
158  }
159 
160  // subject_impl
161 
162  template <typename C, typename E>
163  inline
164  C&
166  {
167  return exact_().get_subject().row();
168  }
169 
170  template <typename C, typename E>
171  inline
172  C&
174  {
175  return exact_().get_subject().col();
176  }
177 
178  template <typename C, typename E>
179  inline
180  C&
181  subject_impl< point<grid::square, C>, E >::operator[](unsigned i)
182  {
183  mln_precondition(i < 2);
184  return exact_().get_subject()[i];
185  }
186 
187  template <typename C, typename E>
188  inline
189  E&
191  {
192  return internal::force_exact<E>(*this);
193  }
194 
195 # endif // ! MLN_INCLUDE_ONLY
196 
197  } // end of namespace mln::internal
198 
199 
200 } // end of namespace mln
201 
202 
203 # include <mln/core/alias/dpoint2d.hh>
204 
205 
206 #endif // ! MLN_CORE_ALIAS_POINT2D_HH