timothyw553 commented on code in PR #18879:
URL: https://github.com/apache/iceberg/pull/18879#discussion_r4723584662


##########
core/src/test/java/org/apache/iceberg/TestSphericalGeographyBoundsBuilder.java:
##########
@@ -0,0 +1,701 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Random;
+import java.util.stream.Stream;
+import org.apache.iceberg.geospatial.BoundingBox;
+import org.apache.iceberg.geospatial.GeospatialBound;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.ValueSource;
+
+class TestSphericalGeographyBoundsBuilder {
+  private static final double LATITUDE_TOLERANCE = 1e-9;
+  private static final double LONGITUDE_TOLERANCE = 1e-9;
+
+  @Test
+  void capturesInteriorNorthernLatitudeExtremum() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, 60.0, 90.0, 60.0);
+
+    double midpointLatitude =
+        Math.toDegrees(Math.atan(Math.tan(Math.toRadians(60.0)) / 
Math.cos(Math.PI / 4.0)));
+    BoundingBox box = bounds.build();
+    assertThat(box.min()).isEqualTo(GeospatialBound.createXY(0.0, 60.0));
+    assertThat(box.max().x()).isEqualTo(90.0);
+    
assertThat(box.max().y()).isGreaterThanOrEqualTo(midpointLatitude).isLessThan(67.793);
+  }
+
+  @Test
+  void capturesInteriorSouthernLatitudeExtremum() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, -60.0, 90.0, -60.0);
+
+    double midpointLatitude =
+        Math.toDegrees(Math.atan(Math.tan(Math.toRadians(-60.0)) / 
Math.cos(Math.PI / 4.0)));
+    BoundingBox box = bounds.build();
+    assertThat(box.min().x()).isEqualTo(0.0);
+    
assertThat(box.min().y()).isLessThanOrEqualTo(midpointLatitude).isGreaterThan(-67.793);
+    assertThat(box.max()).isEqualTo(GeospatialBound.createXY(90.0, -60.0));
+  }
+
+  @Test
+  void doesNotExpandEndpointLatitude() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(20.0, 10.0, 20.0, 80.0);
+
+    BoundingBox box = bounds.build();
+    assertThat(box.min()).isEqualTo(GeospatialBound.createXY(20.0, 10.0));
+    assertThat(box.max()).isEqualTo(GeospatialBound.createXY(20.0, 80.0));
+  }
+
+  @Test
+  void representsAntimeridianCrossingAsWrappedInterval() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(170.0, 5.0, -170.0, 8.0);
+
+    BoundingBox box = bounds.build();
+    assertThat(box.min().x()).isEqualTo(170.0);
+    assertThat(box.max().x()).isEqualTo(-170.0);
+    assertThat(box.min().x()).isGreaterThan(box.max().x());
+  }
+
+  @Test
+  void mergesIntervalsRatherThanOnlyEndpoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(100.0, 0.0, -100.0, 0.0);
+    bounds.addEdge(-10.0, 0.0, 10.0, 0.0);
+
+    BoundingBox box = bounds.build();
+    assertThat(longitudeIsContained(180.0, box)).isTrue();
+    assertThat(longitudeIsContained(0.0, box)).isTrue();
+    assertThat(longitudeIsContained(50.0, box)).isTrue();
+    assertThat(longitudeIsContained(-50.0, box)).isFalse();
+  }
+
+  @Test
+  void includesPoleLongitudeWithFinitePoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addPoint(-120.0, 90.0);
+    bounds.addPoint(40.0, 10.0);
+
+    BoundingBox box = bounds.build();
+    assertThat(box.min()).isEqualTo(GeospatialBound.createXY(-120.0, 10.0));
+    assertThat(box.max()).isEqualTo(GeospatialBound.createXY(40.0, 90.0));
+  }
+
+  @Test
+  void usesStoredLongitudeForPoleOnlyBounds() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addPoint(10.0, 90.0);
+    bounds.addPoint(-50.0, 90.0);
+
+    assertThat(bounds.build())
+        .isEqualTo(
+            new BoundingBox(
+                GeospatialBound.createXY(-50.0, 90.0), 
GeospatialBound.createXY(10.0, 90.0)));
+  }
+
+  @Test
+  void usesFullWorldForOppositePoles() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, -90.0, 30.0, 90.0);
+
+    assertThat(bounds.build())
+        .isEqualTo(
+            new BoundingBox(
+                GeospatialBound.createXY(-180.0, -90.0), 
GeospatialBound.createXY(180.0, 90.0)));
+  }
+
+  @Test
+  void usesFullWorldForAntipodalEndpoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, 0.0, 180.0, 0.0);
+
+    assertThat(bounds.build())
+        .isEqualTo(
+            new BoundingBox(
+                GeospatialBound.createXY(-180.0, -90.0), 
GeospatialBound.createXY(180.0, 90.0)));
+  }
+
+  @Test
+  void treatsCoincidentEndpointsAsAPoint() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(12.0, 34.0, 12.0, 34.0);
+
+    assertThat(bounds.build())
+        .isEqualTo(
+            new BoundingBox(
+                GeospatialBound.createXY(12.0, 34.0), 
GeospatialBound.createXY(12.0, 34.0)));
+  }
+
+  @Test
+  void preservesBothStoredAntimeridianLongitudesForCoincidentEndpoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(-180.0, 30.0, 180.0, 30.0);
+
+    assertThat(bounds.build()).isEqualTo(box(180.0, 30.0, -180.0, 30.0));
+  }
+
+  @Test
+  void coversPoleBetweenNearlyCoincidentEndpoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    double latitude = Math.nextDown(90.0);
+    bounds.addEdge(0.0, latitude, 180.0, latitude);
+
+    BoundingBox box = bounds.build();
+    assertThat(box.min().y()).isLessThanOrEqualTo(latitude);
+    assertThat(box.max().y()).isEqualTo(90.0);
+    assertThat(box.min().x()).isEqualTo(-180.0);
+    assertThat(box.max().x()).isEqualTo(180.0);
+  }
+
+  @ParameterizedTest
+  @ValueSource(doubles = {60.0, -60.0, 1e-4, -1e-4})
+  void coversPoleInsideResolvedMinorArc(double latitude) {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, latitude, 180.0, latitude);
+    double south = latitude < 0.0 ? -90.0 : latitude;
+    double north = latitude > 0.0 ? 90.0 : latitude;
+
+    assertThat(bounds.build()).isEqualTo(box(-180.0, south, 180.0, north));
+  }
+
+  @Test
+  void coversPoleWhenLongitudeDifferenceRoundsTo180() {
+    // In binary64, 134.3 - (-45.7) rounds to 180, but the true difference is 
slightly larger.
+    // The minor arc passes near the North Pole at about -135.7, outside 
[-45.7, 134.3].
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(-45.7, 60.0, 134.3, 60.0);
+
+    assertThat(bounds.build()).isEqualTo(box(-180.0, 60.0, 180.0, 90.0));
+  }
+
+  @Test
+  void boundsShortEdgesWithoutFallingBackToWorld() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, 60.0, 1e-7, 60.0);
+
+    BoundingBox box = bounds.build();
+    assertThat(box.min().x()).isEqualTo(0.0);
+    assertThat(box.max().x()).isEqualTo(1e-7);
+    assertThat(box.min().y()).isBetween(59.999, 60.0);
+    assertThat(box.max().y()).isBetween(60.0, 60.001);
+  }

Review Comment:
   here `isBetween(60.0, 60.001)` lets the bound stop right at 60.0, and the 
1e-7 longitude span is too tiny to exercise the arc-length padding term. could 
we add midpoint checks like (0, 89.99995) to (40, 89.99995) (and negative) so 
both the fixed margin and arc-length padding are covered?



