Copilot commented on code in PR #2899:
URL: https://github.com/apache/sedona/pull/2899#discussion_r3183069169


##########
common/src/main/java/org/apache/sedona/common/Functions.java:
##########
@@ -868,6 +868,27 @@ public static String asWKT(Geometry geometry) {
     return GeomUtils.getWKT(geometry);
   }
 
+  /**
+   * PostGIS-format text for a Box2D: {@code BOX(xmin ymin, xmax ymax)}. NULL 
on null input.
+   *
+   * <p>Note: not WKT (WKT has no BOX type), so this lives outside the {@code 
asWKT} family to keep
+   * that API a true geometry serializer.
+   */
+  public static String box2dAsText(Box2D box) {
+    if (box == null) {
+      return null;
+    }
+    return "BOX("
+        + box.getXMin()
+        + " "
+        + box.getYMin()
+        + ", "
+        + box.getXMax()
+        + " "
+        + box.getYMax()
+        + ")";

Review Comment:
   This formatter serializes the raw stored coordinates as `BOX(xmin ymin, xmax 
ymax)`, but `ST_MakeBox2D` already preserves swapped corner order for cases 
like `170 -> -170`. In those reachable cases the output stops being a min/max 
box string and callers get text that misrepresents the Box2D contract instead 
of a normalized or rejected bbox.
   



##########
common/src/main/java/org/apache/sedona/common/Constructors.java:
##########
@@ -289,6 +289,17 @@ public static Geometry makeEnvelope(double minX, double 
minY, double maxX, doubl
     return makeEnvelope(minX, minY, maxX, maxY, 0);
   }
 
+  /**
+   * Convert a {@link Box2D} to a closed rectangular polygon. NULL on null 
input. Mirrors PostGIS
+   * {@code box2d::geometry}.
+   */
+  public static Geometry geomFromBox2D(Box2D box) {
+    if (box == null) {
+      return null;
+    }
+    return polygonFromEnvelope(box.getXMin(), box.getYMin(), box.getXMax(), 
box.getYMax());

Review Comment:
   `ST_Box2D` can produce zero-width or zero-height boxes for valid POINT and 
axis-aligned LINESTRING inputs, but this helper always goes through 
`polygonFromEnvelope(...)`. That means `ST_GeomFromBox2D(ST_Box2D(geom))` no 
longer matches `ST_Envelope(geom)` for those geometries and returns a 
degenerate POLYGON instead of the POINT/LINESTRING envelope Sedona uses 
elsewhere.
   



-- 
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]

Reply via email to