2006-09-01 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Add bboxes and iterators.
* oln/core/abstract/piter.hh: New.
* oln/core/abstract/bbox.hh: New.
* oln/core/abstract/iter.hh: New.
* oln/core/abstract/pset.hh: New.
* oln/core/2d/aliases.hh: New.
* oln/core/gen/fwd_piter.hh: New.
* oln/core/gen/bkd_piter.hh: New.
* oln/core/gen/bbox.hh: New.
* oln/core/2d/point2d.hh (point2d_): New ctor.
(point2d, dpoint2d, point2df, dpoint2df): Move typedefs to...
* oln/basics2d.hh: ...this new file.
* oln/core/typedefs.hh (oln_type_of_): New macro.
(include): Update.
(fwd_piter_type, bkd_piter_type): New decls.
* oln/core/abstract/point.hh (include): Update.
(vtypes_): New specialization.
* oln/core/abstract/dpoint.hh: Likewise.
* oln/core/abstract/point_nd.hh (include): Update.
(set_super_type): New specialization.
* oln/core/abstract/dpoint_nd.hh: Likewise.
Index: oln/core/typedefs.hh
===================================================================
--- oln/core/typedefs.hh (revision 512)
+++ oln/core/typedefs.hh (working copy)
@@ -32,10 +32,16 @@
# include <mlc/contract.hh>
# include <mlc/flags.hh>
+# include <mlc/is_a.hh>
# include <mlc/cmp.hh>
# include <mlc/typedef.hh>
+# include <mlc/value.hh>
+
+# include <stc/any.hh>
+# include <stc/exact.hh>
# include <stc/vtypes.hh>
+# include <oln/core/type.hh>
/*! \macro oln_type_of(OlnType, Alias)
@@ -47,8 +53,11 @@
# define oln_type_of(OlnType, Alias) \
stc_type_of(oln, void, OlnType, Alias)
+# define oln_type_of_(OlnType, Alias) \
+stc_type_of_(oln, void, OlnType, Alias)
+
namespace oln
{
@@ -87,8 +96,8 @@
// mlc_decl_typedef(bkd_iter_type);
// mlc_decl_typedef(piter_type);
-// mlc_decl_typedef(fwd_piter_type);
-// mlc_decl_typedef(bkd_piter_type);
+ mlc_decl_typedef(fwd_piter_type);
+ mlc_decl_typedef(bkd_piter_type);
// mlc_decl_typedef(qiter_type);
// mlc_decl_typedef(fwd_qiter_type);
Index: oln/core/abstract/piter.hh
===================================================================
--- oln/core/abstract/piter.hh (revision 0)
+++ oln/core/abstract/piter.hh (revision 0)
@@ -0,0 +1,100 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2006 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 OLENA_CORE_ABSTRACT_PITER_HH
+# define OLENA_CORE_ABSTRACT_PITER_HH
+
+# include <oln/core/abstract/iter.hh>
+# include <oln/core/abstract/point.hh>
+
+
+namespace oln
+{
+
+
+ // Forward declaration.
+ namespace abstract { template <typename E> class piter; }
+
+
+ // Super type declaration.
+ template <typename E>
+ struct set_super_type< abstract::piter<E> >
+ {
+ typedef abstract::iter<E> ret;
+ };
+
+
+ /// Virtual types associated to abstract::piter<E>.
+ template <typename E>
+ struct vtypes_< abstract::piter<E> >
+ {
+ typedef mlc::undefined point_type;
+ };
+
+
+ namespace abstract
+ {
+
+ /// Abstract point iterator class.
+ template <typename E>
+ class piter : public abstract::iter<E>
+ {
+ typedef oln_type_of(E, point) point_t;
+
+ public:
+
+ operator point_t() const
+ {
+ precondition(this->is_valid());
+ return p_;
+ }
+
+ protected:
+
+ point_t p_;
+
+ piter()
+ {
+ }
+
+ ~piter()
+ {
+ mlc::assert_defined_< point_t >::check();
+ mlc::assert_< mlc_is_a(point_t, abstract::point) >::check();
+ }
+
+ }; // end of class oln::abstract::piter<E>
+
+
+ } // end of namespace oln::abstract
+
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_ABSTRACT_PITER_HH
Index: oln/core/abstract/point.hh
===================================================================
--- oln/core/abstract/point.hh (revision 512)
+++ oln/core/abstract/point.hh (working copy)
@@ -29,25 +29,17 @@
#ifndef OLENA_CORE_ABSTRACT_POINT_HH
# define OLENA_CORE_ABSTRACT_POINT_HH
-# include <mlc/assert.hh>
-# include <mlc/cmp.hh>
-
-# include <stc/any.hh>
-# include <stc/vtypes.hh>
-# include <stc/exact.hh>
-
-# include <oln/core/type.hh>
# include <oln/core/typedefs.hh>
+# include <oln/core/traits_id.hh>
# include <oln/core/abstract/dpoint.hh>
-# include <oln/core/traits_id.hh>
+namespace oln
+{
-namespace oln {
-
namespace ERROR
{
struct OPERANDS_ARE_NOT_COMPATIBLE;
@@ -56,9 +48,24 @@
- namespace abstract {
+ // Forward declaration.
+ namespace abstract { template <typename E> class point; }
+ /// Virtual types associated to abstract::point<E>.
+ template <typename E>
+ struct vtypes_< abstract::point<E> >
+ {
+ typedef mlc::undefined grid_type;
+ typedef mlc::undefined dpoint_type;
+ typedef mlc::undefined coord_type;
+ typedef mlc::undefined dim_type;
+ };
+
+
+ namespace abstract
+ {
+
/// Abstract point class.
template <typename E>
class point : public stc::any__simple<E>,
@@ -295,18 +302,20 @@
point()
{}
- ~point() {
+ ~point()
+ {
mlc::assert_defined_< oln_type_of(E, grid) >::check();
mlc::assert_defined_< oln_type_of(E, dpoint) >::check();
mlc::assert_defined_< oln_type_of(E, coord) >::check();
mlc::assert_defined_< oln_type_of(E, dim) >::check();
}
- };
+ }; // end of class oln::abstract::point<E>
+
+
} // end of namespace oln::abstract
-
} // end of namespace oln
Index: oln/core/abstract/bbox.hh
===================================================================
--- oln/core/abstract/bbox.hh (revision 0)
+++ oln/core/abstract/bbox.hh (revision 0)
@@ -0,0 +1,227 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2006 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 OLENA_CORE_ABSTRACT_BBOX_HH
+# define OLENA_CORE_ABSTRACT_BBOX_HH
+
+# include <mlc/value.hh>
+# include <oln/core/type.hh>
+# include <oln/core/typedefs.hh>
+# include <oln/core/abstract/pset.hh>
+
+
+namespace oln
+{
+
+ // Forward declaration.
+ namespace abstract { template <typename E> class bbox; }
+
+
+ // Super type declaration.
+ template <typename E>
+ struct set_super_type< abstract::bbox<E> >
+ {
+ typedef abstract::pset<E> ret;
+ };
+
+
+ namespace abstract
+ {
+
+ /// Abstract bbox (bounding box) class.
+ template <typename E>
+ class bbox : public abstract::pset<E>
+ {
+ typedef E exact_t;
+ typedef oln_type_of(E, point) point_t;
+
+ typedef oln_type_of(point_t, dim) dim;
+ enum { n = mlc_value(dim) };
+
+ public:
+
+ unsigned npoints() const
+ {
+ unsigned count = 1;
+ for (unsigned i = 0; i < n; ++i)
+ count *= size(i);
+ return count;
+ }
+
+ const point_t& pmin() const
+ {
+ precondition(is_valid_);
+ return pmin_;
+ }
+
+ const point_t& pmax() const
+ {
+ precondition(is_valid_);
+ return pmax_;
+ }
+
+ unsigned size(unsigned i) const
+ {
+ precondition(is_valid_ and i < n);
+ return pmax_[i] - pmin_[i] + 1;
+ }
+
+ void flush()
+ {
+ is_valid_ = false;
+ }
+
+ void init_with(const point_t& p)
+ {
+ precondition(not is_valid_);
+ pmin_ = p;
+ pmax_ = p;
+ is_valid_ = true;
+ }
+
+ void update_with(const point_t& p)
+ {
+ precondition(is_valid_);
+ for (unsigned i = 0; i < n; ++i)
+ if (p[i] < pmin_[i])
+ pmin_[i] = p[i];
+ else if (p[i] > pmax_[i])
+ pmax_[i] = p[i];
+ }
+
+ void take(const point_t& p)
+ {
+ if (not is_valid_)
+ {
+ init_with(p);
+ return;
+ }
+ for (unsigned i = 0; i < n; ++i)
+ if (p[i] < pmin_[i])
+ pmin_[i] = p[i];
+ else if (p[i] > pmax_[i])
+ pmax_[i] = p[i];
+ }
+
+ // FIXME: Add "update : (rhs : exact)"
+
+ bool has(const point_t& p) const
+ {
+ precondition(is_valid_);
+ for (unsigned i = 0; i < n; ++i)
+ if (p[i] < pmin_[i] or p[i] > pmax_[i])
+ return false;
+ return true;
+ }
+
+ bool includes(const exact_t& rhs) const
+ {
+ precondition(is_valid_ and rhs.is_valid());
+ for (unsigned i = 0; i < n; ++i)
+ if (rhs.pmin()[i] < pmin_[i] or rhs.pmax()[i] > pmax_[i])
+ return false;
+ return true;
+ }
+
+ // FIXME: Add the scool code below.
+
+// invariant {
+// n > 1
+// is_valid => (pmax >= pmin) // FIXME: More.
+// }
+
+// (=) const : (rhs : exact) -> bool =
+// {
+// precondition(@is_valid and rhs.is_valid)
+// return @pmin = rhs.pmin and @pmax = rhs.pmax
+// }
+
+// (+=) : (dp : dpoint const ref) -> exact =
+// {
+// precondition(is_valid)
+// pmin += dp
+// pmax += dp
+// }
+
+// (-=) : (dp : dpoint const ref) -> exact =
+// {
+// precondition(is_valid)
+// pmin -= dp
+// pmax -= dp
+// }
+
+ protected:
+
+ point_t pmin_;
+ point_t pmax_;
+ bool is_valid_;
+
+ bbox()
+ {
+ flush();
+ }
+
+ bbox(const point_t& pmin, const point_t& pmax)
+ : pmin_(pmin),
+ pmax_(pmax)
+ {
+ for (unsigned i = 0; i < n; ++i)
+ precondition(pmax[i] >= pmin[i]);
+ is_valid_ = true;
+ }
+
+ ~bbox()
+ {
+ flush();
+
+ mlc::assert_defined_< point_t >::check();
+
+ typedef oln_type_of(E, fwd_piter) fwd_piter_t;
+ typedef oln_type_of(E, bkd_piter) bkd_piter_t;
+
+ mlc::assert_defined_< fwd_piter_t >::check();
+ mlc::assert_defined_< bkd_piter_t >::check();
+
+ mlc::assert_< mlc::eq_< oln_type_of(fwd_piter_t, grid),
+ oln_type_of(point_t, grid) > >::check();
+
+ mlc::assert_< mlc::eq_< oln_type_of(bkd_piter_t, grid),
+ oln_type_of(point_t, grid) > >::check();
+
+ }
+
+ }; // end of class oln::abstract::bbox<E>
+
+
+ } // end of namespace oln::abstract
+
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_ABSTRACT_BBOX_HH
Index: oln/core/abstract/dpoint.hh
===================================================================
--- oln/core/abstract/dpoint.hh (revision 512)
+++ oln/core/abstract/dpoint.hh (working copy)
@@ -29,13 +29,6 @@
#ifndef OLENA_CORE_ABSTRACT_DPOINT_HH
# define OLENA_CORE_ABSTRACT_DPOINT_HH
-# include <mlc/assert.hh>
-# include <mlc/cmp.hh>
-
-# include <stc/any.hh>
-# include <stc/vtypes.hh>
-
-# include <oln/core/type.hh>
# include <oln/core/typedefs.hh>
@@ -53,6 +46,22 @@
};
+ // Forward declaration.
+ namespace abstract { template <typename E> class dpoint; }
+
+
+ /// Virtual types associated to abstract::dpoint<E>.
+ template <typename E>
+ struct vtypes_< abstract::dpoint<E> >
+ {
+ typedef mlc::undefined grid_type;
+ typedef mlc::undefined point_type;
+ typedef mlc::undefined coord_type;
+ typedef mlc::undefined dim_type;
+ };
+
+
+
namespace abstract
{
Index: oln/core/abstract/iter.hh
===================================================================
--- oln/core/abstract/iter.hh (revision 0)
+++ oln/core/abstract/iter.hh (revision 0)
@@ -0,0 +1,89 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2006 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 OLENA_CORE_ABSTRACT_ITER_HH
+# define OLENA_CORE_ABSTRACT_ITER_HH
+
+# include <oln/core/typedefs.hh>
+
+
+namespace oln
+{
+
+
+ namespace abstract
+ {
+
+ /// Abstract iterator class.
+ template <typename E>
+ class iter : public stc::any__simple<E>,
+ public oln::type
+ {
+ public:
+
+ void start()
+ {
+ this->exact().impl_start();
+ }
+
+ void next()
+ {
+ precondition(this->is_valid());
+ this->exact().impl_next();
+ }
+
+ void invalidate()
+ {
+ this->exact().impl_invalidate();
+ }
+
+ bool is_valid() const
+ {
+ return this->exact().impl_is_valid();
+ }
+
+ protected:
+
+ iter()
+ {
+ this->invalidate();
+ }
+
+ }; // end of class oln::abstract::iter<E>
+
+
+ } // end of namespace oln::abstract
+
+
+} // end of namespace oln
+
+
+#define for_all(i) for (i.start(); i.is_valid(); i.next())
+
+
+#endif // ! OLENA_CORE_ABSTRACT_ITER_HH
Index: oln/core/abstract/point_nd.hh
===================================================================
--- oln/core/abstract/point_nd.hh (revision 512)
+++ oln/core/abstract/point_nd.hh (working copy)
@@ -29,12 +29,10 @@
#ifndef OLENA_CORE_ABSTRACT_POINT_ND_HH
# define OLENA_CORE_ABSTRACT_POINT_ND_HH
-# include <mlc/value.hh>
-
# include <xtd/vec.hh>
# include <xtd/optraits.hh>
+# include <oln/core/traits_id.hh>
-# include <oln/core/traits_id.hh>
# include <oln/core/abstract/point.hh>
# include <oln/core/abstract/dpoint_nd.hh>
@@ -43,7 +41,6 @@
{
-
/// Function "point_ : (n, coord) -> point type".
template <unsigned n, typename C>
struct point_
@@ -53,6 +50,19 @@
+ // Forward declaration.
+ namespace abstract { template <typename E> class point_nd; }
+
+
+
+ // Super type declaration.
+ template <typename E>
+ struct set_super_type< abstract::point_nd<E> >
+ {
+ typedef abstract::point<E> ret;
+ };
+
+
namespace abstract
{
@@ -136,7 +146,8 @@
v_(v)
{}
- xtd::vec<n,coord_t> v_;
+ typedef xtd::vec<n,coord_t> vec_t;
+ vec_t v_;
};
} // end of namespace oln::abstract
Index: oln/core/abstract/pset.hh
===================================================================
--- oln/core/abstract/pset.hh (revision 0)
+++ oln/core/abstract/pset.hh (revision 0)
@@ -0,0 +1,95 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2006 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 OLENA_CORE_ABSTRACT_PSET_HH
+# define OLENA_CORE_ABSTRACT_PSET_HH
+
+# include <stc/any.hh>
+# include <oln/core/type.hh>
+# include <oln/core/typedefs.hh>
+
+
+namespace oln
+{
+
+ /// Forward declaration.
+ namespace abstract { template <typename E> class pset; }
+
+
+
+ /// Virtual types associated to oln::bbox_nd<point>.
+ template <typename E>
+ struct vtypes_< abstract::pset<E> >
+ {
+ typedef mlc::undefined point_type;
+ typedef mlc::undefined fwd_piter_type;
+ typedef mlc::undefined bkd_piter_type;
+ // FIXME: Add grid.
+ };
+
+
+ namespace abstract
+ {
+
+ /// Abstract point class.
+ template <typename E>
+ class pset : public stc::any__simple<E>,
+ public oln::type
+ {
+
+ protected:
+
+ pset()
+ {}
+
+ ~pset()
+ {
+ mlc::assert_defined_< oln_type_of(E, point) >::check();
+
+ // FIXME: Trouble with circular dependencies.
+
+// mlc::assert_defined_< fwd_piter_t >::check();
+// mlc::assert_defined_< bkd_piter_t >::check();
+
+// mlc::assert_< mlc::eq_< oln_type_of(fwd_piter_t, grid),
+// oln_type_of(point_t, grid) > >::check();
+
+// mlc::assert_< mlc::eq_< oln_type_of(bkd_piter_t, grid),
+// oln_type_of(point_t, grid) > >::check();
+ }
+
+ }; // end of class oln::abstract::pset<E>
+
+
+ } // end of namespace oln::abstract
+
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_ABSTRACT_PSET_HH
Index: oln/core/abstract/dpoint_nd.hh
===================================================================
--- oln/core/abstract/dpoint_nd.hh (revision 512)
+++ oln/core/abstract/dpoint_nd.hh (working copy)
@@ -37,6 +37,18 @@
namespace oln
{
+ // Forward declaration.
+ namespace abstract { template <typename E> class dpoint_nd; }
+
+
+ // Super type declaration.
+ template <typename E>
+ struct set_super_type< abstract::dpoint_nd<E> >
+ {
+ typedef abstract::dpoint<E> ret;
+ };
+
+
namespace abstract
{
Index: oln/core/2d/aliases.hh
===================================================================
--- oln/core/2d/aliases.hh (revision 0)
+++ oln/core/2d/aliases.hh (revision 0)
@@ -0,0 +1,64 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2006 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 OLENA_CORE_2D_ALIASES_HH
+# define OLENA_CORE_2D_ALIASES_HH
+
+
+namespace oln
+{
+
+ /// \{
+ /// Forward declarations.
+ template <typename C> class point2d_;
+ template <typename C> class dpoint2d_;
+ template <typename P> class bbox_;
+ template <typename P> class fwd_piter_;
+ template <typename P> class bkd_piter_;
+ class grid2d;
+ /// \}
+
+
+ /// \{
+ /// Alliases.
+ typedef point2d_<int> point2d;
+ typedef dpoint2d_<int> dpoint2d;
+
+ typedef bbox_<point2d> bbox2d;
+ typedef fwd_piter_<point2d> fwd_piter2d;
+ typedef bkd_piter_<point2d> bkd_piter2d;
+
+ typedef point2d_<float> point2df;
+ typedef dpoint2d_<float> dpoint2df;
+ /// \}
+
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_2D_ALIASES_HH
Index: oln/core/2d/point2d.hh
===================================================================
--- oln/core/2d/point2d.hh (revision 512)
+++ oln/core/2d/point2d.hh (working copy)
@@ -28,8 +28,6 @@
#ifndef OLENA_CORE_2D_POINT2D_HH
# define OLENA_CORE_2D_POINT2D_HH
-# include <string>
-
# include <mlc/int.hh>
# include <oln/core/abstract/point_nd.hh>
@@ -39,28 +37,6 @@
/// \{
- /// Forward declarations.
- template <typename C> class point2d_;
- template <typename C> class dpoint2d_;
- class grid2d;
- /// \}
-
-
- /// \{
- /// Classical 2D point classes.
- typedef point2d_<int> point2d;
- typedef point2d_<float> point2df;
- /// \}
-
-
- /// \{
- /// Classical 2D point classes.
- typedef dpoint2d_<int> dpoint2d;
- typedef dpoint2d_<float> dpoint2df;
- /// \}
-
-
- /// \{
/// Specializations of functions point and dpoint : (n,coord) -> type for n = 2.
template <typename C> struct point_ <2, C> { typedef point2d_<C>
ret; };
template <typename C> struct dpoint_ <2, C> { typedef dpoint2d_<C>
ret; };
@@ -90,17 +66,26 @@
public:
+ // Cf. BUG! typedef oln_type_of(self_t, grid) grid_t;
+
/// Ctor.
point2d_()
{
}
/// Ctor.
- point2d_(const xtd::vec<2,coord_t>& v) :
- super_t(v)
+ point2d_(coord_t row, coord_t col)
{
+ v_[0] = row;
+ v_[1] = col;
}
+ /// Ctor.
+ point2d_(const xtd::vec<2,coord_t>& v)
+ : super_t(v)
+ {
+ }
+
coord_t row() const { return v_[0]; }
coord_t& row() { return v_[0]; }
Index: oln/core/gen/fwd_piter.hh
===================================================================
--- oln/core/gen/fwd_piter.hh (revision 0)
+++ oln/core/gen/fwd_piter.hh (revision 0)
@@ -0,0 +1,134 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2006 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 OLENA_CORE_GEN_FWD_PITER_HH
+# define OLENA_CORE_GEN_FWD_PITER_HH
+
+# include <oln/core/abstract/piter.hh>
+# include <oln/core/abstract/point.hh>
+# include <oln/core/gen/bbox.hh>
+
+
+namespace oln
+{
+
+
+ // Forward declaration.
+ template <typename point> class fwd_piter_;
+
+
+ // Super type declaration.
+ template <typename point>
+ struct set_super_type< fwd_piter_<point> >
+ {
+ typedef fwd_piter_<point> self_t;
+ typedef abstract::piter<self_t> ret;
+ };
+
+
+ /// Virtual types associated to oln::fwd_piter_<point>.
+ template <typename point>
+ struct vtypes_< fwd_piter_<point> >
+ {
+ typedef point point_type;
+ typedef oln_type_of(point, grid) grid_type;
+ };
+
+
+
+ /// Abstract forward point iterator class.
+ template <typename point>
+ class fwd_piter_ : public abstract::piter< fwd_piter_<point> >,
+ private mlc::assert_< mlc_is_a(point, abstract::point) >
+ {
+ typedef fwd_piter_<point> self_t;
+ typedef abstract::piter<self_t> super_t;
+
+ using super_t::p_;
+
+ public:
+
+ fwd_piter_(const bbox_<point>& bb)
+ : bb_(bb)
+ {
+ nop_ = bb_.pmax();
+ ++nop_[0];
+
+ psup_ = bb_.pmax().vec();
+ for (unsigned i = 0; i < point::n; ++i)
+ ++psup_[i];
+ }
+
+ void impl_start()
+ {
+ p_ = bb_.pmin();
+ invariant(p_ <= nop_);
+ }
+
+ void impl_next()
+ {
+ invariant(p_ <= nop_);
+ ++p_[0];
+ unsigned i = 0;
+ while (i + 1 < point::n)
+ {
+ if (p_[i] == psup_[i])
+ {
+ p_[i] = bb_.pmin_[i];
+ ++p_[i+1];
+ }
+ ++i;
+ }
+ invariant(p_ <= nop_);
+ }
+
+ void impl_invalidate()
+ {
+ invariant(p_ <= nop_);
+ p_ = nop_;
+ }
+
+ bool impl_is_valid() const
+ {
+ invariant(p_ <= nop_);
+ return p_ != nop_;
+ }
+
+ protected:
+
+ bbox_<point> bb_;
+ point nop_;
+ point psup_;
+
+ }; // end of class oln::fwd_piter_<point>
+
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_GEN_FWD_PITER_HH
Index: oln/core/gen/bkd_piter.hh
===================================================================
--- oln/core/gen/bkd_piter.hh (revision 0)
+++ oln/core/gen/bkd_piter.hh (revision 0)
@@ -0,0 +1,143 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2006 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 OLENA_CORE_GEN_BKD_PITER_HH
+# define OLENA_CORE_GEN_BKD_PITER_HH
+
+# include <oln/core/abstract/piter.hh>
+# include <oln/core/abstract/point.hh>
+# include <oln/core/gen/bbox.hh>
+
+
+namespace oln
+{
+
+
+ // Forward declaration.
+ template <typename point> class bkd_piter_;
+
+
+ // Super type declaration.
+ template <typename point>
+ struct set_super_type< bkd_piter_<point> >
+ {
+ typedef bkd_piter_<point> self_t;
+ typedef abstract::piter<self_t> ret;
+ };
+
+
+ /// Virtual types associated to oln::bbox_<point>.
+ template <typename point>
+ struct vtypes_< bkd_piter_<point> >
+ {
+ typedef point point_type;
+ typedef oln_type_of(point, grid) grid_type;
+ };
+
+
+
+ /// Abstract forward point iterator class.
+ template <typename point>
+ class bkd_piter_ : public abstract::piter< bkd_piter_<point> >,
+ private mlc::assert_< mlc_is_a(point, abstract::point) >
+ {
+ typedef bkd_piter_<point> self_t;
+ typedef abstract::piter<self_t> super_t;
+
+ using super_t::p_;
+
+ public:
+
+ bkd_piter_(const bbox_<point>& bb)
+ : bb_(bb)
+ {
+ nop_ = bb_.pmax();
+ ++nop_[0];
+
+ psup_ = bb_.pmax().vec();
+ for (unsigned i = 0; i < point::n; ++i)
+ ++psup_[i];
+ }
+
+ void impl_start()
+ {
+ p_ = bb_.pmin();
+ }
+
+ void impl_next()
+ {
+ assert(this->is_valid());
+ ++p_[0];
+ unsigned i = 0;
+ while (i + 1 < point::n)
+ {
+ if (p_[i] == psup_[i])
+ {
+ p_[i] = bb_.pmin_[i];
+ ++p_[i+1];
+ }
+ ++i;
+ }
+ }
+
+// def next =
+// {
+// precondition { is_valid }
+// }
+
+ void impl_invalidate()
+ {
+ assert(this->is_valid());
+ p_ = nop_;
+ }
+
+ bool impl_is_valid() const
+ {
+ return p_ != nop_;
+ }
+
+ protected:
+
+ bbox_<point> bb_;
+ point nop_;
+ point psup_;
+
+// invariant
+// {
+// p <= nop
+// }
+
+// make : [D : type] (data : D) = { @bb = data.bbox }
+
+ }; // end of class oln::bkd_piter_<point>
+
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_GEN_BKD_PITER_HH
Index: oln/core/gen/bbox.hh
===================================================================
--- oln/core/gen/bbox.hh (revision 0)
+++ oln/core/gen/bbox.hh (revision 0)
@@ -0,0 +1,92 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2006 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 OLENA_CORE_GEN_BBOX_HH
+# define OLENA_CORE_GEN_BBOX_HH
+
+# include <oln/core/abstract/bbox.hh>
+# include <oln/core/abstract/point.hh>
+
+
+namespace oln
+{
+
+ // Forward declarations.
+ template <typename point> class bbox_;
+ template <typename point> class fwd_piter_;
+ template <typename point> class bkd_piter_;
+
+
+ // Super type declaration.
+ template <typename point>
+ struct set_super_type< bbox_<point> >
+ {
+ typedef bbox_<point> self_t;
+ typedef abstract::bbox<self_t> ret;
+ };
+
+
+ /// Virtual types associated to oln::bbox_<point>.
+ template <typename point>
+ struct vtypes_< bbox_<point> >
+ {
+ typedef point point_type;
+ typedef fwd_piter_<point> fwd_piter_type;
+ typedef bkd_piter_<point> bkd_piter_type;
+ // BUG! typedef oln_type_of(point, grid) grid_type;
+ // BUG! typedef typename point::grid_t grid_type;
+ };
+
+
+ /// Bounding box class based on a point class.
+ template <typename point>
+ class bbox_ : public abstract::bbox< bbox_<point> >,
+ private mlc::assert_< mlc_is_a(point, abstract::point) >
+ {
+ typedef point point_t;
+ typedef bbox_<point> self_t;
+ typedef abstract::bbox<self_t> super_t;
+
+ public:
+
+ bbox_()
+ {
+ }
+
+ bbox_(const point_t& pmin, const point_t& pmax)
+ : super_t(pmin, pmax)
+ {
+ }
+
+ }; // end of class oln::bbox_<point>
+
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_GEN_BBOX_HH
Index: oln/basics2d.hh
===================================================================
--- oln/basics2d.hh (revision 0)
+++ oln/basics2d.hh (revision 0)
@@ -0,0 +1,42 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2006 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 OLENA_BASICS2D_HH
+# define OLENA_BASICS2D_HH
+
+
+# include <oln/core/2d/aliases.hh>
+
+# include <oln/core/2d/point2d.hh>
+# include <oln/core/2d/dpoint2d.hh>
+
+# include <oln/core/gen/bbox.hh>
+# include <oln/core/gen/fwd_piter.hh>
+# include <oln/core/gen/bkd_piter.hh>
+
+
+#endif // ! OLENA_BASICS2D_HH