Search this API

y.layout.router.polyline
Class Interval

java.lang.Object
  extended by y.layout.router.polyline.Interval

public class Interval
extends Object

This class represents a one-dimensional, closed interval.


Constructor Summary
Interval(double bound1, double bound2)
          Creates a new interval between the given bounds.
 
Method Summary
static Interval calculateBridge(Interval i1, Interval i2)
          Returns the bridging interval between the given intervals.
static Interval calculateIntersection(Interval i1, Interval i2)
          Returns the intersection of the given intervals.
static YRectangle calculateSpanningRectangle(Interval horizontal, Interval vertical)
          Returns the spanning rectangle between the given intervals.
static Interval calculateUnion(Interval interval, double value)
          Returns the union of the given interval and the given value.
static Interval calculateUnion(Interval i1, Interval i2)
          Returns the union of the given intervals.
 boolean contains(double value)
          Checks if the given value is inside the interval.
 boolean coveredBy(Interval other)
          Checks if the given interval covers this interval fully.
 boolean coveredBy(Interval other, double eps)
          Checks if the given interval covers this interval fully.
 double distanceTo(double value)
          Returns the distance between the value and the interval.
 double distanceTo(Interval other)
          Returns the distance between this interval and the given interval.
 boolean equals(Object other)
          Checks if this interval equals the given interval.
 double getCenter()
          Returns the midpoint of the interval.
 double getClosest(double value)
          Returns the interval bound that is closest to the given value.
 double getMax()
          Returns the upper bound of the interval.
 double getMin()
          Returns the lower bound of the interval.
 double getSize()
          Returns the size of the interval.
 int hashCode()
          Returns the hash code for this interval.
 boolean hasSameRange(Interval other)
          Checks if this interval and the given interval cover about the same range.
 boolean hasSameRange(Interval other, double eps)
          Checks if this interval and the given interval cover the same range.
 boolean intersects(Interval other)
          Checks if this interval intersects the given interval.
 boolean intersects(Interval other, double minIntersection)
          Checks if this interval intersects the given interval and the intersection has a length of at least minIntersection.
 boolean isGreaterThan(Interval other)
          Checks if the lower bound of this interval is greater than the upper bound of the given interval.
 boolean isLessThan(Interval other)
          Checks if the upper bound of this interval is lesser than the lower bound of the given interval.
 String toString()
          Returns a string representation of this interval.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Interval

public Interval(double bound1,
                double bound2)
Creates a new interval between the given bounds. Determines automatically the upper and lower bound of the two given values.

Parameters:
bound1 - the first interval bound
bound2 - the second interval bound
Method Detail

getMin

public double getMin()
Returns the lower bound of the interval.

Returns:
the lower bound of the interval

getMax

public double getMax()
Returns the upper bound of the interval.

Returns:
the upper bound of the interval

getCenter

public double getCenter()
Returns the midpoint of the interval.

Returns:
the midpoint of the interval

contains

public boolean contains(double value)
Checks if the given value is inside the interval.

Parameters:
value - the value to check
Returns:
true, if the value is inside the interval, false otherwise.

getSize

public double getSize()
Returns the size of the interval.

Returns:
the size of the interval

intersects

public boolean intersects(Interval other)
Checks if this interval intersects the given interval. This means that both intervals have at least one common value.

Parameters:
other - the other interval to check
Returns:
true, if the intervals have at least one common value, false otherwise.

intersects

public boolean intersects(Interval other,
                          double minIntersection)
Checks if this interval intersects the given interval and the intersection has a length of at least minIntersection.

Parameters:
other - the other interval to check
minIntersection - the minimal length the intervals have to intersect
Returns:
true, if the intervals intersect by at least minIntersection, false otherwise.

distanceTo

public double distanceTo(double value)
Returns the distance between the value and the interval.

If this interval contains the specified value, the distance is 0. Otherwise, it is the minimum of dist(value, lower bound) and dist(value, upper bound).

Parameters:
value - the value to calculate the distance to
Returns:
the distance between the value and the interval

distanceTo

public double distanceTo(Interval other)
Returns the distance between this interval and the given interval.

If the intervals intersects(y.layout.router.polyline.Interval), the distance is 0. Otherwise, it is dist(minimum of upper bounds, maximum of lower bounds)."

Parameters:
other - the other interval to calculate the distance to
Returns:
the distance between this interval and the given interval

coveredBy

public boolean coveredBy(Interval other)
Checks if the given interval covers this interval fully.

