Skip to content

Commit 0114701

Browse files
committed
refactor normalizeLongitude
1 parent ebd45a9 commit 0114701

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

parquet-column/src/main/java/org/apache/parquet/column/statistics/geometry/GeospatialUtils.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ public static void normalizeLongitude(Geometry geometry) {
3434
@Override
3535
public void filter(CoordinateSequence seq, int i) {
3636
double x = seq.getX(i);
37-
// Normalize the longitude to be within -180 to 180 range
38-
while (x > 180) x -= 360;
39-
while (x < -180) x += 360;
37+
x = normalizeLongitude(x);
4038
seq.setOrdinate(i, CoordinateSequence.X, x);
4139
}
4240

@@ -53,4 +51,14 @@ public boolean isGeometryChanged() {
5351

5452
geometry.geometryChanged(); // Notify the geometry that its coordinates have been changed
5553
}
54+
55+
private static double normalizeLongitude(double lon) {
56+
if (lon >= -180.0 && lon <= 180.0) {
57+
return lon;
58+
} else if (lon > 180) {
59+
return (lon + 180.0) % 360.0 - 180.0;
60+
} else {
61+
return 180.0 - (180.0 - lon) % 360.0;
62+
}
63+
}
5664
}

0 commit comments

Comments
 (0)