##########
core/src/test/java/org/apache/iceberg/TestSphericalGeographyBoundsBuilder.java:
##########
@@ -0,0 +1,701 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Random;
+import java.util.stream.Stream;
+import org.apache.iceberg.geospatial.BoundingBox;
+import org.apache.iceberg.geospatial.GeospatialBound;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.ValueSource;
+
+class TestSphericalGeographyBoundsBuilder {
+  private static final double LATITUDE_TOLERANCE = 1e-9;
+  private static final double LONGITUDE_TOLERANCE = 1e-9;
+
+  @Test
+  void capturesInteriorNorthernLatitudeExtremum() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, 60.0, 90.0, 60.0);
+
+    double midpointLatitude =
+        Math.toDegrees(Math.atan(Math.tan(Math.toRadians(60.0)) / 
Math.cos(Math.PI / 4.0)));
+    BoundingBox box = bounds.build();
+    assertThat(box.min()).isEqualTo(GeospatialBound.createXY(0.0, 60.0));
+    assertThat(box.max().x()).isEqualTo(90.0);
+    
assertThat(box.max().y()).isGreaterThanOrEqualTo(midpointLatitude).isLessThan(67.793);
+  }
+
+  @Test
+  void capturesInteriorSouthernLatitudeExtremum() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, -60.0, 90.0, -60.0);
+
+    double midpointLatitude =
+        Math.toDegrees(Math.atan(Math.tan(Math.toRadians(-60.0)) / 
Math.cos(Math.PI / 4.0)));
+    BoundingBox box = bounds.build();
+    assertThat(box.min().x()).isEqualTo(0.0);
+    
assertThat(box.min().y()).isLessThanOrEqualTo(midpointLatitude).isGreaterThan(-67.793);
+    assertThat(box.max()).isEqualTo(GeospatialBound.createXY(90.0, -60.0));
+  }
+
+  @Test
+  void doesNotExpandEndpointLatitude() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(20.0, 10.0, 20.0, 80.0);
+
+    BoundingBox box = bounds.build();
+    assertThat(box.min()).isEqualTo(GeospatialBound.createXY(20.0, 10.0));
+    assertThat(box.max()).isEqualTo(GeospatialBound.createXY(20.0, 80.0));
+  }
+
+  @Test
+  void representsAntimeridianCrossingAsWrappedInterval() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(170.0, 5.0, -170.0, 8.0);
+
+    BoundingBox box = bounds.build();
+    assertThat(box.min().x()).isEqualTo(170.0);
+    assertThat(box.max().x()).isEqualTo(-170.0);
+    assertThat(box.min().x()).isGreaterThan(box.max().x());
+  }
+
+  @Test
+  void mergesIntervalsRatherThanOnlyEndpoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(100.0, 0.0, -100.0, 0.0);
+    bounds.addEdge(-10.0, 0.0, 10.0, 0.0);
+
+    BoundingBox box = bounds.build();
+    assertThat(longitudeIsContained(180.0, box)).isTrue();
+    assertThat(longitudeIsContained(0.0, box)).isTrue();
+    assertThat(longitudeIsContained(50.0, box)).isTrue();
+    assertThat(longitudeIsContained(-50.0, box)).isFalse();
+  }
+
+  @Test
+  void includesPoleLongitudeWithFinitePoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addPoint(-120.0, 90.0);
+    bounds.addPoint(40.0, 10.0);
+
+    BoundingBox box = bounds.build();
+    assertThat(box.min()).isEqualTo(GeospatialBound.createXY(-120.0, 10.0));
+    assertThat(box.max()).isEqualTo(GeospatialBound.createXY(40.0, 90.0));
+  }
+
+  @Test
+  void usesStoredLongitudeForPoleOnlyBounds() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addPoint(10.0, 90.0);
+    bounds.addPoint(-50.0, 90.0);
+
+    assertThat(bounds.build())
+        .isEqualTo(
+            new BoundingBox(
+                GeospatialBound.createXY(-50.0, 90.0), 
GeospatialBound.createXY(10.0, 90.0)));
+  }
+
+  @Test
+  void usesFullWorldForOppositePoles() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, -90.0, 30.0, 90.0);
+
+    assertThat(bounds.build())
+        .isEqualTo(
+            new BoundingBox(
+                GeospatialBound.createXY(-180.0, -90.0), 
GeospatialBound.createXY(180.0, 90.0)));
+  }
+
+  @Test
+  void usesFullWorldForAntipodalEndpoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, 0.0, 180.0, 0.0);
+
+    assertThat(bounds.build())
+        .isEqualTo(
+            new BoundingBox(
+                GeospatialBound.createXY(-180.0, -90.0), 
GeospatialBound.createXY(180.0, 90.0)));
+  }
+
+  @Test
+  void treatsCoincidentEndpointsAsAPoint() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(12.0, 34.0, 12.0, 34.0);
+
+    assertThat(bounds.build())
+        .isEqualTo(
+            new BoundingBox(
+                GeospatialBound.createXY(12.0, 34.0), 
GeospatialBound.createXY(12.0, 34.0)));
+  }
+
+  @Test
+  void preservesBothStoredAntimeridianLongitudesForCoincidentEndpoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(-180.0, 30.0, 180.0, 30.0);
+
+    assertThat(bounds.build()).isEqualTo(box(180.0, 30.0, -180.0, 30.0));
+  }
+
+  @Test
+  void coversPoleBetweenNearlyCoincidentEndpoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    double latitude = Math.nextDown(90.0);
+    bounds.addEdge(0.0, latitude, 180.0, latitude);
+
+    BoundingBox box = bounds.build();
+    assertThat(box.min().y()).isLessThanOrEqualTo(latitude);
+    assertThat(box.max().y()).isEqualTo(90.0);
+    assertThat(box.min().x()).isEqualTo(-180.0);
+    assertThat(box.max().x()).isEqualTo(180.0);
+  }
+
+  @ParameterizedTest
+  @ValueSource(doubles = {60.0, -60.0, 1e-4, -1e-4})
+  void coversPoleInsideResolvedMinorArc(double latitude) {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, latitude, 180.0, latitude);
+    double south = latitude < 0.0 ? -90.0 : latitude;
+    double north = latitude > 0.0 ? 90.0 : latitude;
+
+    assertThat(bounds.build()).isEqualTo(box(-180.0, south, 180.0, north));
+  }
+
+  @Test
+  void coversPoleWhenLongitudeDifferenceRoundsTo180() {
+    // In binary64, 134.3 - (-45.7) rounds to 180, but the true difference is 
slightly larger.
+    // The minor arc passes near the North Pole at about -135.7, outside 
[-45.7, 134.3].
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(-45.7, 60.0, 134.3, 60.0);
+
+    assertThat(bounds.build()).isEqualTo(box(-180.0, 60.0, 180.0, 90.0));
+  }
+
+  @Test
+  void boundsShortEdgesWithoutFallingBackToWorld() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, 60.0, 1e-7, 60.0);
+
+    BoundingBox box = bounds.build();
+    assertThat(box.min().x()).isEqualTo(0.0);
+    assertThat(box.max().x()).isEqualTo(1e-7);
+    assertThat(box.min().y()).isBetween(59.999, 60.0);
+    assertThat(box.max().y()).isBetween(60.0, 60.001);
+  }
+
+  @Test
+  void coversNearlyEquatorialLatitudeExtremum() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    double latitude = 1e-10;
+    bounds.addEdge(-45.0, latitude, 45.0, latitude);
+
+    // The midpoint is the northern vertex for endpoints symmetric about the 
prime meridian.
+    double midpointLatitude =
+        Math.toDegrees(Math.atan(Math.tan(Math.toRadians(latitude)) / 
Math.cos(Math.PI / 4.0)));
+    BoundingBox box = bounds.build();
+    assertThat(box.min().y()).isEqualTo(latitude);
+    
assertThat(box.max().y()).isGreaterThanOrEqualTo(midpointLatitude).isLessThan(1e-5);
+  }
+
+  @ParameterizedTest
+  @ValueSource(doubles = {40.44773051160679, -40.44773051160679})
+  void coversInteriorExtremumRoundedBelowEndpoint(double latitude) {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    double longitude1 = 39.99170103009482;
+    double longitude2 = 39.992335550082764;
+    bounds.addEdge(longitude1, latitude, longitude2, latitude);
+
+    // Equal-latitude endpoints reach their latitude extremum at the arc 
midpoint.
+    double halfLongitudeSpan = Math.toRadians((longitude2 - longitude1) / 2.0);
+    double midpointLatitude =
+        Math.toDegrees(Math.atan(Math.tan(Math.toRadians(latitude)) / 
Math.cos(halfLongitudeSpan)));
+    BoundingBox box = bounds.build();
+    assertThat(box.min().y()).isLessThanOrEqualTo(Math.min(latitude, 
midpointLatitude));
+    assertThat(box.max().y()).isGreaterThanOrEqualTo(Math.max(latitude, 
midpointLatitude));
+    assertThat(box.min().y()).isGreaterThan(latitude - 1e-4);
+    assertThat(box.max().y()).isLessThan(latitude + 1e-4);
+  }
+
+  @Test
+  void usesFullWorldForNearlyAntipodalEndpoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, 10.0, 180.0 - 1e-7, -10.0);
+
+    assertThat(bounds.build()).isEqualTo(box(-180.0, -90.0, 180.0, 90.0));
+  }
+
+  @ParameterizedTest
+  @ValueSource(doubles = {2e-5, -2e-5})
+  void usesFullWorldBelowAntipodalFallbackThreshold(double latitude) {
+    // The cross-product length is about 0.987e-6, just below the 1e-6 
fallback threshold.
+    double longitude = 90.0 - Math.abs(latitude);
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(-longitude, latitude, longitude, latitude);
+
+    assertThat(bounds.build()).isEqualTo(box(-180.0, -90.0, 180.0, 90.0));
+  }
+
+  @ParameterizedTest
+  @ValueSource(doubles = {2.1e-5, -2.1e-5})
+  void boundsNearlyAntipodalEdgesAboveFallbackThreshold(double latitude) {
+    // The cross-product length is about 1.037e-6, just above the 1e-6 
fallback threshold.
+    double longitude = 90.0 - Math.abs(latitude);
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(-longitude, latitude, longitude, latitude);
+
+    // Symmetric endpoints reach their extremum at the midpoint. Use sin of 
the complement
+    // instead of cos near pi/2 to avoid cancellation in this independent 
expected value.
+    double midpointLatitude =
+        Math.toDegrees(
+            Math.atan2(
+                Math.tan(Math.toRadians(latitude)), 
Math.sin(Math.toRadians(90.0 - longitude))));
+    double south = Math.min(latitude, midpointLatitude);
+    double north = Math.max(latitude, midpointLatitude);
+    BoundingBox box = bounds.build();
+    assertThat(box.min().x()).isEqualTo(-longitude);
+    assertThat(box.max().x()).isEqualTo(longitude);
+    assertThat(box.min().y()).isBetween(south - 1e-5, south);
+    assertThat(box.max().y()).isBetween(north, north + 1e-5);
+  }
+
+  @Test
+  void explicitlyIncludesWorld() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addWorld();
+
+    assertThat(bounds.build()).isEqualTo(box(-180.0, -90.0, 180.0, 90.0));
+  }
+
+  @Test
+  void worldFallbackDoesNotRestoreInvalidBounds() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addPoint(181.0, 0.0);
+    bounds.addWorld();
+
+    assertThat(bounds.build()).isNull();
+  }
+
+  @Test
+  void invalidCoordinateSuppressesWorldBounds() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addWorld();
+    bounds.addPoint(0.0, 91.0);
+
+    assertThat(bounds.build()).isNull();
+  }
+
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("invalidCoordinates")
+  void invalidCoordinateSuppressesBounds(String description, double longitude, 
double latitude) {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addPoint(0.0, 0.0);
+    bounds.addPoint(longitude, latitude);
+
+    assertThat(bounds.build()).isNull();
+  }
+
+  @Test
+  void skipsNaNOrdinatesWithoutSuppressingBounds() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addPoint(0.0, 0.0);
+    bounds.addPoint(Double.NaN, Double.NaN);
+    bounds.addPoint(Double.NaN, 10.0);
+    bounds.addPoint(20.0, Double.NaN);
+
+    BoundingBox box = bounds.build();
+    assertThat(box.min()).isEqualTo(GeospatialBound.createXY(0.0, 0.0));
+    assertThat(box.max()).isEqualTo(GeospatialBound.createXY(20.0, 10.0));

