905: Add Box and comparison operators between point sets.

https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add Box and comparison operators between point sets. * oln/core/gen/pset_compare.hh: New. * oln/core/concept/point_set.hh (Box): New. * oln/core/2d/box2d.hh (include): Remove gen/box.hh. * oln/core/internal/point_set_base.hh (point_set_selector_): New. * oln/stc/scoop.hxx (super_trait_): Change dummy code. core/2d/box2d.hh | 12 --- core/concept/point_set.hh | 54 +++++++++++++ core/gen/pset_compare.hh | 159 ++++++++++++++++++++++++++++++++++++++++ core/internal/point_set_base.hh | 30 +++++++ stc/scoop.hxx | 12 ++- 5 files changed, 255 insertions(+), 12 deletions(-) Index: oln/core/concept/point_set.hh --- oln/core/concept/point_set.hh (revision 904) +++ oln/core/concept/point_set.hh (working copy) @@ -64,6 +64,24 @@ }; // end of oln::Point_Set<Exact> + /// Concept-class "Box". + + template <typename Exact> + struct Box : public Point_Set<Exact> + { + stc_using_from(Point_Set, point); + + const point& pmin() const; + point& pmin(); + const point& pmax() const; + point& pmax(); + + protected: + Box(); + + }; // end of oln::Box<Exact> + + template <typename Ps> std::ostream& operator<<(std::ostream& ostr, const Point_Set<Ps>& pts); @@ -96,6 +114,38 @@ { } + template <typename Exact> + Box<Exact>::Box() + { + } + + template <typename Exact> + const typename Box<Exact>::point& + Box<Exact>::pmin() const + { + return exact(this)->impl_pmin(); + } + + template <typename Exact> + typename Box<Exact>::point& + Box<Exact>::pmin() + { + return exact(this)->impl_pmin(); + } + + template <typename Exact> + const typename Box<Exact>::point& + Box<Exact>::pmax() const + { + return exact(this)->impl_pmax(); + } + + template <typename Exact> + typename Box<Exact>::point& + Box<Exact>::pmax() + { + return exact(this)->impl_pmax(); + } template <typename Ps> std::ostream& operator<<(std::ostream& ostr, const Point_Set<Ps>& pts) @@ -114,4 +164,8 @@ } // end of namespace oln +// FIXME: Bad? +# include <oln/core/gen/pset_compare.hh> + + #endif // ! OLN_CORE_CONCEPT_POINT_SET_HH Index: oln/core/2d/box2d.hh --- oln/core/2d/box2d.hh (revision 904) +++ oln/core/2d/box2d.hh (working copy) @@ -86,17 +86,9 @@ } // end of namespace oln::internal -} // end of namespace oln - - -# include <oln/core/gen/box.hh> - # ifndef OLN_INCLUDE_ONLY -namespace oln -{ - box2d::box2d() { } @@ -144,10 +136,10 @@ } // end of namespace oln::internal -} // end of namespace oln +# endif // ! OLN_INCLUDE_ONLY -# endif // OLN_INCLUDE_ONLY +} // end of namespace oln #endif // ! OLN_CORE_2D_BOX2D_HH Index: oln/core/gen/pset_compare.hh --- oln/core/gen/pset_compare.hh (revision 0) +++ oln/core/gen/pset_compare.hh (revision 0) @@ -0,0 +1,159 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_CORE_GEN_PSET_COMPARE_HH +# define OLN_CORE_GEN_PSET_COMPARE_HH + +# include <oln/core/concept/point_set.hh> + + +namespace oln +{ + + // Fwd decls. + + template <typename L, typename R> + bool operator = (const Point_Set<L>& lhs, const Point_Set<R>& rhs); + + template <typename L, typename R> + bool operator <= (const Point_Set<L>& lhs, const Point_Set<R>& rhs); + + + // FIXME: Guards; without impl! + template <typename L, typename R> bool operator < (const Point_Set<L>&, const Point_Set<R>&); + template <typename L, typename R> bool operator > (const Point_Set<L>&, const Point_Set<R>&); + template <typename L, typename R> bool operator >= (const Point_Set<L>&, const Point_Set<R>&); + // end of FIXME + + + +# ifndef OLN_INCLUDE_ONLY + + namespace impl + { + + // Point_Set L = Point_Set R + // ------------------------------ + + // Generic version. + + template <typename L, typename R> + bool op_eq_(const Point_Set<L>& lhs, const Point_Set<R>& rhs) + { + oln_piter(L) pl(lhs); + oln_piter(R) pr(rhs); + for (pl.start(), pr.start(); + pl.is_valid(); + pl.next(), pr.next()) + { + if (not pr.is_valid()) // while pl is valid + return false; + if (pl.to_point() != pr.to_point()) + return false; + } + if (pr.is_valid()) // while pl is not valid + return false; + return true; + } + + /* + // Version for Boxes. + + FIXME: Activate. + template <typename L, typename R> + bool op_eq_(const Box<L>& lhs, const Box<R>& rhs) + { + return lhs.pmin() = rhs.pmin() and lhs.pmax() = rhs.pmax(); + } + */ + + + // Point_Set L <= Point_Set R + // ------------------------------ + + // Generic version. + + template <typename L, typename R> + bool op_leq_(const Point_Set<L>& lhs, const Point_Set<R>& rhs) + { + // quick test: + if (lhs.npoints() > rhs.npoints()) + return false; + // final test: + oln_piter(R) pr(rhs); + pr.start(); + oln_piter(L) pl(lhs); + for_all(pl) + { + while (pr.is_valid() and pr.to_point() != pl.to_point()) + pr.next(); + if (not pr.is_valid()) + return false; + } + return true; + } + + /* + // Version for Boxes. + + FIXME: Activate. + template <typename L, typename R> + bool op_leq_(const Box<L>& lhs, const Box<R>& rhs) + { + for (unsigned i = 0; i < L::n; ++i) + if (lhs.pmin()[i] < rhs.pmin()[i] or lhs.pmax()[i] > rhs.pmax()[i]) + return false; + return true; + } + */ + + + } // end of namespace oln::impl + + + // Facades. + + template <typename L, typename R> + bool operator = (const Point_Set<L>& lhs, const Point_Set<R>& rhs) + { + mlc::assert_equal_< oln_grid(L), oln_grid(R) >::check(); // FIXME: Add err msg. + return impl::op_eq_(exact(lhs), exact(rhs)); + } + + template <typename L, typename R> + bool operator <= (const Point_Set<L>& lhs, const Point_Set<R>& rhs) + { + mlc::assert_equal_< oln_grid(L), oln_grid(R) >::check(); // FIXME: Add err msg. + return impl::op_leq_(exact(lhs), exact(rhs)); + } + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + + +#endif // ! OLN_CORE_GEN_PSET_COMPARE_HH Index: oln/core/internal/point_set_base.hh --- oln/core/internal/point_set_base.hh (revision 904) +++ oln/core/internal/point_set_base.hh (working copy) @@ -34,8 +34,28 @@ namespace oln { + + namespace internal + { + + template <bool Is_box, typename Exact> + struct point_set_selector_; + + template <typename Exact> + struct point_set_selector_< true, Exact > : public Box<Exact> + {}; + + template <typename Exact> + struct point_set_selector_< false, Exact > : public Point_Set<Exact> + {}; + + } // end of namespace oln::internal + + + // point_set_base_ class + /// Fwd decls. namespace internal { template <typename Exact> struct point_set_base_; } template <typename P> class gen_box; @@ -46,6 +66,14 @@ struct super_trait_< internal::point_set_base_<Exact> > { typedef Point_Set<Exact> ret; + + /* + FIXME: Activate to replace the above code. + + typedef stc_deferred(box) box__; + typedef mlc::eq_<box__, Exact> test__; + typedef internal::point_set_selector_<mlc_bool(test__), Exact> ret; + */ }; @@ -74,7 +102,7 @@ /// Base class for point sets. template <typename Exact> - struct point_set_base_ : public Point_Set<Exact> + struct point_set_base_ : public Point_Set<Exact> // FIXME: Change inheritance. { protected: point_set_base_(); Index: oln/stc/scoop.hxx --- oln/stc/scoop.hxx (revision 904) +++ oln/stc/scoop.hxx (working copy) @@ -88,7 +88,10 @@ /* super_trait_ */ template <typename from_type> -struct super_trait_; +struct super_trait_ +{ + typedef mlc::none ret; +}; template <typename from_type> @@ -96,6 +99,11 @@ { }; + +/* + + FIXME: Inactivate since dummy code (many class are not Abstractions but abstraction<Exact>). + template <template <class> class abstraction, typename Exact> struct super_trait_< abstraction<Exact> > { @@ -109,6 +117,8 @@ typedef mlc::none ret; }; +*/ +
participants (1)
-
Thierry Geraud