Package com.google.common.geometry
Class S1Interval
- java.lang.Object
-
- com.google.common.geometry.S1Interval
-
- All Implemented Interfaces:
Serializable,Cloneable
@GwtCompatible(serializable=true) public final class S1Interval extends Object implements Cloneable, Serializable
An S1Interval represents a closed interval on a unit circle (also known as a 1-dimensional sphere). It is capable of representing the empty interval (containing no points), the full interval (containing all points), and zero-length intervals (containing a single point).Points are represented by the angle they make with the positive x-axis in the range [-Pi, Pi]. An interval is represented by its lower and upper bounds (both inclusive, since the interval is closed). The lower bound may be greater than the upper bound, in which case the interval is "inverted" (i.e. it passes through the point (-1, 0)).
Note that the point (-1, 0) has two valid representations, Pi and -Pi. The normalized representation of this point internally is Pi, so that endpoints of normal intervals are in the range (-Pi, Pi]. However, we take advantage of the point -Pi to construct two special intervals: the full() interval is [-Pi, Pi], and the Empty() interval is [Pi, -Pi].
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description S1Interval()S1Interval(double lo, double hi)Both endpoints must be in the range -Pi to Pi inclusive.S1Interval(S1Interval interval)Copy constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description S1IntervaladdPoint(double p)Expands the interval by the minimum amount necessary so that it contains the pointp(an angle in the range [-Pi, Pi]).booleanapproxEquals(S1Interval y)AsapproxEquals(S1Interval, double), with a default maxError of 1e-15.booleanapproxEquals(S1Interval y, double maxError)Returns true if this interval can be transformed into the intervalyby moving each endpoint by at most "maxError" (and without the endpoints crossing, which would invert the interval).doubleclampPoint(double p)Returns the closest point in the interval to the pointp.S1Intervalcomplement()Return the complement of the interior of the interval.booleancontains(double p)Returns true if the interval (which is closed) contains the point 'p'.booleancontains(S1Interval y)Returns true if the interval contains the intervaly.static S1Intervalempty()booleanequals(Object that)Returns true if two intervals contains the same set of points.S1Intervalexpanded(double margin)Returns a new interval that has been expanded on each side by the distancemargin.booleanfastContains(double p)Returns true if the interval (which is closed) contains the point 'p'.static S1IntervalfromPoint(double radians)Convenience method to construct an interval containing a single point.static S1IntervalfromPointPair(double p1, double p2)Convenience method to construct the minimal interval containing the two given points.static S1Intervalfull()doubleget(int endpoint)Returns the value of the given endpoint in this interval, which must be 0 for the low end, or 1 for the high end.doublegetCenter()Returns the midpoint of the interval.doublegetComplementCenter()Return the midpoint of the complement of the interval.doublegetDirectedHausdorffDistance(S1Interval y)Return the Hausdorff distance to the given intervaly.doublegetLength()Returns the length of the interval.inthashCode()doublehi()booleaninteriorContains(double p)Returns true if the interior of the interval contains the point 'p'.booleaninteriorContains(S1Interval y)Returns true if the interior of this interval contains the entire interval 'y'.booleaninteriorIntersects(S1Interval y)Returns true if the interior of this interval contains any point of the intervaly(including its boundary).S1Intervalintersection(S1Interval y)Returns the smallest interval that contains the intersection of this interval withy.booleanintersects(S1Interval y)Returns true if the two intervals contain any points in common.booleanisEmpty()Returns true if the interval is empty, i.e.booleanisFull()Returns true if the interval contains all points on the unit circle.booleanisInverted()Returns true if lo() > hi().booleanisValid()An interval is valid if neither bound exceeds Pi in absolute value, and the value -Pi appears only in the Empty() and full() intervals.doublelo()static doublepositiveDistance(double a, double b)Computes the distance fromatobin the range [0, 2*Pi).StringtoString()S1Intervalunion(S1Interval y)Returns the smallest interval that contains this interval and the intervaly.
-
-
-
Constructor Detail
-
S1Interval
public S1Interval()
-
S1Interval
public S1Interval(double lo, double hi)Both endpoints must be in the range -Pi to Pi inclusive. The value -Pi is converted internally to Pi except for the full() and empty() intervals.
-
S1Interval
public S1Interval(S1Interval interval)
Copy constructor. Assumes that theintervalis valid.
-
-
Method Detail
-
empty
public static S1Interval empty()
-
full
public static S1Interval full()
-
fromPoint
public static S1Interval fromPoint(double radians)
Convenience method to construct an interval containing a single point.
-
fromPointPair
public static S1Interval 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()
-
isValid
public boolean isValid()
An interval is valid if neither bound exceeds Pi in absolute value, and the value -Pi appears only in the Empty() and full() intervals.
-
isFull
public boolean isFull()
Returns true if the interval contains all points on the unit circle.
-
isEmpty
public boolean isEmpty()
Returns true if the interval is empty, i.e. it contains no points.
-
isInverted
public boolean isInverted()
Returns true if lo() > hi(). (This is true for empty intervals.)
-
getCenter
public double getCenter()
Returns the midpoint of the interval. For full and empty intervals, the result is arbitrary.
-
getLength
public double getLength()
Returns the length of the interval. The length of an empty interval is negative.
-
complement
public S1Interval complement()
Return the complement of the interior of the interval. An interval and its complement have the same boundary but do not share any interior values. The complement operator is not a bijection, since the complement of a singleton interval (containing a single value) is the same as the complement of an empty interval.
-
getComplementCenter
public double getComplementCenter()
Return the midpoint of the complement of the interval. For full and empty intervals, the result is arbitrary. For a singleton interval (containing a single point), the result is its antipodal point on S1.
-
contains
public boolean contains(double p)
Returns true if the interval (which is closed) contains the point 'p'.
-
fastContains
public boolean fastContains(double p)
Returns true if the interval (which is closed) contains the point 'p'. Skips the normalization of 'p' from -Pi to Pi.
-
interiorContains
public boolean interiorContains(double p)
Returns true if the interior of the interval contains the point 'p'.
-
contains
public boolean contains(S1Interval y)
Returns true if the interval contains the intervaly. Works for empty, full, and singleton intervals.
-
interiorContains
public boolean interiorContains(S1Interval y)
Returns true if the interior of this interval contains the entire interval 'y'. Note that x.interiorContains(x) is true only when x is the empty or full interval, and x.interiorContains(S1Interval(p,p)) is equivalent to x.InteriorContains(p).
-
intersects
public boolean intersects(S1Interval y)
Returns true if the two intervals contain any points in common. Note that the point +/-Pi has two representations, so the intervals [-Pi,-3] and [2,Pi] intersect, for example.
-
interiorIntersects
public boolean interiorIntersects(S1Interval y)
Returns true if the interior of this interval contains any point of the intervaly(including its boundary). Works for empty, full, and singleton intervals.
-
getDirectedHausdorffDistance
public double getDirectedHausdorffDistance(S1Interval y)
Return the Hausdorff distance to the given intervaly. For two S1Intervals x and y, this distance is defined byh(x, y) = max_{p in x} min_{q in y} d(p, q), whered(.,.)is measured along S1.
-
addPoint
@CheckReturnValue public S1Interval addPoint(double p)
Expands the interval by the minimum amount necessary so that it contains the pointp(an angle in the range [-Pi, Pi]).
-
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 S1Interval expanded(double margin)
Returns a new interval that has been expanded on each side by the distancemargin. If "margin" is negative, then shrink the interval on each side by "margin" instead. The resulting interval may be empty or full. Any expansion (positive or negative) of a full interval remains full, and any expansion of an empty interval remains empty.
-
union
@CheckReturnValue public S1Interval union(S1Interval y)
Returns the smallest interval that contains this interval and the intervaly.
-
get
public double get(int endpoint)
Returns the value of the given endpoint in this interval, which must be 0 for the low end, or 1 for the high end.
-
intersection
@CheckReturnValue public S1Interval intersection(S1Interval y)
Returns the smallest interval that contains the intersection of this interval withy. Note that the region of intersection may consist of two disjoint intervals.
-
approxEquals
public boolean approxEquals(S1Interval y, double maxError)
Returns true if this interval can be transformed into the intervalyby moving each endpoint by at most "maxError" (and without the endpoints crossing, which would invert the interval). Empty and full intervals are considered to start at an arbitrary point on the unit circle, thus any interval with (length <= 2*maxError) matches the empty interval, and any interval with (length >= 2*Pi - 2*maxError) matches the full interval.
-
approxEquals
public boolean approxEquals(S1Interval y)
AsapproxEquals(S1Interval, double), with a default maxError of 1e-15.
-
equals
public boolean equals(Object that)
Returns true if two intervals contains the same set of points.
-
positiveDistance
public static double positiveDistance(double a, double b)Computes the distance fromatobin the range [0, 2*Pi). This is equivalent todrem(b - a - S2.M_PI, 2 * S2.M_PI) + S2.M_PI, except that it is more numerically stable (it does not lose precision for very small positive distances).
-
-