3636 *
3737 */
3838
39- public strictfp class S1Interval implements Cloneable {
39+ public final strictfp class S1Interval implements Cloneable {
4040
41- private final double [] bounds = new double [2 ];
41+ // TODO(dbeaumont): Make this class immutable and fix callers.
42+ private double lo ;
43+ private double hi ;
4244
4345 /**
4446 * Both endpoints must be in the range -Pi to Pi inclusive. The value -Pi is
@@ -50,32 +52,33 @@ public S1Interval(double lo, double hi) {
5052
5153 /**
5254 * Copy constructor. Assumes that the given interval is valid.
55+ *
56+ * TODO(dbeaumont): Make this class immutable and remove this method.
5357 */
5458 public S1Interval (S1Interval interval ) {
55- bounds [ 0 ] = interval .bounds [ 0 ] ;
56- bounds [ 1 ] = interval .bounds [ 1 ] ;
59+ this . lo = interval .lo ;
60+ this . hi = interval .hi ;
5761 }
5862
5963 /**
6064 * Internal constructor that assumes that both arguments are in the correct
6165 * range, i.e. normalization from -Pi to Pi is already done.
6266 */
6367 private S1Interval (double lo , double hi , boolean checked ) {
64- bounds [0 ] = lo ;
65- bounds [1 ] = hi ;
66-
68+ double newLo = lo ;
69+ double newHi = hi ;
6770 if (!checked ) {
6871 if (lo == -S2 .M_PI && hi != S2 .M_PI ) {
69- setLo ( S2 .M_PI ) ;
72+ newLo = S2 .M_PI ;
7073 }
7174 if (hi == -S2 .M_PI && lo != S2 .M_PI ) {
72- setHi ( S2 .M_PI ) ;
75+ newHi = S2 .M_PI ;
7376 }
7477 }
75- // assert (isValid());
78+ this .lo = newLo ;
79+ this .hi = newHi ;
7680 }
7781
78-
7982 public static S1Interval empty () {
8083 return new S1Interval (S2 .M_PI , -S2 .M_PI , true );
8184 }
@@ -112,30 +115,21 @@ public static S1Interval fromPointPair(double p1, double p2) {
112115 }
113116 }
114117
115-
116118 public double lo () {
117- return bounds [ 0 ] ;
119+ return lo ;
118120 }
119121
120122 public double hi () {
121- return bounds [ 1 ] ;
123+ return hi ;
122124 }
123125
124- public double bound (int i ) {
125- return bounds [i ];
126- }
127-
128- public double [] bounds () {
129- return bounds ;
130- }
131-
132- public void setLo (double p ) {
133- bounds [0 ] = p ;
126+ public void setLo (double lo ) {
127+ this .lo = lo ;
134128 // assert (isValid());
135129 }
136130
137- public void setHi (double p ) {
138- bounds [ 1 ] = p ;
131+ public void setHi (double hi ) {
132+ this . hi = hi ;
139133 // assert (isValid());
140134 }
141135
@@ -148,7 +142,6 @@ public boolean isValid() {
148142 && !(lo () == -S2 .M_PI && hi () != S2 .M_PI ) && !(hi () == -S2 .M_PI && lo () != S2 .M_PI ));
149143 }
150144
151-
152145 /** Return true if the interval contains all points on the unit circle. */
153146 public boolean isFull () {
154147 return hi () - lo () == 2 * S2 .M_PI ;
@@ -166,7 +159,6 @@ public boolean isInverted() {
166159 return lo () > hi ();
167160 }
168161
169-
170162 /**
171163 * Return the midpoint of the interval. For full and empty intervals, the
172164 * result is arbitrary.
@@ -194,7 +186,6 @@ public double getLength() {
194186 return (length > 0 ) ? length : -1 ;
195187 }
196188
197-
198189 /**
199190 * Return the complement of the interior of the interval. An interval and its
200191 * complement have the same boundary but do not share any interior values. The
@@ -221,7 +212,6 @@ public boolean contains(double p) {
221212 return fastContains (p );
222213 }
223214
224-
225215 /**
226216 * Return true if the interval (which is closed) contains the point 'p'. Skips
227217 * the normalization of 'p' from -Pi to Pi.
@@ -235,7 +225,6 @@ public boolean fastContains(double p) {
235225 }
236226 }
237227
238-
239228 /** Return true if the interior of the interval contains the point 'p'. */
240229 public boolean interiorContains (double p ) {
241230 // Works for empty, full, and singleton intervals.
@@ -251,7 +240,6 @@ public boolean interiorContains(double p) {
251240 }
252241 }
253242
254-
255243 /**
256244 * Return true if the interval contains the given interval 'y'. Works for
257245 * empty, full, and singleton intervals.
@@ -332,7 +320,6 @@ public boolean interiorIntersects(final S1Interval y) {
332320 }
333321 }
334322
335-
336323 /**
337324 * Expand the interval by the minimum amount necessary so that it contains the
338325 * given point "p" (an angle in the range [-Pi, Pi]).
@@ -388,7 +375,6 @@ public S1Interval expanded(double radius) {
388375 return result ;
389376 }
390377
391-
392378 /**
393379 * Return the smallest interval that contains this interval and the given
394380 * interval "y".
@@ -432,7 +418,6 @@ public S1Interval union(final S1Interval y) {
432418 }
433419 }
434420
435-
436421 /**
437422 * Return the smallest interval that contains the intersection of this
438423 * interval with "y". Note that the region of intersection may consist of two
@@ -472,7 +457,6 @@ public S1Interval intersection(final S1Interval y) {
472457 return empty ();
473458 }
474459
475-
476460 /**
477461 * Return true if the length of the symmetric difference between the two
478462 * intervals is at most the given tolerance.
0 commit comments