/* BoundingBox class declaration. Copyright (C) 2001-2004 Roberto Bagnara This file is part of the Parma Polyhedra Library (PPL). The PPL is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The PPL 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 program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. For the most up-to-date information see the Parma Polyhedra Library site: http://www.cs.unipr.it/ppl/ . */ #ifndef PPL_BoundingBox_defs_hh #define PPL_BoundingBox_defs_hh 1 #include "Integer.types.hh" #include "globals.hh" #include "Interval.defs.hh" #include #include namespace Parma_Polyhedra_Library { #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS //! A not necessarily closed bounding-box. /*! A BoundingBox object represents the Cartesian product of \f$n\f$ not necessarily closed and possibly unbounded intervals, where \f$n\f$ is the space-dimension of the box. */ #endif // PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS class BoundingBox { public: //! Constructs a universe bounding box of dimension \p num_dimensions. BoundingBox(dimension_type num_dimensions); //! Returns the dimension of the vector space enclosing \p *this. dimension_type space_dimension() const; //! \brief //! Returns a reference the interval that bounds //! the box on the k-th dimension. const Interval& operator[](dimension_type k) const; //! Returns true if and only if \p *this is empty. bool is_empty() const; //! \brief //! If the k-th dimension is unbounded below, //! returns false. //! Otherwise returns true and set \p closed, //! \p n and \p d accordingly. /*! Let \f$I\f$ the interval corresponding to the k-th dimension. If \f$I\f$ is not bounded from below, simply return false. Otherwise, set closed, n and d as follows: closed is set to true if the the lower boundary of \f$I\f$ is closed and is set to false otherwise; n and d are assigned the integers \f$n\f$ and \f$d\f$ such that the canonical fraction \f$n/d\f$ corresponds to the greatest lower bound of \f$I\f$. The fraction \f$n/d\f$ is in canonical form if and only if \f$n\f$ and \f$d\f$ have no common factors and \f$d\f$ is positive, \f$0/1\f$ being the unique representation for zero. An undefined behavior is obtained if \p k is greater than or equal to the space dimension of \p *this. */ bool get_lower_bound(dimension_type k, bool& closed, Integer& n, Integer& d) const; //! \brief //! If the k-th dimension is unbounded above, //! returns false. //! Otherwise returns true and set \p closed, //! \p n and \p d accordingly. /*! Let \f$I\f$ the interval corresponding to the k-th dimension. If \f$I\f$ is not bounded from above, simply return false. Otherwise, set closed, n and d as follows: closed is set to true if the the upper boundary of \f$I\f$ is closed and is set to false otherwise; n and d are assigned the integers \f$n\f$ and \f$d\f$ such that the canonical fraction \f$n/d\f$ corresponds to the least upper bound of \f$I\f$. An undefined behavior is obtained if \p k is greater than or equal to the space dimension of \p *this. */ bool get_upper_bound(dimension_type k, bool& closed, Integer& n, Integer& d) const; //! Causes the box to become empty, i.e., to represent the empty set. void set_empty(); //! \brief //! Raises the lower bound of the interval corresponding //! to the k-th dimension. /*! Intersects the interval corresponding to the k-th dimension with \f$[n/d, +\infty)\f$ if closed is true, with \f$(n/d, +\infty)\f$ if closed is false. An undefined behavior is obtained if \p k is greater than or equal to the space dimension of \p *this or if \p d is equal to zero. */ void raise_lower_bound(dimension_type k, bool closed, const Integer& n, const Integer& d); //! \brief //! Lowers the upper bound of the interval corresponding //! to the k-th dimension. /*! Intersects the interval corresponding to the k-th dimension with \f$(-\infty, n/d]\f$ if closed is true, with \f$(-\infty, n/d)\f$ if closed is false. An undefined behavior is obtained if \p k is greater than or equal to the space dimension of \p *this or if \p d is equal to zero. */ void lower_upper_bound(dimension_type k, bool closed, const Integer& n, const Integer& d); private: //! \brief //! A vector of rational intervals, one for each dimension //! of the vector space. std::vector vec; //! \brief //! A boolean flag indicating emptyness of the bounding box. //! Only meaningful when \p empty_up_to_date is true. mutable bool empty; //! Tells whether or not the flag \p empty is meaningful. mutable bool empty_up_to_date; }; namespace IO_Operators { #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS //! Output operator. /*! \relates Parma_Polyhedra_Library::BoundingBox */ #endif // PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS std::ostream& operator<<(std::ostream& s, const BoundingBox& bbox); } // namespace IO_Operators } // namespace Parma_Polyhedra_Library #include "BoundingBox.inlines.hh" #endif // !defined(PPL_BoundingBox_defs_hh)