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


##########
common/src/main/java/org/apache/sedona/common/Functions.java:
##########
@@ -1681,6 +1672,30 @@ private static boolean checkIfPolygonCW(Polygon geom) {
     return isExteriorRingCW && isInteriorRingCW;
   }
 
+  /**
+   * Recursively walks a geometry's polygonal components (Polygon, 
MultiPolygon, or any nested
+   * GeometryCollection) and returns true only if every one of them satisfies 
{@code
+   * ringOrientationCheck}. Non-polygonal components (points, line strings) 
are ignored, and inputs
+   * with no polygonal components at all vacuously return true.
+   */
+  private static boolean allPolygonalComponentsMatchOrientation(
+      Geometry geom, Predicate<Polygon> ringOrientationCheck) {
+    if (geom instanceof Polygon) {
+      return ringOrientationCheck.test((Polygon) geom);
+    } else if (geom instanceof GeometryCollection) {
+      GeometryCollection collection = (GeometryCollection) geom;
+      for (int i = 0; i < collection.getNumGeometries(); i++) {
+        if (!allPolygonalComponentsMatchOrientation(
+            collection.getGeometryN(i), ringOrientationCheck)) {
+          return false;
+        }
+      }
+      return true;
+    }
+    // No polygonal component to violate the orientation for remaining 
geometry types
+    return true;

Review Comment:
   Could we keep the previous behavior for a direct Java null here? It looks 
like null misses both branches and falls through to true, so 
Functions.isPolygonCW(null) and isPolygonCCW(null) now both return true instead 
of the previous false. The SQL wrappers seem to handle null separately, but 
direct common callers can still reach this. Maybe add a null guard and a small 
common test?



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