prantogg commented on code in PR #1259:
URL: https://github.com/apache/sedona/pull/1259#discussion_r1506403071


##########
common/src/main/java/org/apache/sedona/common/Predicates.java:
##########
@@ -62,4 +64,82 @@ public static boolean dWithin(Geometry leftGeometry, 
Geometry rightGeometry, dou
             return leftGeometry.isWithinDistance(rightGeometry, distance);
         }
     }
+
+    /**
+     * Checks if a geometry crosses the International Date Line.
+     *
+     * @param geometry The geometry to check.
+     * @return True if the geometry crosses the Date Line, false otherwise.
+     */
+    public static boolean crossesDateLine(Geometry geometry) {
+        if (geometry == null || geometry.isEmpty()) {
+            return false;
+        }
+
+        AtomicBoolean crossesDateLine = new AtomicBoolean(false);

Review Comment:
   The `CoordinateSequenceFilter` being an anonymous inner class could not 
modify a local variable outside its filter scope unless its `final`. 
`AtomicBoolean` was a work around because final variable's cannot be modified. 
I have removed separate handling of `GeometryCollection` so I can define a 
private local variable `crossesDateLine` within the filter.



##########
common/src/main/java/org/apache/sedona/common/Predicates.java:
##########
@@ -62,4 +64,82 @@ public static boolean dWithin(Geometry leftGeometry, 
Geometry rightGeometry, dou
             return leftGeometry.isWithinDistance(rightGeometry, distance);
         }
     }
+
+    /**
+     * Checks if a geometry crosses the International Date Line.
+     *
+     * @param geometry The geometry to check.
+     * @return True if the geometry crosses the Date Line, false otherwise.
+     */
+    public static boolean crossesDateLine(Geometry geometry) {
+        if (geometry == null || geometry.isEmpty()) {
+            return false;
+        }
+
+        AtomicBoolean crossesDateLine = new AtomicBoolean(false);
+
+        CoordinateSequenceFilter filter = new CoordinateSequenceFilter() {
+            private Coordinate previous = null;
+
+            @Override
+            public void filter(CoordinateSequence seq, int i) {
+                if (i == 0) {
+                    previous = seq.getCoordinateCopy(i);
+                    return;
+                }
+
+                Coordinate current = seq.getCoordinateCopy(i);
+                if (Math.abs(current.x - previous.x) > 180) {
+                    crossesDateLine.set(true);
+                }
+
+                previous = current;
+            }
+
+            @Override
+            public boolean isDone() {
+                return crossesDateLine.get();
+            }
+
+            @Override
+            public boolean isGeometryChanged() {
+                return false;
+            }
+        };
+
+        if (geometry instanceof GeometryCollection) {

Review Comment:
   I initially wanted to make sure Every geometry within the 
`GeometryCollection` is handled separately because `crossesDateLine` should 
return true if any geometry is crossing the dateline.
   You're right, explicit handling for `GeometryCollection` was not required, 
`CoordinateSequenceFilter` is able to handle this well. Have pushed the changes.



-- 
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: issues-unsubscr...@sedona.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to