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


##########
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:
   Fixed in c8eecaf0. ST_GeomFromBox2D now dispatches on dimensionality — POINT 
for 0-D (xmin==xmax && ymin==ymax), LINESTRING for 1-D (one axis collapsed), 
POLYGON otherwise. ST_GeomFromBox2D(ST_Box2D(geom)) now matches 
ST_Envelope(geom) for points, axis-aligned lines, and 2-D geometries. Added 
unit coverage in ConstructorsTest and SQL coverage in constructorTestScala for 
all three branches.



##########
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:
   Keeping the as-stored emit semantics — but tightened the Javadoc in c8eecaf0 
to make the contract explicit. Reasoning: the rest of the Box2D API 
(ST_XMin/XMax/YMin/YMax) returns stored values, not normalized values; if 
box2dAsText normalized, text output would diverge from accessor output and 
round-trip via text would be lossy. The swapped-corner ordering is reserved for 
future antimeridian semantics on geography bboxes (cf. sedona-db 
WraparoundInterval) and was decided in #2883. Inputs that arrive swapped today 
are user error rather than a contract violation, and faithful text output is 
the right debug aid.



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