3838
3939public final strictfp class S1Interval implements Cloneable {
4040
41- // TODO(dbeaumont): Make this class immutable and fix callers.
42- private double lo ;
43- private double hi ;
41+ private final double lo ;
42+ private final double hi ;
4443
4544 /**
4645 * Both endpoints must be in the range -Pi to Pi inclusive. The value -Pi is
@@ -123,16 +122,6 @@ public double hi() {
123122 return hi ;
124123 }
125124
126- public void setLo (double lo ) {
127- this .lo = lo ;
128- // assert (isValid());
129- }
130-
131- public void setHi (double hi ) {
132- this .hi = hi ;
133- // assert (isValid());
134- }
135-
136125 /**
137126 * An interval is valid if neither bound exceeds Pi in absolute value, and the
138127 * value -Pi appears only in the Empty() and Full() intervals.
@@ -350,8 +339,8 @@ public S1Interval addPoint(double p) {
350339 }
351340
352341 /**
353- * Return an interval that contains all points with a distance "radius" of a
354- * point in this interval. Note that the expansion of an empty interval is
342+ * Return an interval that contains all points within a distance "radius" of
343+ * a point in this interval. Note that the expansion of an empty interval is
355344 * always empty. The radius must be non-negative.
356345 */
357346 public S1Interval expanded (double radius ) {
@@ -366,13 +355,13 @@ public S1Interval expanded(double radius) {
366355 return full ();
367356 }
368357
369- S1Interval result =
370- new S1Interval ( Math .IEEEremainder (lo () - radius , 2 * S2 .M_PI ),
371- Math .IEEEremainder (hi () + radius , 2 * S2 .M_PI ) );
372- if (result . lo () == -S2 .M_PI ) {
373- result . setLo ( S2 .M_PI ) ;
358+ // NOTE(dbeaumont): Should this remainder be 2 * M_PI or just M_PI ??
359+ double lo = Math .IEEEremainder (lo () - radius , 2 * S2 .M_PI );
360+ double hi = Math .IEEEremainder (hi () + radius , 2 * S2 .M_PI );
361+ if (lo == -S2 .M_PI ) {
362+ lo = S2 .M_PI ;
374363 }
375- return result ;
364+ return new S1Interval ( lo , hi ) ;
376365 }
377366
378367 /**
@@ -516,12 +505,4 @@ public static double positiveDistance(double a, double b) {
516505 // the return result is approximately 2*Pi and not zero.
517506 return (b + S2 .M_PI ) - (a - S2 .M_PI );
518507 }
519-
520- @ Override
521- public Object clone () throws CloneNotSupportedException {
522- S1Interval clone = (S1Interval ) super .clone ();
523- clone .setLo (lo ());
524- clone .setHi (hi ());
525- return clone ;
526- }
527508}
0 commit comments