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:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    (package private) static enum 
    Designates which end of the interval to work with.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private double
     
    private double
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor, contains the empty interval.
    R1Interval(double lo, double hi)
    Interval constructor.
    Copy constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    addPoint(double p)
    Returns the smallest interval that contains this interval and the point p.
    boolean
    As approxEquals(R1Interval, double), with a default value for maxError just larger than typical rounding errors in computing intervals.
    boolean
    approxEquals(R1Interval y, double maxError)
    Returns true if this interval can be transformed into y by moving each endpoint by at most maxError.
    double
    clampPoint(double p)
    Returns the closest point in the interval to the point p.
    boolean
    contains(double p)
     
    boolean
    Returns true if this interval contains the interval y.
    static R1Interval
    Returns an empty interval.
    boolean
    equals(Object that)
     
    expanded(double radius)
    Return an interval that contains all points with a distance "radius" of a point in this interval.
    (package private) void
    expandedInternal(double radius)
    Expands this interval to contain all points within a distance "radius" of a point in this interval.
    static R1Interval
    fromPoint(double p)
    Convenience method to construct an interval containing a single point.
    static R1Interval
    fromPointPair(double p1, double p2)
    Convenience method to construct the minimal interval containing the two given points.
    double
    Returns the center of the interval.
    double
    Return the Hausdorff distance to the given interval y.
    double
    Returns the length of the interval.
    (package private) double
    Returns the value at the given Endpoint, which must not be null.
    int
     
    double
    hi()
     
    (package private) void
    initFromPointPair(double p1, double p2)
     
    boolean
    interiorContains(double p)
     
    boolean
    Returns true if the interior of this interval contains the entire interval y (including its boundary).
    boolean
    Returns true if the interior of this interval intersects any point of y (including its boundary).
    Returns the intersection of this interval with y.
    (package private) void
    Sets this interval to the intersection of the current interval and y.
    boolean
    Returns true if this interval intersects y, i.e.
    boolean
    Returns true if the interval is empty, i.e.
    double
    lo()
     
    (package private) void
    set(double lo, double hi)
    Sets the minimum and maximum value of this interval.
    (package private) void
    Sets the current interval to the empty interval.
    (package private) void
    setHi(double hi)
    Sets the maximum value of this interval.
    (package private) void
    setLo(double lo)
    Sets the minimum value of this interval.
    (package private) void
    setValue(R1Interval.Endpoint endpoint, double value)
    Sets the value of the given Endpoint, which must not be null.
     
    Returns the smallest interval that contains this interval and y.
    (package private) void
    unionInternal(double p)
    Expands this interval so that it contains the point p.
    (package private) void
    Sets this interval to the union of this interval and y.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • lo

      private double lo
    • hi

      private double hi
  • Constructor Details

    • R1Interval

      R1Interval()
      Default constructor, contains the empty interval.

      Package private since only the S2 library needs to mutate R1Intervals. External code that needs an empty interval should call empty().

    • R1Interval

      public R1Interval(double lo, double hi)
      Interval constructor. If lo > hi, the interval is empty.
    • R1Interval

      public R1Interval(R1Interval interval)
      Copy constructor.
  • Method Details

    • 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.
    • initFromPointPair

      void initFromPointPair(double p1, double p2)
    • lo

      public double lo()
    • hi

      public double hi()
    • getValue

      double getValue(R1Interval.Endpoint endpoint)
      Returns the value at the given Endpoint, which must not be null.
    • setValue

      void setValue(R1Interval.Endpoint endpoint, double value)
      Sets the value of the given Endpoint, which must not be null.
    • 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 interval y.
    • interiorContains

      public boolean interiorContains(R1Interval y)
      Returns true if the interior of this interval contains the entire interval y (including its boundary).
    • intersects

      public boolean intersects(R1Interval y)
      Returns true if this interval intersects y, 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 of y (including its boundary).
    • getDirectedHausdorffDistance

      public double getDirectedHausdorffDistance(R1Interval y)
      Return the Hausdorff distance to the given interval y. 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).
    • set

      void set(double lo, double hi)
      Sets the minimum and maximum value of this interval. If lo is greater than hi this interval will become empty.

      Package private since only the S2 libraries have a current need to mutate R1Intervals.

    • setLo

      void setLo(double lo)
      Sets the minimum value of this interval. If lo is greater than hi() this interval will become empty.

      Package private since only the S2 libraries have a current need to mutate R1Intervals.

    • setHi

      void setHi(double hi)
      Sets the maximum value of this interval. If hi is less than lo() this interval will become empty.

      Package private since only the S2 libraries have a current need to mutate R1Intervals.

    • setEmpty

      void setEmpty()
      Sets the current interval to the empty interval.

      Package private since only the S2 libraries have a current need to mutate R1Intervals.

    • unionInternal

      void unionInternal(double p)
      Expands this interval so that it contains the point p.

      Package private since only the S2 library needs to mutate R1Intervals.

    • clampPoint

      public double clampPoint(double p)
      Returns the closest point in the interval to the point p. 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.
    • expandedInternal

      void expandedInternal(double radius)
      Expands this interval to contain all points within a distance "radius" of a point in this interval.

      Package private since only S2 classes are intended to mutate R1Intervals for now.

    • union

      Returns the smallest interval that contains this interval and y.
    • unionInternal

      void unionInternal(R1Interval y)
      Sets this interval to the union of this interval and y.

      Package private since only S2 classes are intended to mutate R11Intervals for now.

    • intersection

      @CheckReturnValue public R1Interval intersection(R1Interval y)
      Returns the intersection of this interval with y. Empty intervals do not need to be special-cased.
    • intersectionInternal

      void intersectionInternal(R1Interval y)
      Sets this interval to the intersection of the current interval and y.

      Package private since only S2 classes are intended to mutate R1 intervals for now.

    • addPoint

      @CheckReturnValue public R1Interval addPoint(double p)
      Returns the smallest interval that contains this interval and the point p.
    • equals

      public boolean equals(Object that)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • approxEquals

      public boolean approxEquals(R1Interval y)
      As approxEquals(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 into y by moving each endpoint by at most maxError. The empty interval is considered to be positioned arbitrarily on the real line, thus any interval for which length <= 2*maxError is true matches the empty interval.
    • toString

      public String toString()
      Overrides:
      toString in class Object