@@ -273,30 +273,46 @@ public GeoPoints(MultiGeoPointValues in) {
273
273
public void setNextDocId (int docId ) throws IOException {
274
274
if (in .advanceExact (docId )) {
275
275
resize (in .docValueCount ());
276
- double centroidLat = 0 ;
277
- double centroidLon = 0 ;
278
- double maxLon = Double .NEGATIVE_INFINITY ;
279
- double minLon = Double .POSITIVE_INFINITY ;
280
- double maxLat = Double .NEGATIVE_INFINITY ;
281
- double minLat = Double .POSITIVE_INFINITY ;
282
- for (int i = 0 ; i < count ; i ++) {
283
- GeoPoint point = in .nextValue ();
284
- values [i ].reset (point .lat (), point .lon ());
285
- centroidLat += point .getLat ();
286
- centroidLon += point .getLon ();
287
- maxLon = Math .max (maxLon , values [i ].getLon ());
288
- minLon = Math .min (minLon , values [i ].getLon ());
289
- maxLat = Math .max (maxLat , values [i ].getLat ());
290
- minLat = Math .min (minLat , values [i ].getLat ());
276
+ if (count == 1 ) {
277
+ setSingleValue ();
278
+ } else {
279
+ setMultiValue ();
291
280
}
292
- centroid .reset (centroidLat / count , centroidLon / count );
293
- boundingBox .topLeft ().reset (maxLat , minLon );
294
- boundingBox .bottomRight ().reset (minLat , maxLon );
295
281
} else {
296
282
resize (0 );
297
283
}
298
284
}
299
285
286
+ private void setSingleValue () throws IOException {
287
+ GeoPoint point = in .nextValue ();
288
+ values [0 ].reset (point .lat (), point .lon ());
289
+ centroid .reset (point .lat (), point .lon ());
290
+ boundingBox .topLeft ().reset (point .lat (), point .lon ());
291
+ boundingBox .bottomRight ().reset (point .lat (), point .lon ());
292
+ }
293
+
294
+ private void setMultiValue () throws IOException {
295
+ double centroidLat = 0 ;
296
+ double centroidLon = 0 ;
297
+ double maxLon = Double .NEGATIVE_INFINITY ;
298
+ double minLon = Double .POSITIVE_INFINITY ;
299
+ double maxLat = Double .NEGATIVE_INFINITY ;
300
+ double minLat = Double .POSITIVE_INFINITY ;
301
+ for (int i = 0 ; i < count ; i ++) {
302
+ GeoPoint point = in .nextValue ();
303
+ values [i ].reset (point .lat (), point .lon ());
304
+ centroidLat += point .getLat ();
305
+ centroidLon += point .getLon ();
306
+ maxLon = Math .max (maxLon , values [i ].getLon ());
307
+ minLon = Math .min (minLon , values [i ].getLon ());
308
+ maxLat = Math .max (maxLat , values [i ].getLat ());
309
+ minLat = Math .min (minLat , values [i ].getLat ());
310
+ }
311
+ centroid .reset (centroidLat / count , centroidLon / count );
312
+ boundingBox .topLeft ().reset (maxLat , minLon );
313
+ boundingBox .bottomRight ().reset (minLat , maxLon );
314
+ }
315
+
300
316
/**
301
317
* Set the {@link #size()} and ensure that the {@link #values} array can
302
318
* store at least that many entries.
0 commit comments