GeoPolyLine extends GeoObject { @Nonnull @Override public GeoPoint getCenter() { assert !points.isEmpty(); double elevationMeters = 0.0; GeoPoint southWest = points.get(0); GeoPoint northEast = points.get(0); for (final GeoPoint point : points) { elevationMeters = elevationMeters + point.getElevationMetersOrNaN(); final GeoLine sw = new GeoLine(southWest, point); if (sw.isWrappedOnLongSide()) { southWest = southWest.withLon(point.getLon()); } else { final GeoLine ne = new GeoLine(northEast, point); if (!ne.isWrappedOnLongSide()) { northEast = northEast.withLon(point.getLon()); } } if (point.getLat() < southWest.getLat()) { southWest = southWest.withLat(point.getLat()); } else { if (point.getLat() > northEast.getLat()) { northEast = northEast.withLat(point.getLat()); } } } final GeoPoint center = new GeoPoint( (southWest.getLat() + northEast.getLat()) / 2.0, (southWest.getLon() + northEast.getLon()) / 2.0, elevationMeters / points.size()); return center; } GeoPolyLine(@Nonnull final List<GeoPoint> points); @SuppressWarnings({"ConstantConditions", "UnusedDeclaration"}) @Deprecated private  GeoPolyLine(); @Nonnull @Override GeoPoint getOrigin(); @Nonnull @Override GeoPoint getCenter(); @Nonnull GeoPoint getPointAtOffset(final double offsetInMeters); int size(); @Nonnull GeoPoint get(final int i); @Nonnull List<GeoLine> asLines(); @Nonnull GeoLine getLine(final int i); @Nonnull @Override GeoPolyLine translate(@Nonnull final GeoVector vector); @Nonnull @Override GeoPolyLine moveTo(@Nonnull final GeoPoint origin); double getLengthMeters(); @Override boolean canEqual(@Nonnull final Object obj); @Override boolean equals(@Nullable final Object obj); @Override int hashCode();  }
@Test public void testGetCenter1() { LOG.info("testGetCenter1"); final GeoPoint x1 = new GeoPoint(0.0, 0.0); final GeoPoint x2 = new GeoPoint(10.0, 0.0); final GeoPoint x3 = new GeoPoint(10.0, 10.0); final GeoPoint x4 = new GeoPoint(0.0, 10.0); final List<GeoPoint> p1 = Lists.asList(x1, new GeoPoint[]{x2, x3, x4}); final GeoPolyLine poly1 = new GeoPolyLine(p1); Assert.assertEquals(new GeoPoint(5.0, 5.0), poly1.getCenter()); }
@Test public void testGetCenter2() { LOG.info("testGetCenter2"); final GeoPoint x1 = new GeoPoint(0.0, 0.0); final GeoPoint x2 = new GeoPoint(0.0, 10.0); final GeoPoint x3 = new GeoPoint(2.0, 20.0); final List<GeoPoint> p1 = Lists.asList(x1, new GeoPoint[]{x2, x3}); final GeoPolyLine poly1 = new GeoPolyLine(p1); Assert.assertEquals(new GeoPoint(1.0, 10.0), poly1.getCenter()); }