Commit 677bbd2d authored by Thierry Geraud's avatar Thierry Geraud
Browse files

2006-09-01 Thierry GERAUD <theo@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.



git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@513 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 70828a71
2006-09-01 Thierry GERAUD <theo@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.
2006-08-31 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr>
Add dpoint, oln traits, and operators on point/dpoint.
......
// 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
// 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
......@@ -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>
......@@ -38,28 +36,6 @@ namespace oln
{
/// \{
/// 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; };
......@@ -90,14 +66,23 @@ namespace oln
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)
{
}
......
// 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
......@@ -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 @@ namespace oln
};
// 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
{
......
......@@ -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
{
......
// 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
// 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> >
{