26 #ifndef MLN_CORE_SITE_SET_P_LINE2D_HH
27 # define MLN_CORE_SITE_SET_P_LINE2D_HH
34 # include <mln/core/site_set/p_array.hh>
35 # include <mln/core/alias/box2d.hh>
37 # include <mln/math/sign.hh>
38 # include <mln/math/abs.hh>
39 # include <mln/math/min.hh>
40 # include <mln/math/max.hh>
55 struct site_set_< p_line2d >
57 typedef trait::site_set::nsites::known
nsites;
58 typedef trait::site_set::bbox::straight bbox;
59 typedef trait::site_set::contents::fixed contents;
60 typedef trait::site_set::arity::unique arity;
64 struct set_precise_unary_< op::ord, p_line2d >
66 typedef set_precise_unary_< op::ord, p_line2d > ret;
67 bool strict(
const p_line2d& lhs,
const p_line2d& rhs)
const;
79 class p_line2d :
public internal::site_set_base_< point2d, p_line2d >
105 bool is_end_excluded =
false);
112 bool has(
const util::index& i)
const;
142 const std::vector<point2d>&
std_vector()
const;
145 algebra::vec<2, float> to_vec()
const;
153 bool is_end_excluded);
158 # ifndef MLN_INCLUDE_ONLY
168 bool is_end_excluded)
171 mln_precondition(end != beg);
172 compute_(beg, end, is_end_excluded);
179 bool is_end_excluded)
182 mln_precondition(end != beg);
187 srow = math::sign(dp.row()), drow =
math::abs(dp.row()), ddrow = 2 * drow,
188 scol = math::sign(dp.col()), dcol =
math::abs(dp.col()), ddcol = 2 * dcol,
193 int e = ddrow - dcol;
194 for (
int i = 0; i < dcol; ++i)
196 arr_.append(
point2d(static_cast<def::coord>(row),
197 static_cast<def::coord>(col)));
209 int e = ddcol - drow;
210 for (
int i = 0; i < drow; ++i)
212 arr_.append(
point2d(static_cast<def::coord>(row),
213 static_cast<def::coord>(col)));
223 if (! is_end_excluded)
224 arr_.append(
point2d(static_cast<def::coord>(row),
225 static_cast<def::coord>(col)));
228 point2d end_ = arr_[arr_.nsites() - 1];
229 bb_.pmin() =
point2d(math::min(beg.row(), end_.row()),
230 math::min(beg.col(), end_.col()));
231 bb_.pmax() =
point2d(math::max(beg.row(), end_.row()),
232 math::max(beg.col(), end_.col()));
234 mln_postcondition(this->
begin() == beg);
235 mln_postcondition(is_end_excluded == (this->
end() != end));
242 mln_precondition(p.target_() ==
this);
243 if (!
has(p.index()))
245 mln_invariant(p.to_site() == (*this)[p.index()]);
253 return i >= 0 && unsigned(i) <
nsites();
260 mln_invariant(
implies(bb_.is_valid(), ! arr_.is_empty()));
261 return bb_.is_valid();
268 return arr_.nsites();
280 const std::vector<point2d>&
283 return arr_.std_vector();
288 algebra::vec<2, float>
289 p_line2d::to_vec()
const
291 algebra::vec<2, float> res;
292 res[0] = float(
end().row() -
begin().row());
293 res[1] = float(
end().col() -
begin().col());
301 mln_precondition(i <
nsites());
318 return arr_[
nsites() - 1];
325 return arr_.memory_size() +
sizeof(
box2d);
334 set_precise_unary_< op::ord, p_line2d >::strict(
const p_line2d& lhs,
337 return util::ord_lexi_strict(lhs.
begin(), lhs.
end(),
343 # endif // ! MLN_INCLUDE_ONLY
348 #endif // ! MLN_CORE_SITE_SET_P_LINE2D_HH