Skip to content

Commit

Permalink
core: bump geo to 0.29 and fix deprecation warings
Browse files Browse the repository at this point in the history
Signed-off-by: Tristram Gräbener <[email protected]>
  • Loading branch information
Tristramg committed Dec 2, 2024
1 parent 797415d commit 120d503
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 32 deletions.
78 changes: 72 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
4 changes: 2 additions & 2 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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
Expand Down
48 changes: 25 additions & 23 deletions src/curves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Euclidean>();
Self {
max_extent,
geom,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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::<Euclidean>();
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) {
Expand Down Expand Up @@ -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::<Geodesic>();
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;
Expand All @@ -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::<Geodesic>();
if cum_length + length >= fractional_length {
let segment_fraction = (fractional_length - cum_length) / length;
return segment.line_interpolate_point(segment_fraction);
Expand All @@ -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::<Geodesic>();
Self {
max_extent,
geom,
Expand Down Expand Up @@ -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,
Expand All @@ -431,15 +431,19 @@ 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::<Geodesic>();
if accumulated_length + segment_length >= fractional_length {
let segment_fraction = (fractional_length - accumulated_length) / segment_length;
let segment_start = Point::from(segment.start);
let segment_end = Point::from(segment.end);

// 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;
}
Expand All @@ -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)
}
Expand All @@ -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<Point> {
self.geom
.densify_haversine(self.densify_by)
.densify::<Haversine>(self.densify_by)
.lines()
.flat_map(|curve_line| {
match geo::line_intersection::line_intersection(segment, curve_line) {
Expand All @@ -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::<Haversine>(self.densify_by).lines() {
let segment_length = segment.length::<Geodesic>();
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()));
}
Expand Down Expand Up @@ -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::<Geodesic>();
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) {
Expand Down

0 comments on commit 120d503

Please sign in to comment.