Search this API

y.layout.router.polyline
Class Interval

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

public class Interval
extends java.lang.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 intervals and the given value.
static Interval calculateUnion(Interval i1, Interval i2)
          Returns the union of the given intervals.
 boolean contains(double value)
          Checks whether or not the given value lies within the interval.
 boolean coveredBy(Interval other)
          Checks whether or not the given interval fully covers this interval.
 boolean coveredBy(Interval other, double eps)
          Checks whether or not the given interval fully covers this interval given a small epsilon value.
 double distanceTo(double value)
          Returns the distance between the value and this interval.
 double distanceTo(Interval other)
          Returns the distance between this interval and the given interval.
 boolean equals(java.lang.Object other)
          Checks whether or not this interval equals to 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, i.e., the difference between the upper bound and the lower bound.
 int hashCode()
          Returns the hash code for this interval.
 boolean hasSameRange(Interval other)
          Checks whether or not this interval and the given interval cover about the same range.
 boolean hasSameRange(Interval other, double eps)
          Checks whether or not this interval and the given interval cover the same range.
 boolean intersects(Interval other)
          Checks whether or not this interval intersects with the given interval.
 boolean intersects(Interval other, double minIntersection)
          Checks whether or not this interval intersects with the given interval, considering the given minimum intersection length.
 boolean isGreaterThan(Interval other)
          Checks whether or not the lower bound of this interval is greater than the upper bound of the given interval.
 boolean isLessThan(Interval other)
          Checks whether or not the upper bound of this interval is smaller than the lower bound of the given interval.
 java.lang.String toString()
          Returns a string representation of this Interval object.
 
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.

The upper and lower bound of the two given values are determined automatically, i.e., the smaller one will be treated as the lower bound and the larger one as the upper bound.

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 whether or not the given value lies within the interval.

Parameters:
value - the value to check
Returns:
true if the value lies within the interval, false otherwise

getSize

public double getSize()
Returns the size of the interval, i.e., the difference between the upper bound and the lower bound.

Returns:
the size of the interval

intersects

public boolean intersects(Interval other)
Checks whether or not this interval intersects with 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 whether or not this interval intersects with the given interval, considering the given minimum intersection length.

Parameters:
other - the other interval to check
minIntersection - the minimum length of the intersection of the intervals
Returns:
true if the intervals intersect at least by the given minimum length, false otherwise

distanceTo

public double distanceTo(double value)
Returns the distance between the value and this 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 which the distance is calculated
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 intersect, the distance is 0. Otherwise, it is equal to dist(minimum of upper bounds, maximum of lower bounds).

Parameters:
other - the other interval to which the distance is calculated
Returns:
the distance between this interval and the given interval

coveredBy

public boolean coveredBy(Interval other)
Checks whether or not the given interval fully covers this interval.

The given interval covers this interval, if other lower bound - epsilon <= this lower bound and this upper bound <= other upper bound + 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 whether or not the given interval fully covers this interval given a small epsilon value.

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

Parameters:
other - the other interval
eps - the epsilon value that determines the extended range of the other interval
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 for which the closest interval bound will be returned
Returns:
  • the value, if the given value lies within the interval, or
  • the lower bound, if the given value is smaller than or equal to the lower bound, or
  • the upper bound, if the given value is greater than or equal to the upper bound

isLessThan

public boolean isLessThan(Interval other)
Checks whether or not the upper bound of this interval is smaller than the lower bound of the given interval.

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

isGreaterThan

public boolean isGreaterThan(Interval other)
Checks whether or not 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 on the right of the given one, false otherwise

toString

public java.lang.String toString()
Returns a string representation of this Interval object.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this Interval object

hasSameRange

public boolean hasSameRange(Interval other)
Checks whether or not 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 a small 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 whether or not this interval and the given interval cover 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 the given epsilon value.

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 each other. Otherwise, the intersection is [maximum of lower bounds, minimum of 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 of lower bounds, maximum of 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 intervals and the given value.

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

Parameters:
interval - the interval to be extended
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 each other. Otherwise, the bridging interval is [minimum of upper bounds, maximum of 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(java.lang.Object other)
Checks whether or not this interval equals to the given interval.

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

Overrides:
equals in class java.lang.Object
Parameters:
other - the other interval
Returns:
true if the two given intervals are equal, false otherwise

hashCode

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

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

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