Package com.google.common.geometry
Class R1Interval
- java.lang.Object
-
- com.google.common.geometry.R1Interval
-
- All Implemented Interfaces:
Serializable
@GwtCompatible(serializable=true) public final class R1Interval extends Object implements Serializable
An R1Interval represents a closed, bounded interval on the real line. It is capable of representing the empty interval (containing no points) and zero-length intervals (containing a single point).- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description R1Interval(double lo, double hi)Interval constructor.R1Interval(R1Interval interval)Copy constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description R1IntervaladdPoint(double p)Returns the smallest interval that contains this interval and the pointp.booleanapproxEquals(R1Interval y)AsapproxEquals(R1Interval, double), with a default value for maxError just larger than typical rounding errors in computing intervals.booleanapproxEquals(R1Interval y, double maxError)Returns true if this interval can be transformed intoyby moving each endpoint by at mostmaxError.doubleclampPoint(double p)Returns the closest point in the interval to the pointp.booleancontains(double p)booleancontains(R1Interval y)Returns true if this interval contains the intervaly.static R1Intervalempty()Returns an empty interval.booleanequals(Object that)R1Intervalexpanded(double radius)Return an interval that contains all points with a distance "radius" of a point in this interval.static R1IntervalfromPoint(double p)Convenience method to construct an interval containing a single point.static R1IntervalfromPointPair(double p1, double p2)Convenience method to construct the minimal interval containing the two given points.doublegetCenter()Returns the center of the interval.doublegetDirectedHausdorffDistance(R1Interval y)Return the Hausdorff distance to the given intervaly.doublegetLength()Returns the length of the interval.inthashCode()doublehi()booleaninteriorContains(double p)booleaninteriorContains(R1Interval y)Returns true if the interior of this interval contains the entire intervaly(including its boundary).booleaninteriorIntersects(R1Interval y)Returns true if the interior of this interval intersects any point ofy(including its boundary).R1Intervalintersection(R1Interval y)Returns the intersection of this interval withy.booleanintersects(R1Interval y)Returns true if this interval intersectsy, i.e.booleanisEmpty()Returns true if the interval is empty, i.e.doublelo()StringtoString()R1Intervalunion(R1Interval y)Returns the smallest interval that contains this interval andy.
-
-
-
Constructor Detail
-
R1Interval
public R1Interval(double lo, double hi)Interval constructor. If lo > hi, the interval is empty.
-
R1Interval
public R1Interval(R1Interval interval)
Copy constructor.
-
-
Method Detail
-
empty
public static R1Interval empty()
Returns an empty interval. (Any interval where lo > hi is considered empty.)
-
fromPoint
public static R1Interval fromPoint(double p)
Convenience method to construct an interval containing a single point.
-
fromPointPair
public static R1Interval fromPointPair(double p1, double p2)
Convenience method to construct the minimal interval containing the two given points. This is equivalent to starting with an empty interval and calling AddPoint() twice, but it is more efficient.
-
lo
public double lo()
-
hi
public double hi()
-
isEmpty
public boolean isEmpty()
Returns true if the interval is empty, i.e. it contains no points.
-
getCenter
public double getCenter()
Returns the center of the interval. For empty intervals, the result is arbitrary.
-
getLength
public double getLength()
Returns the length of the interval. The length of an empty interval is negative.
-
contains
public boolean contains(double p)
-
interiorContains
public boolean interiorContains(double p)
-
contains
public boolean contains(R1Interval y)
Returns true if this interval contains the intervaly.
-
interiorContains
public boolean interiorContains(R1Interval y)
Returns true if the interior of this interval contains the entire intervaly(including its boundary).
-
intersects
public boolean intersects(R1Interval y)
Returns true if this interval intersectsy, i.e. if they have any points in common.
-
interiorIntersects
public boolean interiorIntersects(R1Interval y)
Returns true if the interior of this interval intersects any point ofy(including its boundary).
-
getDirectedHausdorffDistance
public double getDirectedHausdorffDistance(R1Interval y)
Return the Hausdorff distance to the given intervaly. For two R1Intervals x and y, this distance is defined as h(x, y) = max_{p in x} min_{q in y} d(p, q).
-
clampPoint
public double clampPoint(double p)
Returns the closest point in the interval to the pointp. The interval must be non-empty.
-
expanded
@CheckReturnValue public R1Interval expanded(double radius)
Return an interval that contains all points with a distance "radius" of a point in this interval. Note that the expansion of an empty interval is always empty.
-
union
@CheckReturnValue public R1Interval union(R1Interval y)
Returns the smallest interval that contains this interval andy.
-
intersection
@CheckReturnValue public R1Interval intersection(R1Interval y)
Returns the intersection of this interval withy. Empty intervals do not need to be special-cased.
-
addPoint
@CheckReturnValue public R1Interval addPoint(double p)
Returns the smallest interval that contains this interval and the pointp.
-
approxEquals
public boolean approxEquals(R1Interval y)
AsapproxEquals(R1Interval, double), with a default value for maxError just larger than typical rounding errors in computing intervals.
-
approxEquals
public boolean approxEquals(R1Interval y, double maxError)
Returns true if this interval can be transformed intoyby moving each endpoint by at mostmaxError. The empty interval is considered to be positioned arbitrarily on the real line, thus any interval for whichlength <= 2*maxErroris true matches the empty interval.
-
-