From 4c7e1446c9db4fb076f7e73c5885d96dd7d00a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristram=20Gr=C3=A4bener?= Date: Sun, 1 Dec 2024 14:24:53 +0100 Subject: [PATCH] core: bump geo to 0.29 and fix deprecation warings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tristram Gräbener --- Cargo.lock | 78 ++++++++++++++++++++++++++++++++++++++++++++++---- Cargo.toml | 2 +- src/builder.rs | 4 +-- src/curves.rs | 48 ++++++++++++++++--------------- 4 files changed, 100 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 62bb25a..a7c5766 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -294,14 +294,15 @@ dependencies = [ [[package]] name = "geo" -version = "0.28.0" +version = "0.29.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f811f663912a69249fa620dcd2a005db7254529da2d8a0b23942e81f47084501" +checksum = "009245d261b86621c38d1c4e5a6578d52294e3e5445401d713584dfe42f8ae9c" dependencies = [ "earcutr", "float_next_after", "geo-types", "geographiclib-rs", + "i_overlay", "log", "num-traits", "robust", @@ -311,12 +312,13 @@ dependencies = [ [[package]] name = "geo-types" -version = "0.7.13" +version = "0.7.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ff16065e5720f376fbced200a5ae0f47ace85fd70b7e54269790281353b6d61" +checksum = "b6f47c611187777bbca61ea7aba780213f5f3441fd36294ab333e96cfa791b65" dependencies = [ "approx", "num-traits", + "rayon", "rstar", "serde", ] @@ -371,6 +373,50 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "i_float" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5fe043aae28ce70bd2f78b2f5f82a3654d63607c82594da4dabb8b6cb81f2b2" +dependencies = [ + "serde", +] + +[[package]] +name = "i_key_sort" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "347c253b4748a1a28baf94c9ce133b6b166f08573157e05afe718812bc599fcd" + +[[package]] +name = "i_overlay" +version = "1.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1d5024b4346ff4699e2db65674bbcb3a7cb8c5a820e9745ec777a7cb2bb5f42" +dependencies = [ + "i_float", + "i_key_sort", + "i_shape", + "i_tree", + "rayon", +] + +[[package]] +name = "i_shape" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b44852d57a991c7dedaf76c55bc44f677f547ff899a430d29e13efd6133d7d8" +dependencies = [ + "i_float", + "serde", +] + +[[package]] +name = "i_tree" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "155181bc97d770181cf9477da51218a19ee92a8e5be642e796661aee2b601139" + [[package]] name = "indoc" version = "2.0.5" @@ -653,6 +699,26 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + [[package]] name = "robust" version = "1.1.0" @@ -737,9 +803,9 @@ dependencies = [ [[package]] name = "spade" -version = "2.6.0" +version = "2.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61addf9117b11d1f5b4bf6fe94242ba25f59d2d4b2080544b771bd647024fd00" +checksum = "93f5ef1f863aca7d1d7dda7ccfc36a0a4279bd6d3c375176e5e0712e25cb4889" dependencies = [ "hashbrown", "num-traits", diff --git a/Cargo.toml b/Cargo.toml index bfb5d76..59beffa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ path = "src/geometry_from_osm.rs" [dependencies] approx = "0.5.1" flatbuffers = "24.3" -geo = "0.28" +geo = "0.29" thiserror = "2.0" osm4routing = "0.7.0" clap = { version = "4.5", features = ["derive"] } diff --git a/src/builder.rs b/src/builder.rs index 82ba1aa..a444ea9 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -5,7 +5,7 @@ use std::collections::HashMap; use std::path::{Path, PathBuf}; use flatbuffers::{ForwardsUOffset, Vector, WIPOffset}; -use geo::Coord; +use geo::{Coord, Distance}; use crate::curves::{Curve, CurveError, CurveProjection, SphericalLineStringCurve}; @@ -489,7 +489,7 @@ impl<'fbb> Builder<'fbb> { pub fn euclidean_distance(&self, lrm_index_a: usize, lrm_index_b: usize) -> f64 { let a = &self.temp_traversal[lrm_index_a].curve.geom; let b = &self.temp_traversal[lrm_index_b].curve.geom; - geo::EuclideanDistance::euclidean_distance(a, b) + geo::Euclidean::distance(a, b) } /// Returns the position along the curve of the traversal diff --git a/src/curves.rs b/src/curves.rs index deab8c6..9dd58b7 100644 --- a/src/curves.rs +++ b/src/curves.rs @@ -101,7 +101,7 @@ pub struct PlanarLineStringCurve { impl Curve for PlanarLineStringCurve { fn new(geom: LineString, max_extent: f64) -> Self { - let length = geom.euclidean_length(); + let length = geom.length::(); Self { max_extent, geom, @@ -144,7 +144,7 @@ impl Curve for PlanarLineStringCurve { Orientation::Clockwise => 1., _ => -1., }; - let offset = point.euclidean_distance(&self.geom) * sign; + let offset = Euclidean::distance(&self.geom, &point) * sign; Ok(CurveProjection { distance_along_curve, @@ -204,7 +204,7 @@ impl Curve for PlanarLineStringCurve { let line = self .geom .lines_iter() - .find(|line| line.euclidean_distance(&point) < self.length / 1e9) + .find(|line| Euclidean::distance(line, &point) < self.length / 1e9) .ok_or(CurveError::NotFiniteCoordinates)?; // translate to (0, 0) and normalize by the length of the curve to get unit vector of tangent @@ -238,7 +238,7 @@ impl Curve for PlanarLineStringCurve { let mut points = Vec::new(); for segment in self.geom.lines() { - let length = segment.euclidean_length(); + let length = segment.length::(); if cum_length + length >= start_fractional_length && points.is_empty() { let segment_fraction = (start_fractional_length - cum_length) / length; match segment.line_interpolate_point(segment_fraction) { @@ -317,8 +317,8 @@ impl SphericalLineStringCurve { let mut closest_dist_to_point = f64::infinity(); let mut fraction = 0.0; for segment in self.geom.lines() { - let segment_distance_to_point = segment.euclidean_distance(p); - let segment_length = segment.geodesic_length(); + let segment_distance_to_point = Euclidean::distance(&segment, p); + let segment_length = segment.length::(); let segment_fraction = segment.line_locate_point(p)?; // if any segment has a None fraction, return None if segment_distance_to_point < closest_dist_to_point { closest_dist_to_point = segment_distance_to_point; @@ -336,7 +336,7 @@ impl SphericalLineStringCurve { let fractional_length = total_length * fraction; let mut cum_length = f64::zero(); for segment in self.geom.lines() { - let length = segment.geodesic_length(); + let length = segment.length::(); if cum_length + length >= fractional_length { let segment_fraction = (fractional_length - cum_length) / length; return segment.line_interpolate_point(segment_fraction); @@ -363,7 +363,7 @@ impl SphericalLineStringCurve { impl Curve for SphericalLineStringCurve { fn new(geom: LineString, max_extent: f64) -> Self { - let length = geom.geodesic_length(); + let length = geom.length::(); Self { max_extent, geom, @@ -408,7 +408,7 @@ impl Curve for SphericalLineStringCurve { Orientation::Clockwise => 1., _ => -1., }; - let offset = projected_coords.geodesic_distance(&point) * sign; + let offset = Geodesic::distance(projected_coords, point) * sign; Ok(CurveProjection { distance_along_curve, @@ -431,7 +431,7 @@ impl Curve for SphericalLineStringCurve { // go through each segment and look for the one that frame the distance that we seek for segment in self.geom.lines() { - let segment_length = segment.geodesic_length(); + let segment_length = segment.length::(); if accumulated_length + segment_length >= fractional_length { let segment_fraction = (fractional_length - accumulated_length) / segment_length; let segment_start = Point::from(segment.start); @@ -439,7 +439,11 @@ impl Curve for SphericalLineStringCurve { // get the Point at a geodesic distance between two Points // of a certain fraction of length on this distance - return Ok(segment_start.geodesic_intermediate(&segment_end, segment_fraction)); + return Ok(Geodesic::point_at_ratio_between( + segment_start, + segment_end, + segment_fraction, + )); } accumulated_length += segment_length; } @@ -452,14 +456,12 @@ impl Curve for SphericalLineStringCurve { let max_point = geo::Point(self.geom.bounding_rect().unwrap().max()); // add max_extend distance in South and then West direction - let min_point_extended = min_point - .geodesic_destination(180., self.max_extent) - .geodesic_destination(270., self.max_extent); + let min_point_extended = Geodesic::destination(min_point, 180., self.max_extent); + let min_point_extended = Geodesic::destination(min_point_extended, 270., self.max_extent); // add max_extend distance in North and then East direction - let max_point_extended = max_point - .geodesic_destination(0., self.max_extent) - .geodesic_destination(90., self.max_extent); + let max_point_extended = Geodesic::destination(max_point, 0., self.max_extent); + let max_point_extended = Geodesic::destination(max_point_extended, 90., self.max_extent); Rect::new(min_point_extended, max_point_extended) } @@ -469,7 +471,7 @@ impl Curve for SphericalLineStringCurve { // to get the intersection(s) closer to the real closest path. fn intersect_segment(&self, segment: Line) -> Option { self.geom - .densify_haversine(self.densify_by) + .densify::(self.densify_by) .lines() .flat_map(|curve_line| { match geo::line_intersection::line_intersection(segment, curve_line) { @@ -493,18 +495,18 @@ impl Curve for SphericalLineStringCurve { let distance_along_curve = curve_position * self.length; // go through each segment and look for the one that frame the distance that we seek let mut accumulated_length = 0.; - for segment in self.geom.densify_haversine(self.densify_by).lines() { - let segment_length = segment.geodesic_length(); + for segment in self.geom.densify::(self.densify_by).lines() { + let segment_length = segment.length::(); if accumulated_length + segment_length >= distance_along_curve { // get Points from the segment that frame the point let start = geo::Point(segment.start); let end = geo::Point(segment.end); // get bearing from start Point and end Point of the segment, and add 90° clockwise rotation to it - let normal_vector_bearing = start.geodesic_bearing(end) + 90.; + let normal_vector_bearing = Geodesic::bearing(start, end) + 90.; // get end Point from the end of the segment for the normal vector bearing value and 1m of (haversine) length - let end_normal = end.geodesic_destination(normal_vector_bearing, 1.); + let end_normal = Geodesic::destination(end, normal_vector_bearing, 1.); return Ok((end_normal.x() - end.x(), end_normal.y() - end.y())); } @@ -532,7 +534,7 @@ impl Curve for SphericalLineStringCurve { let mut points = Vec::new(); for segment in self.geom.lines() { - let length = segment.geodesic_length(); + let length = segment.length::(); if cum_length + length >= start_fractional_length && points.is_empty() { let segment_fraction = (start_fractional_length - cum_length) / length; match segment.line_interpolate_point(segment_fraction) {