Example #1
0
Interval operator/ (Interval const& lhs, Interval const& rhs){
    // this may be improved if multiple intervals are used
    if(in(0, lhs) || in(0, rhs)){
        return Interval::world();
    }
    else{
        // [a,b] / [c,d] = [min (a/c, a/d, b/c, b/d), max (a/c, a/d, b/c, b/d)]
        double a = static_cast<double>(lhs.lower());
        double b = static_cast<double>(lhs.upper());
        double c = static_cast<double>(rhs.lower());
        double d = static_cast<double>(rhs.upper());
        
        return Interval(
            (detail::min)(
                (a / c),
                (a / d),
                (b / c),
                (b / d)
            ),
            (detail::max)(
                (a / c),
                (a / d),
                (b / c),
                (b / d)
            )
        );
    }
}
Example #2
0
//Returns the mignitude of an interval X
Rat mig(const Interval& X)
{
	if(X.lower() > 0)
		return X.lower();
	else if(X.upper() < 0)
		return (-1)*X.upper();
	else
		return 0;
}
Example #3
0
Interval operator/(const Interval& X, const Interval& Y)
{
	if(boost::numeric::zero_in(Y) == false)
		return (X * (1/Y));
	else
	{
		if(X.upper() <= 0 && Y.upper() == 0)
		{
			Interval Z(X.upper()/Y.lower(), infinity);
			return Z;
		}
		else if(X.upper() <= 0 && Y.lower() ==0)
		{
			Interval Z(neginfinity, X.upper()/Y.upper());
			return Z;
		}
		else if(X.lower() >= 0 && Y.upper() == 0)
		{
			Interval Z(neginfinity, X.lower()/Y.lower());
			return Z;
		}
		else if(X.lower() >= 0 && Y.lower() == 0)
		{
			Interval Z(X.lower()/Y.upper(), infinity);
			return Z;
		}
		else if(X.lower() <= 0 && 0 <= X.upper())
		{
			Interval Z(neginfinity, infinity);
			return Z;
		}
	}

	return (Interval)0;
}
Example #4
0
Region::Axis::Axis(Interval i, float res)
    : bounds(i)
{
    size_t size = std::max((size_t)1,
                           (size_t)(res * (i.upper() - i.lower())));
    for (unsigned index=0; index < size; ++index)
    {
        const float frac = (index + 0.5) / size;
        values.push_back(i.lower() * (1 - frac) + i.upper() * frac);
    }
}
Example #5
0
 std::string operator()(Interval   const & e, bool use_parenthesis = false) const
 {
   std::stringstream ss;
   ss << " [ " << operator()(e.lower()) << "; " << operator()(e.upper()) << " ] ";
   static_cast<int>(use_parenthesis); //to silence unused parameter warnings
   return ss.str();
 }