The given interval covers this interval, if lower bound other - epsilon <= lower bound this and upper bound this <= upper bound other + epsilon where epsilon is a small value.

Parameters:
other - the other interval
Returns:
true if this interval is fully covered by the other interval, false otherwise.

coveredBy

public boolean coveredBy(Interval other,
                         double eps)
Checks if the given interval covers this interval fully.

The given interval covers this interval, if lower bound other - epsilon <= lower bound this and upper bound this <= upper bound other + epsilon.

Parameters:
other - the other interval
eps - The epsilon value the range of the other interval is extended.
Returns:
true if this interval is fully covered by the other interval, false otherwise.

getClosest

public double getClosest(double value)
Returns the interval bound that is closest to the given value.

Parameters:
value - the value to get the closest interval bound for
Returns:
value, if the given value is inside the interval, the lower bound if the given value is lesser than or equal the lower bound and the upper bound if the given value is greater than or equal the upper bound.

isLessThan

public boolean isLessThan(Interval other)
Checks if the upper bound of this interval is lesser than the lower bound of the given interval.

Parameters:
other - the interval to compare.
Returns:
true if the current interval is left of the given one, false otherwise.

isGreaterThan

public boolean isGreaterThan(Interval other)
Checks if the lower bound of this interval is greater than the upper bound of the given interval.

Parameters:
other - the interval to compare.
Returns:
true if the current interval is right of the given one, false otherwise.

toString

public String toString()
Returns a string representation of this interval.

Overrides:
toString in class Object
Returns:
a string representation of this interval

hasSameRange

public boolean hasSameRange(Interval other)
Checks if this interval and the given interval cover about the same range.

The intervals are considered to cover the same range, if their minimum values as well as their maximum values differ only in an epsilon value.

Parameters:
other - the other interval
Returns:
true if the intervals cover the same range, false otherwise.

hasSameRange

public boolean hasSameRange(Interval other,
                            double eps)
Checks if this interval and the given interval cover the same range.

Parameters:
other - the other interval
eps - The maximum distance between the two minimum and the two maximum values.
Returns:
true if the intervals cover the same range, false otherwise.

calculateIntersection

public static Interval calculateIntersection(Interval i1,
                                             Interval i2)
Returns the intersection of the given intervals.

The intersection is null if the given intervals do not intersect. Otherwise the intersection is [maximum lower bounds, minimum upper bounds].

Parameters:
i1 - the first interval
i2 - the second interval
Returns:
the intersection of the given intervals or null if the intervals do not intersect.

calculateUnion

public static Interval calculateUnion(Interval i1,
                                      Interval i2)
Returns the union of the given intervals.

The union is [minimum lower bounds, maximum upper bounds].

Parameters:
i1 - the first interval
i2 - the second interval
Returns:
the union of the given intervals.

calculateUnion

public static Interval calculateUnion(Interval interval,
                                      double value)
Returns the union of the given interval and the given value.

The union is between the minimal of the lower bound of interval and value and the maximum of the upper bound of interval and value.

Parameters:
interval - the interval to extend
value - the value to be in the union
Returns:
the union of the given interval and the given value.

calculateBridge

public static Interval calculateBridge(Interval i1,
                                       Interval i2)
Returns the bridging interval between the given intervals.

The bridging interval is null if the given intervals intersect. Otherwise the bridging interval is [minimum upper bounds, maximum lower bounds].

Parameters:
i1 - the first interval
i2 - the second interval
Returns:
the bridging interval between the given intervals or null if the intervals intersect.

calculateSpanningRectangle

public static YRectangle calculateSpanningRectangle(Interval horizontal,
                                                    Interval vertical)
Returns the spanning rectangle between the given intervals.

The first interval spans the rectangle in horizontal dimension, the second interval in vertical dimension.

Parameters:
horizontal - the interval that defines the location and length of the rectangle in horizontal dimension
vertical - the interval that defines the location and length of the rectangle in vertical dimension
Returns:
the spanning rectangle between the given intervals.

equals

public boolean equals(Object other)
Checks if this interval equals the given interval.

Two intervals are equal if the have the same lower and upper bounds.

Overrides:
equals in class Object
Parameters:
other - the other interval
Returns:
true if this and the given interval are equal, false otherwise.

hashCode

public int hashCode()
Returns the hash code for this interval.

Overrides:
hashCode in class Object
Returns:
the hash code for this interval.

© Copyright 2000-2013,
yWorks GmbH.
All rights reserved.