Review Comment:
   since this starts with a complete (0, 0) point, we don't have tests for 
missing a single dimension (e.g. `addPoint(10, NaN)` returning null, or 
combining `(10, NaN)` with `(NaN, 20)`) or `addEdge(10, NaN, NaN, 20)` skipping 
arc interpolation. could we add separate tests for those?



##########
core/src/test/java/org/apache/iceberg/TestSphericalGeographyBoundsBuilder.java:
##########
@@ -0,0 +1,701 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Random;
+import java.util.stream.Stream;
+import org.apache.iceberg.geospatial.BoundingBox;
+import org.apache.iceberg.geospatial.GeospatialBound;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.ValueSource;
+
+class TestSphericalGeographyBoundsBuilder {
+  private static final double LATITUDE_TOLERANCE = 1e-9;
+  private static final double LONGITUDE_TOLERANCE = 1e-9;
+
+  @Test
+  void capturesInteriorNorthernLatitudeExtremum() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, 60.0, 90.0, 60.0);
+
+    double midpointLatitude =
+        Math.toDegrees(Math.atan(Math.tan(Math.toRadians(60.0)) / 
Math.cos(Math.PI / 4.0)));
+    BoundingBox box = bounds.build();
+    assertThat(box.min()).isEqualTo(GeospatialBound.createXY(0.0, 60.0));
+    assertThat(box.max().x()).isEqualTo(90.0);
+    
assertThat(box.max().y()).isGreaterThanOrEqualTo(midpointLatitude).isLessThan(67.793);
+  }
+
+  @Test
+  void capturesInteriorSouthernLatitudeExtremum() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, -60.0, 90.0, -60.0);
+
+    double midpointLatitude =
+        Math.toDegrees(Math.atan(Math.tan(Math.toRadians(-60.0)) / 
Math.cos(Math.PI / 4.0)));
+    BoundingBox box = bounds.build();
+    assertThat(box.min().x()).isEqualTo(0.0);
+    
assertThat(box.min().y()).isLessThanOrEqualTo(midpointLatitude).isGreaterThan(-67.793);
+    assertThat(box.max()).isEqualTo(GeospatialBound.createXY(90.0, -60.0));
+  }
+
+  @Test
+  void doesNotExpandEndpointLatitude() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(20.0, 10.0, 20.0, 80.0);
+
+    BoundingBox box = bounds.build();
+    assertThat(box.min()).isEqualTo(GeospatialBound.createXY(20.0, 10.0));
+    assertThat(box.max()).isEqualTo(GeospatialBound.createXY(20.0, 80.0));
+  }
+
+  @Test
+  void representsAntimeridianCrossingAsWrappedInterval() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(170.0, 5.0, -170.0, 8.0);
+
+    BoundingBox box = bounds.build();
+    assertThat(box.min().x()).isEqualTo(170.0);
+    assertThat(box.max().x()).isEqualTo(-170.0);
+    assertThat(box.min().x()).isGreaterThan(box.max().x());
+  }
+
+  @Test
+  void mergesIntervalsRatherThanOnlyEndpoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(100.0, 0.0, -100.0, 0.0);
+    bounds.addEdge(-10.0, 0.0, 10.0, 0.0);
+
+    BoundingBox box = bounds.build();
+    assertThat(longitudeIsContained(180.0, box)).isTrue();
+    assertThat(longitudeIsContained(0.0, box)).isTrue();
+    assertThat(longitudeIsContained(50.0, box)).isTrue();
+    assertThat(longitudeIsContained(-50.0, box)).isFalse();
+  }
+
+  @Test
+  void includesPoleLongitudeWithFinitePoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addPoint(-120.0, 90.0);
+    bounds.addPoint(40.0, 10.0);
+
+    BoundingBox box = bounds.build();
+    assertThat(box.min()).isEqualTo(GeospatialBound.createXY(-120.0, 10.0));
+    assertThat(box.max()).isEqualTo(GeospatialBound.createXY(40.0, 90.0));
+  }
+
+  @Test
+  void usesStoredLongitudeForPoleOnlyBounds() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addPoint(10.0, 90.0);
+    bounds.addPoint(-50.0, 90.0);
+
+    assertThat(bounds.build())
+        .isEqualTo(
+            new BoundingBox(
+                GeospatialBound.createXY(-50.0, 90.0), 
GeospatialBound.createXY(10.0, 90.0)));
+  }
+
+  @Test
+  void usesFullWorldForOppositePoles() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, -90.0, 30.0, 90.0);
+
+    assertThat(bounds.build())
+        .isEqualTo(
+            new BoundingBox(
+                GeospatialBound.createXY(-180.0, -90.0), 
GeospatialBound.createXY(180.0, 90.0)));
+  }
+
+  @Test
+  void usesFullWorldForAntipodalEndpoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, 0.0, 180.0, 0.0);
+
+    assertThat(bounds.build())
+        .isEqualTo(
+            new BoundingBox(
+                GeospatialBound.createXY(-180.0, -90.0), 
GeospatialBound.createXY(180.0, 90.0)));
+  }
+
+  @Test
+  void treatsCoincidentEndpointsAsAPoint() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(12.0, 34.0, 12.0, 34.0);
+
+    assertThat(bounds.build())
+        .isEqualTo(
+            new BoundingBox(
+                GeospatialBound.createXY(12.0, 34.0), 
GeospatialBound.createXY(12.0, 34.0)));
+  }
+
+  @Test
+  void preservesBothStoredAntimeridianLongitudesForCoincidentEndpoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(-180.0, 30.0, 180.0, 30.0);
+
+    assertThat(bounds.build()).isEqualTo(box(180.0, 30.0, -180.0, 30.0));
+  }
+
+  @Test
+  void coversPoleBetweenNearlyCoincidentEndpoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    double latitude = Math.nextDown(90.0);
+    bounds.addEdge(0.0, latitude, 180.0, latitude);
+
+    BoundingBox box = bounds.build();
+    assertThat(box.min().y()).isLessThanOrEqualTo(latitude);
+    assertThat(box.max().y()).isEqualTo(90.0);
+    assertThat(box.min().x()).isEqualTo(-180.0);
+    assertThat(box.max().x()).isEqualTo(180.0);
+  }
+
+  @ParameterizedTest
+  @ValueSource(doubles = {60.0, -60.0, 1e-4, -1e-4})
+  void coversPoleInsideResolvedMinorArc(double latitude) {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, latitude, 180.0, latitude);
+    double south = latitude < 0.0 ? -90.0 : latitude;
+    double north = latitude > 0.0 ? 90.0 : latitude;
+
+    assertThat(bounds.build()).isEqualTo(box(-180.0, south, 180.0, north));
+  }
+
+  @Test
+  void coversPoleWhenLongitudeDifferenceRoundsTo180() {
+    // In binary64, 134.3 - (-45.7) rounds to 180, but the true difference is 
slightly larger.
+    // The minor arc passes near the North Pole at about -135.7, outside 
[-45.7, 134.3].
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(-45.7, 60.0, 134.3, 60.0);
+
+    assertThat(bounds.build()).isEqualTo(box(-180.0, 60.0, 180.0, 90.0));
+  }
+
+  @Test
+  void boundsShortEdgesWithoutFallingBackToWorld() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, 60.0, 1e-7, 60.0);
+
+    BoundingBox box = bounds.build();
+    assertThat(box.min().x()).isEqualTo(0.0);
+    assertThat(box.max().x()).isEqualTo(1e-7);
+    assertThat(box.min().y()).isBetween(59.999, 60.0);
+    assertThat(box.max().y()).isBetween(60.0, 60.001);
+  }
+
+  @Test
+  void coversNearlyEquatorialLatitudeExtremum() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    double latitude = 1e-10;
+    bounds.addEdge(-45.0, latitude, 45.0, latitude);
+
+    // The midpoint is the northern vertex for endpoints symmetric about the 
prime meridian.
+    double midpointLatitude =
+        Math.toDegrees(Math.atan(Math.tan(Math.toRadians(latitude)) / 
Math.cos(Math.PI / 4.0)));
+    BoundingBox box = bounds.build();
+    assertThat(box.min().y()).isEqualTo(latitude);
+    
assertThat(box.max().y()).isGreaterThanOrEqualTo(midpointLatitude).isLessThan(1e-5);
+  }
+
+  @ParameterizedTest
+  @ValueSource(doubles = {40.44773051160679, -40.44773051160679})
+  void coversInteriorExtremumRoundedBelowEndpoint(double latitude) {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    double longitude1 = 39.99170103009482;
+    double longitude2 = 39.992335550082764;
+    bounds.addEdge(longitude1, latitude, longitude2, latitude);
+
+    // Equal-latitude endpoints reach their latitude extremum at the arc 
midpoint.
+    double halfLongitudeSpan = Math.toRadians((longitude2 - longitude1) / 2.0);
+    double midpointLatitude =
+        Math.toDegrees(Math.atan(Math.tan(Math.toRadians(latitude)) / 
Math.cos(halfLongitudeSpan)));
+    BoundingBox box = bounds.build();
+    assertThat(box.min().y()).isLessThanOrEqualTo(Math.min(latitude, 
midpointLatitude));
+    assertThat(box.max().y()).isGreaterThanOrEqualTo(Math.max(latitude, 
midpointLatitude));
+    assertThat(box.min().y()).isGreaterThan(latitude - 1e-4);
+    assertThat(box.max().y()).isLessThan(latitude + 1e-4);
+  }
+
+  @Test
+  void usesFullWorldForNearlyAntipodalEndpoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, 10.0, 180.0 - 1e-7, -10.0);
+
+    assertThat(bounds.build()).isEqualTo(box(-180.0, -90.0, 180.0, 90.0));
+  }
+
+  @ParameterizedTest
+  @ValueSource(doubles = {2e-5, -2e-5})
+  void usesFullWorldBelowAntipodalFallbackThreshold(double latitude) {
+    // The cross-product length is about 0.987e-6, just below the 1e-6 
fallback threshold.
+    double longitude = 90.0 - Math.abs(latitude);
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(-longitude, latitude, longitude, latitude);
+
+    assertThat(bounds.build()).isEqualTo(box(-180.0, -90.0, 180.0, 90.0));
+  }
+
+  @ParameterizedTest
+  @ValueSource(doubles = {2.1e-5, -2.1e-5})
+  void boundsNearlyAntipodalEdgesAboveFallbackThreshold(double latitude) {
+    // The cross-product length is about 1.037e-6, just above the 1e-6 
fallback threshold.
+    double longitude = 90.0 - Math.abs(latitude);
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(-longitude, latitude, longitude, latitude);
+
+    // Symmetric endpoints reach their extremum at the midpoint. Use sin of 
the complement
+    // instead of cos near pi/2 to avoid cancellation in this independent 
expected value.
+    double midpointLatitude =
+        Math.toDegrees(
+            Math.atan2(
+                Math.tan(Math.toRadians(latitude)), 
Math.sin(Math.toRadians(90.0 - longitude))));
+    double south = Math.min(latitude, midpointLatitude);
+    double north = Math.max(latitude, midpointLatitude);
+    BoundingBox box = bounds.build();
+    assertThat(box.min().x()).isEqualTo(-longitude);
+    assertThat(box.max().x()).isEqualTo(longitude);
+    assertThat(box.min().y()).isBetween(south - 1e-5, south);
+    assertThat(box.max().y()).isBetween(north, north + 1e-5);
+  }
+
+  @Test
+  void explicitlyIncludesWorld() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addWorld();
+
+    assertThat(bounds.build()).isEqualTo(box(-180.0, -90.0, 180.0, 90.0));
+  }
+
+  @Test
+  void worldFallbackDoesNotRestoreInvalidBounds() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addPoint(181.0, 0.0);
+    bounds.addWorld();
+
+    assertThat(bounds.build()).isNull();
+  }
+
+  @Test
+  void invalidCoordinateSuppressesWorldBounds() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addWorld();
+    bounds.addPoint(0.0, 91.0);
+
+    assertThat(bounds.build()).isNull();
+  }
+
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("invalidCoordinates")
+  void invalidCoordinateSuppressesBounds(String description, double longitude, 
double latitude) {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addPoint(0.0, 0.0);
+    bounds.addPoint(longitude, latitude);
+
+    assertThat(bounds.build()).isNull();
+  }
+
+  @Test
+  void skipsNaNOrdinatesWithoutSuppressingBounds() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addPoint(0.0, 0.0);
+    bounds.addPoint(Double.NaN, Double.NaN);
+    bounds.addPoint(Double.NaN, 10.0);
+    bounds.addPoint(20.0, Double.NaN);
+
+    BoundingBox box = bounds.build();
+    assertThat(box.min()).isEqualTo(GeospatialBound.createXY(0.0, 0.0));
+    assertThat(box.max()).isEqualTo(GeospatialBound.createXY(20.0, 10.0));
+  }
+
+  @Test
+  void nanOnlyInputHasNoBounds() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addPoint(Double.NaN, Double.NaN);
+
+    assertThat(bounds.build()).isNull();
+  }
+
+  @Test
+  void emptyBuilderHasNoBounds() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+
+    assertThat(bounds.build()).isNull();
+  }
+
+  @ParameterizedTest(name = "({0}, {1}) to ({2}, {3})")
+  @MethodSource("edgeBoundsCases")
+  void buildsBoundsForSphericalEdges(
+      double longitude1,
+      double latitude1,
+      double longitude2,
+      double latitude2,
+      BoundingBox expected) {
+    SphericalGeographyBoundsBuilder forward = new 
SphericalGeographyBoundsBuilder();
+    forward.addEdge(longitude1, latitude1, longitude2, latitude2);
+    assertBoundsCloseTo(forward.build(), expected);
+
+    SphericalGeographyBoundsBuilder reverse = new 
SphericalGeographyBoundsBuilder();
+    reverse.addEdge(longitude2, latitude2, longitude1, latitude1);
+    assertBoundsCloseTo(reverse.build(), expected);
+  }
+
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("lineBoundsCases")
+  void buildsBoundsForSphericalLines(String description, double[][] points, 
BoundingBox expected) {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    addLine(bounds, points);
+
+    assertBoundsCloseTo(bounds.build(), expected);
+  }
+
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("pointBoundsCases")
+  void buildsBoundsForPointSets(String description, double[][] points, 
BoundingBox expected) {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    for (double[] point : points) {
+      bounds.addPoint(point[0], point[1]);
+    }
+
+    assertBoundsCloseTo(bounds.build(), expected);
+  }
+
+  @Test
+  void mergesBoundsAcrossDisconnectedLines() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    addLine(bounds, new double[][] {{180.0, 10.0}, {170.0, 10.0}});
+    addLine(bounds, new double[][] {{20.0, 10.0}, {-150.0, 10.0}, {-180.0, 
10.0}});
+    addLine(bounds, new double[][] {{160.0, 0.0}, {40.0, 20.0}});
+
+    assertBoundsCloseTo(bounds.build(), box(40.0, 0.0, 20.0, 
63.6975136546575));
+  }
+
+  @Test
+  void coversSampledPointsAlongRandomMinorArcs() {
+    Random random = new Random(42L);
+    for (int edge = 0; edge < 2_000; edge += 1) {
+      double longitude1 = random.nextDouble() * 360.0 - 180.0;
+      double latitude1 = random.nextDouble() * 180.0 - 90.0;
+      double longitude2 = normalizeLongitude(longitude1 + random.nextDouble() 
* 360.0 - 180.0);
+      double latitude2 = random.nextDouble() * 180.0 - 90.0;
+
+      double[] point1 = toUnitVector(longitude1, latitude1);
+      double[] point2 = toUnitVector(longitude2, latitude2);
+      double centralAngle = centralAngle(longitude1, latitude1, longitude2, 
latitude2);
+      // Keep the interpolation oracle away from its near-antipodal 
singularity.
+      // Dedicated analytical cases cover the fallback threshold.
+      if (centralAngle > Math.toRadians(179.0)) {
+        continue;
+      }
+
+      SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+      bounds.addEdge(longitude1, latitude1, longitude2, latitude2);
+      BoundingBox box = bounds.build();
+
+      for (int sample = 0; sample <= 100; sample += 1) {
+        double[] point = slerp(point1, point2, sample / 100.0, centralAngle);
+        double latitude = Math.toDegrees(Math.asin(clamp(point[2], -1.0, 
1.0)));
+        double longitude = Math.toDegrees(Math.atan2(point[1], point[0]));
+
+        assertThat(latitude)
+            .as("latitude for edge %s sample %s", edge, sample)
+            .isBetween(box.min().y() - 1e-8, box.max().y() + 1e-8);
+        assertThat(longitudeIsContained(longitude, box))
+            .as("longitude for edge %s sample %s", edge, sample)
+            .isTrue();
+      }
+    }
+  }
+
+  private static Stream<Arguments> invalidCoordinates() {
+    return Stream.of(
+        Arguments.of("longitude above range", 180.1, 0.0),
+        Arguments.of("longitude below range", -180.1, 0.0),
+        Arguments.of("latitude above range", 0.0, 90.1),
+        Arguments.of("latitude below range", 0.0, -90.1),
+        Arguments.of("infinite longitude", Double.POSITIVE_INFINITY, 0.0),
+        Arguments.of("infinite latitude", 0.0, Double.NEGATIVE_INFINITY));
+  }
+
+  private static Stream<Arguments> lineBoundsCases() {
+    return Stream.of(
+        Arguments.of(
+            "ordinary polyline",
+            new double[][] {{1.0, 2.0}, {5.0, 6.0}, {-10.0, -7.0}},
+            box(-10.0, -7.0, 5.0, 6.0)),
+        Arguments.of(
+            "approaches positive antimeridian",
+            new double[][] {{180.0, 0.0}, {170.0, 0.0}},
+            box(170.0, 0.0, 180.0, 0.0)),
+        Arguments.of(
+            "crosses negative antimeridian",
+            new double[][] {{-180.0, 0.0}, {170.0, 0.0}},
+            box(170.0, 0.0, -180.0, 0.0)),
+        Arguments.of(
+            "latitude bulge near antimeridian",
+            new double[][] {{180.0, 10.0}, {170.0, 10.0}},
+            box(170.0, 10.0, 180.0, 10.0374230459107)),
+        Arguments.of(
+            "narrow antimeridian crossing",
+            new double[][] {{-179.0, 10.0}, {179.0, 10.0}},
+            box(179.0, 10.0, -179.0, 10.0014925269841)),
+        Arguments.of(
+            "edges cover every longitude",
+            new double[][] {
+              {180.0, 10.0},
+              {170.0, 10.0},
+              {20.0, 10.0},
+              {-20.0, 10.0},
+              {-160.0, 10.0},
+              {-180.0, 10.0}
+            },
+            box(-180.0, 10.0, 180.0, 34.2656315104621)),
+        Arguments.of(
+            "wide non-wrapping line",
+            new double[][] {
+              {179.0, 10.0},
+              {170.0, 10.0},
+              {20.0, 10.0},
+              {-20.0, 10.0},
+              {-160.0, 10.0},
+              {-179.0, 10.0}
+            },
+            box(-179.0, 10.0, 179.0, 34.2656315104621)),
+        Arguments.of(
+            "line touches north pole",
+            new double[][] {{10.0, 20.0}, {10.0, 90.0}, {30.0, 20.0}},
+            box(10.0, 20.0, 30.0, 90.0)),
+        Arguments.of(
+            "line stays on north pole",
+            new double[][] {{20.0, 90.0}, {10.0, 90.0}, {30.0, 90.0}},
+            box(10.0, 90.0, 30.0, 90.0)),
+        Arguments.of(
+            "line stays on south pole",
+            new double[][] {{20.0, -90.0}, {10.0, -90.0}, {30.0, -90.0}},
+            box(10.0, -90.0, 30.0, -90.0)),
+        Arguments.of(
+            "edge connects opposite poles",
+            new double[][] {{30.0, 90.0}, {10.0, -90.0}},
+            box(-180.0, -90.0, 180.0, 90.0)),
+        Arguments.of(
+            "line visits both poles",
+            new double[][] {{10.0, 90.0}, {10.0, 0.0}, {10.0, -90.0}, {20.0, 
0.0}, {20.0, 90.0}},
+            box(10.0, -90.0, 20.0, 90.0)));
+  }
+
+  private static Stream<Arguments> edgeBoundsCases() {
+    return Stream.concat(antimeridianEdgeBoundsCases(), 
latitudeEdgeBoundsCases());
+  }
+
+  private static Stream<Arguments> antimeridianEdgeBoundsCases() {
+    return Stream.of(
+        edgeCase(5.0, 10.0, 15.0, 10.0, 5.0, 10.0, 15.0, 10.0374230459107),
+        edgeCase(5.0, -10.0, 15.0, -10.0, 5.0, -10.0374230459107, 15.0, -10.0),
+        edgeCase(5.0, 10.0, -179.0, 10.0, 5.0, 10.0, -179.0, 78.8044356595847),
+        edgeCase(5.0, 10.0, -175.1, 10.0, 5.0, 10.0, -175.1, 89.7164382601682),
+        edgeCase(5.0, 10.0, 105.0, -10.0, 5.0, -10.0, 105.0, 10.0),
+        edgeCase(5.0, 10.0, 25.0, 10.0, 5.0, 10.0, 25.0, 10.1510817110481),
+        edgeCase(5.0, -10.0, 25.0, -10.0, 5.0, -10.1510817110481, 25.0, -10.0),
+        edgeCase(-170.0, 10.0, 160.0, 10.0, 160.0, 10.0, -170.0, 
10.34527004615),
+        edgeCase(-170.0, -10.0, 160.0, -10.0, 160.0, -10.34527004615, -170.0, 
-10.0),
+        edgeCase(-180.0, 10.0, -170.0, 10.0, -180.0, 10.0, -170.0, 
10.0374230459107),
+        edgeCase(180.0, 10.0, 170.0, 10.0, 170.0, 10.0, 180.0, 
10.0374230459107),
+        edgeCase(180.0, 10.0, 180.0, 5.0, 180.0, 5.0, 180.0, 10.0),
+        edgeCase(-180.0, 10.0, -180.0, 5.0, -180.0, 5.0, -180.0, 10.0),
+        edgeCase(10.0, 90.0, 20.0, 90.0, 10.0, 90.0, 20.0, 90.0),
+        edgeCase(10.0, -90.0, 20.0, -90.0, 10.0, -90.0, 20.0, -90.0));
+  }
+
+  private static Stream<Arguments> latitudeEdgeBoundsCases() {
+    return Stream.of(
+        edgeCase(10.0, 90.0, 20.0, -90.0, -180.0, -90.0, 180.0, 90.0),
+        edgeCase(10.0, 90.0, 10.0, -90.0, -180.0, -90.0, 180.0, 90.0),
+        edgeCase(10.0, -0.1, 100.0, 1.0, 10.0, -0.1, 100.0, 1.0),
+        edgeCase(10.0, -1.0, 100.0, 1.0, 10.0, -1.0, 100.0, 1.0),
+        edgeCase(10.0, 0.0, 120.0, 0.0, 10.0, 0.0, 120.0, 0.0),
+        edgeCase(10.0, 0.0, 120.0, 1.0, 10.0, 0.0, 120.0, 1.06416345908854),
+        edgeCase(10.0, 10.0, 20.0, 20.0, 10.0, 10.0, 20.0, 20.0),
+        edgeCase(10.0, 60.0, 70.0, 70.0, 10.0, 60.0, 70.0, 70.2055784851265),
+        edgeCase(10.0, 10.0, 80.0, 20.0, 10.0, 10.0, 80.0, 20.210054644153),
+        edgeCase(5.0, 10.0, 105.0, 10.0, 5.0, 10.0, 105.0, 15.339814499188),
+        edgeCase(5.0, 10.0, 175.0, 10.0, 5.0, 10.0, 175.0, 63.6975136546575),
+        edgeCase(10.0, 20.0, 10.0, 90.0, 10.0, 20.0, 10.0, 90.0),
+        edgeCase(10.0, 20.0, 10.0, -90.0, 10.0, -90.0, 10.0, 20.0),
+        edgeCase(10.0, -20.0, -10.0, 90.0, -10.0, -20.0, 10.0, 90.0),
+        edgeCase(10.0, -20.0, -10.0, -90.0, -10.0, -90.0, 10.0, -20.0));
+  }
+
+  private static Stream<Arguments> pointBoundsCases() {
+    return Stream.of(
+        Arguments.of(
+            "ordinary points",
+            new double[][] {{1.0, 2.0}, {5.0, 6.0}, {-10.0, -7.0}},
+            box(-10.0, -7.0, 5.0, 6.0)),
+        Arguments.of(
+            "points approach positive antimeridian",
+            new double[][] {{180.0, 0.0}, {170.0, 0.0}},
+            box(170.0, 0.0, 180.0, 0.0)),
+        Arguments.of(
+            "points cross negative antimeridian",
+            new double[][] {{-180.0, 0.0}, {170.0, 0.0}},
+            box(170.0, 0.0, -180.0, 0.0)),
+        Arguments.of(
+            "point set wraps around antimeridian",
+            new double[][] {
+              {180.0, 10.0}, {170.0, 10.0}, {20.0, 10.0}, {-160.0, 10.0}, 
{-180.0, 10.0}
+            },
+            box(20.0, 10.0, -160.0, 10.0)),
+        Arguments.of(
+            "point set excludes its largest circular gap",
+            new double[][] {
+              {179.0, 10.0},
+              {170.0, 10.0},
+              {20.0, 10.0},
+              {-20.0, 10.0},
+              {-160.0, 10.0},
+              {-179.0, 10.0}
+            },
+            box(170.0, 10.0, 20.0, 10.0)),
+        Arguments.of(
+            "points stay on north pole",
+            new double[][] {{20.0, 90.0}, {10.0, 90.0}, {30.0, 90.0}},
+            box(10.0, 90.0, 30.0, 90.0)),
+        Arguments.of(
+            "points include both poles",
+            new double[][] {{10.0, 90.0}, {30.0, -90.0}},
+            box(10.0, -90.0, 30.0, 90.0)),
+        Arguments.of(
+            "pole longitudes do not widen finite points",
+            new double[][] {{10.0, 90.0}, {10.0, 0.0}, {10.0, -90.0}, {20.0, 
0.0}, {20.0, 90.0}},
+            box(10.0, -90.0, 20.0, 90.0)));
+  }
+
+  private static void addLine(SphericalGeographyBoundsBuilder bounds, 
double[][] points) {
+    if (points.length == 1) {
+      bounds.addPoint(points[0][0], points[0][1]);
+      return;
+    }
+
+    for (int index = 1; index < points.length; index += 1) {
+      double[] start = points[index - 1];
+      double[] end = points[index];
+      bounds.addEdge(start[0], start[1], end[0], end[1]);
+    }
+  }
+
+  private static void assertBoundsCloseTo(BoundingBox actual, BoundingBox 
expected) {
+    assertThat(actual).isNotNull();
+    assertThat(actual.min().x()).isEqualTo(expected.min().x());
+    assertThat(actual.max().x()).isEqualTo(expected.max().x());
+    // Latitude extrema are conservatively widened, so assert coverage rather 
than exact values.
+    assertThat(actual.min().y()).isLessThanOrEqualTo(expected.min().y() + 
LATITUDE_TOLERANCE);
+    assertThat(actual.max().y()).isGreaterThanOrEqualTo(expected.max().y() - 
LATITUDE_TOLERANCE);

Review Comment:
   nit: these only assert coverage, so returning `[-90, 90]` for every 
edge/line case would still pass this helper. could we also cap how much wider 
than `expected` the latitude bounds are allowed to be (e.g. within 1e-4)?



##########
core/src/test/java/org/apache/iceberg/TestSphericalGeographyBoundsBuilder.java:
##########
@@ -0,0 +1,701 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Random;
+import java.util.stream.Stream;
+import org.apache.iceberg.geospatial.BoundingBox;
+import org.apache.iceberg.geospatial.GeospatialBound;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.ValueSource;
+
+class TestSphericalGeographyBoundsBuilder {
+  private static final double LATITUDE_TOLERANCE = 1e-9;
+  private static final double LONGITUDE_TOLERANCE = 1e-9;
+
+  @Test
+  void capturesInteriorNorthernLatitudeExtremum() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, 60.0, 90.0, 60.0);
+
+    double midpointLatitude =
+        Math.toDegrees(Math.atan(Math.tan(Math.toRadians(60.0)) / 
Math.cos(Math.PI / 4.0)));
+    BoundingBox box = bounds.build();
+    assertThat(box.min()).isEqualTo(GeospatialBound.createXY(0.0, 60.0));
+    assertThat(box.max().x()).isEqualTo(90.0);
+    
assertThat(box.max().y()).isGreaterThanOrEqualTo(midpointLatitude).isLessThan(67.793);
+  }
+
+  @Test
+  void capturesInteriorSouthernLatitudeExtremum() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, -60.0, 90.0, -60.0);
+
+    double midpointLatitude =
+        Math.toDegrees(Math.atan(Math.tan(Math.toRadians(-60.0)) / 
Math.cos(Math.PI / 4.0)));
+    BoundingBox box = bounds.build();
+    assertThat(box.min().x()).isEqualTo(0.0);
+    
assertThat(box.min().y()).isLessThanOrEqualTo(midpointLatitude).isGreaterThan(-67.793);
+    assertThat(box.max()).isEqualTo(GeospatialBound.createXY(90.0, -60.0));
+  }
+
+  @Test
+  void doesNotExpandEndpointLatitude() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(20.0, 10.0, 20.0, 80.0);
+
+    BoundingBox box = bounds.build();
+    assertThat(box.min()).isEqualTo(GeospatialBound.createXY(20.0, 10.0));
+    assertThat(box.max()).isEqualTo(GeospatialBound.createXY(20.0, 80.0));
+  }
+
+  @Test
+  void representsAntimeridianCrossingAsWrappedInterval() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(170.0, 5.0, -170.0, 8.0);
+
+    BoundingBox box = bounds.build();
+    assertThat(box.min().x()).isEqualTo(170.0);
+    assertThat(box.max().x()).isEqualTo(-170.0);
+    assertThat(box.min().x()).isGreaterThan(box.max().x());
+  }
+
+  @Test
+  void mergesIntervalsRatherThanOnlyEndpoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(100.0, 0.0, -100.0, 0.0);
+    bounds.addEdge(-10.0, 0.0, 10.0, 0.0);
+
+    BoundingBox box = bounds.build();
+    assertThat(longitudeIsContained(180.0, box)).isTrue();
+    assertThat(longitudeIsContained(0.0, box)).isTrue();
+    assertThat(longitudeIsContained(50.0, box)).isTrue();
+    assertThat(longitudeIsContained(-50.0, box)).isFalse();
+  }
+
+  @Test
+  void includesPoleLongitudeWithFinitePoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addPoint(-120.0, 90.0);
+    bounds.addPoint(40.0, 10.0);
+
+    BoundingBox box = bounds.build();
+    assertThat(box.min()).isEqualTo(GeospatialBound.createXY(-120.0, 10.0));
+    assertThat(box.max()).isEqualTo(GeospatialBound.createXY(40.0, 90.0));
+  }
+
+  @Test
+  void usesStoredLongitudeForPoleOnlyBounds() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addPoint(10.0, 90.0);
+    bounds.addPoint(-50.0, 90.0);
+
+    assertThat(bounds.build())
+        .isEqualTo(
+            new BoundingBox(
+                GeospatialBound.createXY(-50.0, 90.0), 
GeospatialBound.createXY(10.0, 90.0)));
+  }
+
+  @Test
+  void usesFullWorldForOppositePoles() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, -90.0, 30.0, 90.0);
+
+    assertThat(bounds.build())
+        .isEqualTo(
+            new BoundingBox(
+                GeospatialBound.createXY(-180.0, -90.0), 
GeospatialBound.createXY(180.0, 90.0)));
+  }
+
+  @Test
+  void usesFullWorldForAntipodalEndpoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, 0.0, 180.0, 0.0);
+
+    assertThat(bounds.build())
+        .isEqualTo(
+            new BoundingBox(
+                GeospatialBound.createXY(-180.0, -90.0), 
GeospatialBound.createXY(180.0, 90.0)));
+  }
+
+  @Test
+  void treatsCoincidentEndpointsAsAPoint() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(12.0, 34.0, 12.0, 34.0);
+
+    assertThat(bounds.build())
+        .isEqualTo(
+            new BoundingBox(
+                GeospatialBound.createXY(12.0, 34.0), 
GeospatialBound.createXY(12.0, 34.0)));
+  }
+
+  @Test
+  void preservesBothStoredAntimeridianLongitudesForCoincidentEndpoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(-180.0, 30.0, 180.0, 30.0);
+
+    assertThat(bounds.build()).isEqualTo(box(180.0, 30.0, -180.0, 30.0));
+  }
+
+  @Test
+  void coversPoleBetweenNearlyCoincidentEndpoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    double latitude = Math.nextDown(90.0);
+    bounds.addEdge(0.0, latitude, 180.0, latitude);
+
+    BoundingBox box = bounds.build();
+    assertThat(box.min().y()).isLessThanOrEqualTo(latitude);
+    assertThat(box.max().y()).isEqualTo(90.0);
+    assertThat(box.min().x()).isEqualTo(-180.0);
+    assertThat(box.max().x()).isEqualTo(180.0);
+  }
+
+  @ParameterizedTest
+  @ValueSource(doubles = {60.0, -60.0, 1e-4, -1e-4})
+  void coversPoleInsideResolvedMinorArc(double latitude) {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, latitude, 180.0, latitude);
+    double south = latitude < 0.0 ? -90.0 : latitude;
+    double north = latitude > 0.0 ? 90.0 : latitude;
+
+    assertThat(bounds.build()).isEqualTo(box(-180.0, south, 180.0, north));
+  }
+
+  @Test
+  void coversPoleWhenLongitudeDifferenceRoundsTo180() {
+    // In binary64, 134.3 - (-45.7) rounds to 180, but the true difference is 
slightly larger.
+    // The minor arc passes near the North Pole at about -135.7, outside 
[-45.7, 134.3].
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(-45.7, 60.0, 134.3, 60.0);
+
+    assertThat(bounds.build()).isEqualTo(box(-180.0, 60.0, 180.0, 90.0));
+  }
+
+  @Test
+  void boundsShortEdgesWithoutFallingBackToWorld() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, 60.0, 1e-7, 60.0);
+
+    BoundingBox box = bounds.build();
+    assertThat(box.min().x()).isEqualTo(0.0);
+    assertThat(box.max().x()).isEqualTo(1e-7);
+    assertThat(box.min().y()).isBetween(59.999, 60.0);
+    assertThat(box.max().y()).isBetween(60.0, 60.001);
+  }
+
+  @Test
+  void coversNearlyEquatorialLatitudeExtremum() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    double latitude = 1e-10;
+    bounds.addEdge(-45.0, latitude, 45.0, latitude);
+
+    // The midpoint is the northern vertex for endpoints symmetric about the 
prime meridian.
+    double midpointLatitude =
+        Math.toDegrees(Math.atan(Math.tan(Math.toRadians(latitude)) / 
Math.cos(Math.PI / 4.0)));
+    BoundingBox box = bounds.build();
+    assertThat(box.min().y()).isEqualTo(latitude);
+    
assertThat(box.max().y()).isGreaterThanOrEqualTo(midpointLatitude).isLessThan(1e-5);
+  }
+
+  @ParameterizedTest
+  @ValueSource(doubles = {40.44773051160679, -40.44773051160679})
+  void coversInteriorExtremumRoundedBelowEndpoint(double latitude) {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    double longitude1 = 39.99170103009482;
+    double longitude2 = 39.992335550082764;
+    bounds.addEdge(longitude1, latitude, longitude2, latitude);
+
+    // Equal-latitude endpoints reach their latitude extremum at the arc 
midpoint.
+    double halfLongitudeSpan = Math.toRadians((longitude2 - longitude1) / 2.0);
+    double midpointLatitude =
+        Math.toDegrees(Math.atan(Math.tan(Math.toRadians(latitude)) / 
Math.cos(halfLongitudeSpan)));
+    BoundingBox box = bounds.build();
+    assertThat(box.min().y()).isLessThanOrEqualTo(Math.min(latitude, 
midpointLatitude));
+    assertThat(box.max().y()).isGreaterThanOrEqualTo(Math.max(latitude, 
midpointLatitude));
+    assertThat(box.min().y()).isGreaterThan(latitude - 1e-4);
+    assertThat(box.max().y()).isLessThan(latitude + 1e-4);
+  }
+
+  @Test
+  void usesFullWorldForNearlyAntipodalEndpoints() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(0.0, 10.0, 180.0 - 1e-7, -10.0);
+
+    assertThat(bounds.build()).isEqualTo(box(-180.0, -90.0, 180.0, 90.0));
+  }
+
+  @ParameterizedTest
+  @ValueSource(doubles = {2e-5, -2e-5})
+  void usesFullWorldBelowAntipodalFallbackThreshold(double latitude) {
+    // The cross-product length is about 0.987e-6, just below the 1e-6 
fallback threshold.
+    double longitude = 90.0 - Math.abs(latitude);
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(-longitude, latitude, longitude, latitude);
+
+    assertThat(bounds.build()).isEqualTo(box(-180.0, -90.0, 180.0, 90.0));
+  }
+
+  @ParameterizedTest
+  @ValueSource(doubles = {2.1e-5, -2.1e-5})
+  void boundsNearlyAntipodalEdgesAboveFallbackThreshold(double latitude) {
+    // The cross-product length is about 1.037e-6, just above the 1e-6 
fallback threshold.
+    double longitude = 90.0 - Math.abs(latitude);
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addEdge(-longitude, latitude, longitude, latitude);
+
+    // Symmetric endpoints reach their extremum at the midpoint. Use sin of 
the complement
+    // instead of cos near pi/2 to avoid cancellation in this independent 
expected value.
+    double midpointLatitude =
+        Math.toDegrees(
+            Math.atan2(
+                Math.tan(Math.toRadians(latitude)), 
Math.sin(Math.toRadians(90.0 - longitude))));
+    double south = Math.min(latitude, midpointLatitude);
+    double north = Math.max(latitude, midpointLatitude);
+    BoundingBox box = bounds.build();
+    assertThat(box.min().x()).isEqualTo(-longitude);
+    assertThat(box.max().x()).isEqualTo(longitude);
+    assertThat(box.min().y()).isBetween(south - 1e-5, south);
+    assertThat(box.max().y()).isBetween(north, north + 1e-5);
+  }
+
+  @Test
+  void explicitlyIncludesWorld() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addWorld();
+
+    assertThat(bounds.build()).isEqualTo(box(-180.0, -90.0, 180.0, 90.0));
+  }
+
+  @Test
+  void worldFallbackDoesNotRestoreInvalidBounds() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addPoint(181.0, 0.0);
+    bounds.addWorld();
+
+    assertThat(bounds.build()).isNull();
+  }
+
+  @Test
+  void invalidCoordinateSuppressesWorldBounds() {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addWorld();
+    bounds.addPoint(0.0, 91.0);
+
+    assertThat(bounds.build()).isNull();
+  }
+
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("invalidCoordinates")
+  void invalidCoordinateSuppressesBounds(String description, double longitude, 
double latitude) {
+    SphericalGeographyBoundsBuilder bounds = new 
SphericalGeographyBoundsBuilder();
+    bounds.addPoint(0.0, 0.0);
+    bounds.addPoint(longitude, latitude);
+
+    assertThat(bounds.build()).isNull();

Review Comment:
   this stops right after the invalid input, so it doesn't verify that later 
valid points or edges stay suppressed. could we extend it?
   
   ```diff
    assertThat(bounds.build()).isNull();
   +
   +bounds.addPoint(10.0, 10.0);
   +bounds.addEdge(0.0, 0.0, 20.0, 20.0);
   +assertThat(bounds.build()).isNull();
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to