Example #6
0
Region::Axis::Axis(Interval i, size_t size)
    : bounds(i)
{
    for (unsigned index=0; index < size; ++index)
    {
        const float frac = (index + 0.5) / size;
        values.push_back(i.lower() * (1 - frac) + i.upper() * frac);
    }
}
Example #7
0
Interval operator/(const int& x, const Interval& Y)
{
	if(boost::numeric::zero_in(Y) == false)
	{
		Interval X(x/Y.upper(), x/Y.lower());
		return X;
	}
	else
	{
		Interval X(x,x);

		if(X.upper() <= 0 && Y.upper() == 0)
		{
			Interval Z(X.upper()/Y.lower(), infinity);
			return Z;
		}
		else if(X.upper() <= 0 && Y.lower() ==0)
		{
			Interval Z(neginfinity, X.upper()/Y.upper());
			return Z;
		}
		else if(X.lower() >= 0 && Y.upper() == 0)
		{
			Interval Z(neginfinity, X.lower()/Y.lower());
			return Z;
		}
		else if(X.lower() >= 0 && Y.lower() == 0)
		{
			Interval Z(X.lower()/Y.upper(), infinity);
			return Z;
		}
		else if(X.lower() <= 0 && 0 <= X.upper())
		{
			Interval Z(neginfinity, infinity);
			return Z;
		}
	}

	return (Interval)0;
}
Example #8
0
void Octree::populateChildren(Evaluator* e, const Subregion& r,
                              uint32_t flags)
{
    // The cell is a LEAF cell until proven otherwise
    type = LEAF;

    // If we can recurse, then it may become a BRANCH cell
    if (r.canSplit())
    {
        // First, do interval evaluation to see if the cell should be checked
        Interval out = e->eval(r.X.bounds, r.Y.bounds, r.Z.bounds);
        if (out.upper() < 0)
        {
            type = FULL;
        }
        else if (out.lower() >= 0)
        {
            type = EMPTY;
        }
        else
        {   // If the cell wasn't empty or filled, recurse
            e->push();
            auto rs = r.octsect();
            for (uint8_t i=0; i < 8; ++i)
            {
                children[i].reset(new Octree(e, rs[i], flags));
            }
            type = BRANCH;
            e->pop();
        }
    }

    // Otherwise, calculate corner values
    if (type != BRANCH)
    {
        for (uint8_t i=0; i < 8; ++i)
        {
            auto c = pos(i);
            e->set(c.x, c.y, c.z, i);
        }
        const float* fs = e->values(8);
        for (uint8_t i=0; i < 8; ++i)
        {
            corners[i] = fs[i] < 0;
        }
    }
}
Example #9
0
Union_of_Intervals zero_division_solve(Interval X, Interval Y)
{
	if(X.upper() < 0 && Y.lower() < 0 && Y.upper() > 0)
	{
		Union_of_Intervals Z(neginfinity, X.upper()/Y.upper(), X.upper()/Y.lower(), infinity);
		return Z;
	}
	else if(X.lower() > 0 && Y.lower() < 0 && Y.upper() > 0)
	{
		Union_of_Intervals Z(neginfinity, X.lower()/Y.lower(), X.lower()/Y.upper(), infinity);
		return Z;
	}
	else
	{
		Union_of_Intervals Z(0,0,0,0);
		return Z;
	}
}
Example #10
0
Interval operator* (Interval const& lhs, Interval const& rhs){
    // [a,b] * [c,d] = [min (ac, ad, bc, bd), max (ac, ad, bc, bd)]
    return Interval(
        (detail::min)(
            lhs.lower() * rhs.lower(),
            lhs.lower() * rhs.upper(),
            lhs.upper() * rhs.lower(),
            lhs.upper() * rhs.upper()
        ),
        (detail::max)(
            lhs.lower() * rhs.lower(),
            lhs.lower() * rhs.upper(),
            lhs.upper() * rhs.lower(),
            lhs.upper() * rhs.upper()
        )
    );
}
Example #11
0
// A ∩ B = [max(a,c),min(b,d)]
Interval operator& (Interval const& lhs, Interval const& rhs){
    return Interval(
        (std::max)(lhs.lower(), rhs.lower()),
        (std::min)(lhs.upper(), rhs.upper())
    );
}
Example #12
0
std::pair<double, double> IntervalBoundsCheck::calc_bounds(const Sym& sym) const {

    Interval bounds = eval(sym, pimpl->bounds);
    return make_pair(bounds.lower(), bounds.upper());
}
Example #13
0
 static T lower(const Interval<T>& interval)
 {
   return interval.lower();
 }
Example #14
0
// A ∩ (B ∪ [-∞,c]) = [a,min(b,d)]
Interval restrictLeft(Interval const& lhs, Interval const& rhs){
    return Interval(lhs.lower(), (std::min)(lhs.upper(), rhs.upper()));
}
Example #15
0
//// set operations ////
bool in(Interval::Integer x, Interval const& i){
    return x >= i.lower() && x <= i.upper();
}
Example #16
0
// A ∩ (B ∪ [d,+∞]) = [max(a,c),b]
Interval restrictRight(Interval const& lhs, Interval const& rhs){
    return Interval((std::max)(lhs.lower(), rhs.lower()), lhs.upper());
}
Example #17
0
Interval operator- (Interval const& lhs, Interval const& rhs){
    return Interval(lhs.lower() - rhs.lower(), lhs.upper() - rhs.upper());
}
Example #18
0
bool Interval::operator==(Interval const& rhs) const {
    return lower() == rhs.lower() && upper() == rhs.upper();
}