1616
1717package com .google .common .geometry ;
1818
19- import com .google .common .annotations .VisibleForTesting ;
2019import com .google .common .base .Objects ;
2120import com .google .common .base .Preconditions ;
2221
2928 * straight edges (geodesics). Edges of length 0 and 180 degrees are not
3029 * allowed, i.e. adjacent vertices should not be identical or antipodal.
3130 *
31+ * <p>Note: Polylines do not have a Contains(S2Point) method, because
32+ * "containment" is not numerically well-defined except at the polyline
33+ * vertices.
34+ *
3235 */
33- public strictfp class S2Polyline implements S2Region {
36+ public final strictfp class S2Polyline implements S2Region {
3437 private static final Logger log = Logger .getLogger (S2Polyline .class .getCanonicalName ());
3538
36- private int numVertices ;
37-
38- private S2Point [] vertices ;
39-
40- // TODO(kirilll): Get rid of debug mode. Turn it into tests.
41- @ VisibleForTesting
42- static boolean debugMode = false ;
39+ private final int numVertices ;
40+ private final S2Point [] vertices ;
4341
4442 /**
4543 * Create a polyline that connects the given vertices. Empty polylines are
4644 * allowed. Adjacent vertices should not be identical or antipodal. All
4745 * vertices should be unit length.
48- *
49- * @param vertices
5046 */
5147 public S2Polyline (List <S2Point > vertices ) {
48+ // assert isValid(vertices);
5249 this .numVertices = vertices .size ();
53- this .vertices = new S2Point [numVertices ];
54-
55- if (debugMode ) {
56- // assert (isValid(vertices));
57- }
58-
59- if (numVertices > 0 ) {
60- vertices .toArray (this .vertices );
61- }
50+ this .vertices = vertices .toArray (new S2Point [numVertices ]);
6251 }
6352
6453 /**
6554 * Copy constructor.
55+ *
56+ * TODO(dbeaumont): Now that S2Polyline is immutable, remove this.
6657 */
6758 public S2Polyline (S2Polyline src ) {
6859 this .numVertices = src .numVertices ();
@@ -239,7 +230,6 @@ public int getNearestEdgeIndex(S2Point point) {
239230 minIndex = i ;
240231 }
241232 }
242-
243233 return minIndex ;
244234 }
245235
@@ -264,7 +254,6 @@ public boolean equals(Object that) {
264254 }
265255
266256 S2Polyline thatPolygon = (S2Polyline ) that ;
267-
268257 if (numVertices != thatPolygon .numVertices ) {
269258 return false ;
270259 }
@@ -274,16 +263,11 @@ public boolean equals(Object that) {
274263 return false ;
275264 }
276265 }
277-
278266 return true ;
279267 }
280268
281269 @ Override
282270 public int hashCode () {
283271 return Objects .hashCode (numVertices , Arrays .deepHashCode (vertices ));
284272 }
285-
286-
287- // Polylines do not have a Contains(S2Point) method, because "containment"
288- // is not numerically well-defined except at the polyline vertices.
289273}
0 commit comments