org.spaceroots.mantissa.utilities
Class Interval

java.lang.Object
  extended byorg.spaceroots.mantissa.utilities.Interval

public class Interval
extends Object

This class represents an interval on the real line.

This class allows to perform simple interval operations like point inclusion tests and intersection operations.

There is no distinction between open and closed intervals because real numbers cannot be represented exactly.

Version:
$Id: Interval.java 1539 2003-12-13 19:31:14Z luc $
Author:
Luc Maisonobe
See Also:
IntervalsList

Constructor Summary
Interval()
          Build the [0, 0] interval.
Interval(double a, double b)
          Build an interval with the given bounds.
Interval(Interval i)
          Copy-constructor.
 
Method Summary
static Interval add(Interval i1, Interval i2)
          Add two intervals.
 void addToSelf(Interval i)
          Add an interval to the instance.
 boolean contains(double x)
          Check if the interval contains a point.
 boolean contains(Interval i)
          Check if the interval contains another interval.
 double getInf()
          Get the lower bound of the interval.
 double getLength()
          Get the length of the interval.
 double getSup()
          Get the upper bound of the interval.
static Interval intersection(Interval i1, Interval i2)
          Intersect two intervals.
 boolean intersects(Interval i)
          Check if an interval intersects the instance.
 void intersectSelf(Interval i)
          Intersects the instance with an interval.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Interval

public Interval()
Build the [0, 0] interval.


Interval

public Interval(double a,
                double b)
Build an interval with the given bounds.

The given bounds do not need to be ordered, they will be reordered by the constructor.

Parameters:
a - first bound
b - second bound

Interval

public Interval(Interval i)
Copy-constructor.

Parameters:
i - interval to copy
Method Detail

getInf

public double getInf()
Get the lower bound of the interval.

Returns:
lower bound of the interval

getSup

public double getSup()
Get the upper bound of the interval.

Returns:
upper bound of the interval

getLength

public double getLength()
Get the length of the interval.

Returns:
length of the interval

contains

public boolean contains(double x)
Check if the interval contains a point.

Parameters:
x - point to check
Returns:
true if the interval contains x

contains

public boolean contains(Interval i)
Check if the interval contains another interval.

Parameters:
i - interval to check
Returns:
true if i is completely included in the instance

intersects

public boolean intersects(Interval i)
Check if an interval intersects the instance.

Parameters:
i - interval to check
Returns:
true if i intersects the instance

addToSelf

public void addToSelf(Interval i)
Add an interval to the instance.

This method expands the instance.

This operation is not a union operation. If the instance and the interval are disjoints (i.e. if intersects(i) would return false), then the hole between the intervals is filled in.

Parameters:
i - interval to add to the instance

add

public static Interval add(Interval i1,
                           Interval i2)
Add two intervals.

This operation is not a union operation. If the intervals are disjoints (i.e. if i1.intersects(i2) would return false), then the hole between the intervals is filled in.

Parameters:
i1 - first interval
i2 - second interval
Returns:
a new interval

intersectSelf

public void intersectSelf(Interval i)
Intersects the instance with an interval.

This method reduces the instance, it could even become empty if the interval does not intersects the instance.

Parameters:
i - interval with which the instance should be intersected

intersection

public static Interval intersection(Interval i1,
                                    Interval i2)
Intersect two intervals.

Parameters:
i1 - first interval
i2 - second interval
Returns:
a new interval which is the intersection of i1 with i2


Copyright © 2001-2007 Luc Maisonobe. All Rights Reserved.