00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef PPL_Bounding_Box_inlines_hh
00024 #define PPL_Bounding_Box_inlines_hh 1
00025
00026 namespace Parma_Polyhedra_Library {
00027
00028 inline
00029 Bounding_Box::Bounding_Box(dimension_type num_dimensions)
00030 : vec(num_dimensions), empty(false), empty_up_to_date(true) {
00031 }
00032
00033 inline dimension_type
00034 Bounding_Box::space_dimension() const {
00035 return vec.size();
00036 }
00037
00038 inline const Interval&
00039 Bounding_Box::operator[](const dimension_type k) const {
00040 assert(k < vec.size());
00041 return vec[k];
00042 }
00043
00044 inline bool
00045 Bounding_Box::is_empty() const {
00046 if (empty_up_to_date)
00047 return empty;
00048 else {
00049 empty_up_to_date = true;
00050 for (dimension_type k = vec.size(); k-- > 0; )
00051 if (vec[k].is_empty()) {
00052 empty = true;
00053 return true;
00054 }
00055 empty = false;
00056 return false;
00057 }
00058 }
00059
00060 inline bool
00061 Bounding_Box::get_lower_bound(const dimension_type k, bool& closed,
00062 Coefficient& n, Coefficient& d) const {
00063 assert(k < vec.size());
00064 const LBoundary& lb = vec[k].lower_bound();
00065 const ERational& lr = lb.bound();
00066
00067 if (is_plus_infinity(lr) || is_minus_infinity(lr))
00068 return false;
00069
00070 closed = lb.is_closed();
00071 n = raw_value(lr).get_num();
00072 d = raw_value(lr).get_den();
00073
00074 return true;
00075 }
00076
00077 inline bool
00078 Bounding_Box::get_upper_bound(const dimension_type k, bool& closed,
00079 Coefficient& n, Coefficient& d) const {
00080 assert(k < vec.size());
00081 const UBoundary& ub = vec[k].upper_bound();
00082 const ERational& ur = ub.bound();
00083
00084 if (is_plus_infinity(ur) || is_minus_infinity(ur))
00085 return false;
00086
00087 closed = ub.is_closed();
00088 n = raw_value(ur).get_num();
00089 d = raw_value(ur).get_den();
00090
00091 return true;
00092 }
00093
00094 inline void
00095 Bounding_Box::set_empty() {
00096 for (dimension_type k = vec.size(); k-- > 0; )
00097 vec[k].set_empty();
00098 empty = empty_up_to_date = true;
00099 }
00100
00101 inline void
00102 Bounding_Box::raise_lower_bound(const dimension_type k, const bool closed,
00103 Coefficient_traits::const_reference n,
00104 Coefficient_traits::const_reference d) {
00105 assert(k < vec.size());
00106 assert(d != 0);
00107 mpq_class q;
00108 assign_r(q.get_num(), n, ROUND_NOT_NEEDED);
00109 assign_r(q.get_den(), d, ROUND_NOT_NEEDED);
00110 q.canonicalize();
00111 vec[k].raise_lower_bound(LBoundary(ERational(q, ROUND_NOT_NEEDED),
00112 (closed
00113 ? LBoundary::CLOSED
00114 : LBoundary::OPEN)));
00115 empty_up_to_date = false;
00116 }
00117
00118 inline void
00119 Bounding_Box::lower_upper_bound(const dimension_type k, const bool closed,
00120 Coefficient_traits::const_reference n,
00121 Coefficient_traits::const_reference d) {
00122 assert(k < vec.size());
00123 assert(d != 0);
00124 mpq_class q;
00125 assign_r(q.get_num(), n, ROUND_NOT_NEEDED);
00126 assign_r(q.get_den(), d, ROUND_NOT_NEEDED);
00127 q.canonicalize();
00128 vec[k].lower_upper_bound(UBoundary(ERational(q, ROUND_NOT_NEEDED),
00129 (closed
00130 ? UBoundary::CLOSED
00131 : UBoundary::OPEN)));
00132 empty_up_to_date = false;
00133 }
00134
00135 }
00136
00137 #endif // !defined(PPL_Bounding_Box_inlines_hh)