This is an automated email from the ASF dual-hosted git repository.

prantogg pushed a commit to branch orient-ccw
in repository https://gitbox.apache.org/repos/asf/sedona-spatialbench.git


The following commit(s) were added to refs/heads/orient-ccw by this push:
     new 7843b7e  add wrap around logic to keep points within [-180, 180] 
degrees
7843b7e is described below

commit 7843b7ea107df0143d898891d7d7dce7bed07113
Author: Pranav Toggi <[email protected]>
AuthorDate: Thu Nov 6 16:03:54 2025 -0800

    add wrap around logic to keep points within [-180, 180] degrees
---
 spatialbench/src/generators.rs           |  4 +++-
 spatialbench/src/spatial/geometry.rs     |  3 ++-
 spatialbench/src/spatial/utils/affine.rs | 15 +++++++++++++++
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/spatialbench/src/generators.rs b/spatialbench/src/generators.rs
index 5751542..122718f 100644
--- a/spatialbench/src/generators.rs
+++ b/spatialbench/src/generators.rs
@@ -11,7 +11,7 @@ use crate::random::{RandomAlphaNumeric, 
RandomAlphaNumericInstance};
 use crate::random::{RandomBoundedInt, RandomString, RandomStringSequence, 
RandomText};
 use crate::spatial::overrides as spatial_overrides;
 use crate::spatial::utils::continent::{build_continent_cdf, WeightedTarget};
-use crate::spatial::utils::{hash_to_unit_u64, spider_seed_for_index};
+use crate::spatial::utils::{hash_to_unit_u64, spider_seed_for_index, 
wrap_around_longitude};
 use crate::spatial::{ContinentAffines, SpatialDefaults, SpatialGenerator};
 use crate::text::TextPool;
 use geo::Point;
@@ -1132,6 +1132,8 @@ impl TripGeneratorIterator {
         let angle: f64 = angle_rng.gen::<f64>() * std::f64::consts::TAU;
 
         let mut dropoff_x = pickuploc.x() + distance_value * angle.cos();
+        dropoff_x = wrap_around_longitude(dropoff_x);
+
         let mut dropoff_y = pickuploc.y() + distance_value * angle.sin();
 
         // Hard code coordinate precision to 8 decimal places - milimeter 
level precision for WGS 84
diff --git a/spatialbench/src/spatial/geometry.rs 
b/spatialbench/src/spatial/geometry.rs
index 5fb2860..a0f9aa5 100644
--- a/spatialbench/src/spatial/geometry.rs
+++ b/spatialbench/src/spatial/geometry.rs
@@ -1,4 +1,4 @@
-use crate::spatial::utils::{apply_affine, round_coordinates};
+use crate::spatial::utils::{apply_affine, round_coordinates, 
wrap_around_longitude};
 use crate::spatial::{GeomType, SpatialConfig};
 use geo::orient::Direction;
 use geo::{coord, Geometry, LineString, Orient, Point, Polygon};
@@ -24,6 +24,7 @@ pub fn emit_geom(
 
 pub fn generate_point_geom(center: (f64, f64), m: &[f64; 6]) -> Geometry {
     let (x, y) = apply_affine(center.0, center.1, m);
+    let x = wrap_around_longitude(x);
     let (x, y) = round_coordinates(x, y, GEOMETRY_PRECISION);
     Geometry::Point(Point::new(x, y))
 }
diff --git a/spatialbench/src/spatial/utils/affine.rs 
b/spatialbench/src/spatial/utils/affine.rs
index 5100cad..3e04e4a 100644
--- a/spatialbench/src/spatial/utils/affine.rs
+++ b/spatialbench/src/spatial/utils/affine.rs
@@ -15,3 +15,18 @@ pub fn round_coordinates(x: f64, y: f64, precision: f64) -> 
(f64, f64) {
         round_coordinate(y, precision),
     )
 }
+
+/// Wraps a longitude value to ensure it stays within the valid range of 
[-180, 180] degrees.
+///
+/// Longitude is a circular coordinate:
+/// - If longitude exceeds 180°, it wraps around from the eastern hemisphere 
back to the western hemisphere.
+/// - If longitude is below -180°, it wraps around from the western hemisphere 
back to the eastern hemisphere.
+pub fn wrap_around_longitude(mut lon: f64) -> f64 {
+    while lon > 180.0 {
+        lon -= 360.0;
+    }
+    while lon < -180.0 {
+        lon += 360.0;
+    }
+    lon
+}

Reply via email to