Skip to content

Commit be0b149

Browse files
michaelkirkdabreegster
authored andcommitted
update to latest (not yet released) geo
NOTE: the test fixture changes appear to be due to georust/geo#1310, which reversed the Polygon winding on the output from geo::boolean_operations. Now the exterior is wound counter-clockwise and the interior clockwise. This output convention matches what's used elsewhere in geo and also in the geojson spec. In practice many tools are tolerant of both, but it's probably better to follow convention here.
1 parent de1d2a9 commit be0b149

13 files changed

+30
-33
lines changed

backend/Cargo.lock

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/src/cells.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn floodfill(map: &MapModel, start: RoadID, neighbourhood: &Neighbourhood) -> Ce
140140
if interval.start == 0.0 {
141141
visited_start = true;
142142
}
143-
if interval.end == next_road.linestring.length::<Euclidean>() {
143+
if interval.end == Euclidean.length(&next_road.linestring) {
144144
visited_end = true;
145145
}
146146
}

backend/src/geo_helpers/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ pub fn bearing_from_endpoint(endpoint: Point, linestring: &LineString) -> f64 {
141141
pub fn angle_of_pt_on_line(linestring: &LineString, pt: Coord) -> f64 {
142142
let line = linestring
143143
.lines()
144-
.min_by_key(|line| (Euclidean::distance(line, pt) * 10e9) as usize)
144+
.min_by_key(|line| (Euclidean.distance(line, pt) * 10e9) as usize)
145145
.unwrap();
146146
angle_of_line(line)
147147
}
@@ -193,7 +193,7 @@ pub fn make_arrow(line: Line, thickness: f64, double_ended: bool) -> Option<Poly
193193
let head_size = thickness * 2.0;
194194
let triangle_height = head_size / 2.0_f64.sqrt();
195195
let angle = angle_of_line(line);
196-
let length = line.length::<Euclidean>();
196+
let length = Euclidean.length(&line);
197197

198198
if length < triangle_height * 3.0 {
199199
return None;

backend/src/geo_helpers/slice_nearest_boundary.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl SliceNearestFrechetBoundary for Polygon {
7070
let mut segment_idx_closest_to_final = 0;
7171
let mut coord_closest_to_final = coord!(x: 0., y: 0.);
7272
for (segment_idx, segment) in exterior.lines().enumerate() {
73-
let new_first_distance = Euclidean::distance(&segment, first_coord);
73+
let new_first_distance = Euclidean.distance(&segment, first_coord);
7474
if new_first_distance < distance_to_first {
7575
distance_to_first = new_first_distance;
7676
segment_idx_closest_to_first = segment_idx;
@@ -86,7 +86,7 @@ impl SliceNearestFrechetBoundary for Polygon {
8686
};
8787
}
8888

89-
let new_final_distance = Euclidean::distance(&segment, final_coord);
89+
let new_final_distance = Euclidean.distance(&segment, final_coord);
9090
if new_final_distance < distance_to_final {
9191
distance_to_final = new_final_distance;
9292
segment_idx_closest_to_final = segment_idx;

backend/src/map_model.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use crate::impact::Impact;
99
use crate::Router;
1010
use anyhow::Result;
1111
use geo::{
12-
Closest, ClosestPoint, Coord, Euclidean, Length, Line, LineInterpolatePoint, LineLocatePoint,
13-
LineString, Point, Polygon,
12+
Closest, ClosestPoint, Coord, Distance, Euclidean, Length, LineInterpolatePoint,
13+
LineLocatePoint, LineString, Point, Polygon,
1414
};
1515
use geojson::{Feature, FeatureCollection, GeoJson, Geometry, JsonValue};
1616
use rstar::{primitives::GeomWithData, RTree, AABB};
@@ -212,7 +212,7 @@ impl MapModel {
212212
Closest::SinglePoint(pt) => Some(pt),
213213
Closest::Indeterminate => None,
214214
} {
215-
let score = Line::new(click_pt, hit_pt.into()).length::<Euclidean>();
215+
let score = Euclidean.distance(click_pt, hit_pt.0);
216216
let percent_along = road.linestring.line_locate_point(&hit_pt).unwrap();
217217
Some(((score * 100.0) as usize, road.id, percent_along))
218218
} else {
@@ -229,16 +229,14 @@ impl MapModel {
229229
self.roads
230230
.iter()
231231
.min_by_key(|r| {
232-
let diff1 = Line::new(
232+
let diff1 = Euclidean.distance(
233233
r.linestring.points().next().unwrap(),
234234
linestring.points().next().unwrap(),
235-
)
236-
.length::<Euclidean>();
237-
let diff2 = Line::new(
235+
);
236+
let diff2 = Euclidean.distance(
238237
r.linestring.points().last().unwrap(),
239238
linestring.points().last().unwrap(),
240-
)
241-
.length::<Euclidean>();
239+
);
242240
((diff1 + diff2) * 100.0) as usize
243241
})
244242
.unwrap()
@@ -703,7 +701,7 @@ impl MapModel {
703701
impl Road {
704702
// How long does it take for a car following the speed limit to cross this road?
705703
pub fn cost_seconds(&self) -> f64 {
706-
let meters = self.linestring.length::<Euclidean>();
704+
let meters = Euclidean.length(&self.linestring);
707705
let meters_per_second = (self.speed_mph as f64) * 0.44704;
708706
meters / meters_per_second
709707
}

backend/src/movements.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn render_arrow(i: IntersectionID, road1: &Road, road2: &Road) -> Polygon {
6969
fn pt_near_intersection(i: IntersectionID, road: &Road) -> Point {
7070
// If the road is long enough, offset from the intersection this much
7171
let distance_away = 10.0;
72-
let len = road.linestring.length::<Euclidean>();
72+
let len = Euclidean.length(&road.linestring);
7373

7474
if len > distance_away {
7575
let pct = if road.src_i == i {

backend/src/neighbourhood.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,11 @@ fn line_in_polygon(
344344
let mut sum = 0.0;
345345
// TODO: update this to use i_overlay impl
346346
for clipped in clip_linestring_to_polygon(linestring, polygon) {
347-
sum += clipped.length::<Euclidean>();
347+
sum += Euclidean.length(&clipped);
348348
}
349349
// How much of the clipped linestring is inside the boundary? If it's nearly 1, then this
350350
// road is interior.
351-
let ratio_inside = sum / linestring.length::<Euclidean>();
351+
let ratio_inside = sum / Euclidean.length(linestring);
352352
if ratio_inside > 0.99 {
353353
LineInPolygon::Inside
354354
} else if ratio_inside < 0.01 {

backend/src/render_cells.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl RenderCells {
5757
let road = map.get_r(*r);
5858
let slice = slice_linestring(&road.linestring, interval.start, interval.end);
5959
// Walk along the center line
60-
for pt in slice.densify::<Euclidean>(RESOLUTION_M / 2.0).0 {
60+
for pt in Euclidean.densify(&slice, RESOLUTION_M / 2.0).0 {
6161
let grid_idx = grid.idx(
6262
((pt.x - bounds.min().x) / RESOLUTION_M) as usize,
6363
((pt.y - bounds.min().y) / RESOLUTION_M) as usize,
@@ -90,9 +90,8 @@ impl RenderCells {
9090
// the area. The grid covers the rectangular bounds of the polygon. Rather than make an
9191
// enum with 3 cases, just assign a new index to mean "boundary."
9292
let boundary_marker = cells.len();
93-
for pt in boundary_polygon
94-
.exterior()
95-
.densify::<Euclidean>(RESOLUTION_M / 2.0)
93+
for pt in Euclidean
94+
.densify(boundary_polygon.exterior(), RESOLUTION_M / 2.0)
9695
.0
9796
{
9897
// TODO Refactor helpers to transform between map-space and the grid tiles. Possibly

backend/src/route.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl Route {
171171
let mut time = 0.0;
172172
for (r, _) in &self.steps {
173173
let road = &map.roads[r.0];
174-
distance += road.linestring.length::<Euclidean>();
174+
distance += Euclidean.length(&road.linestring);
175175
time += road.cost_seconds();
176176
}
177177
(distance, time)

backend/src/shortcuts.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl Shortcuts {
6969
let road = map.find_edge(i1, i2);
7070
steps.push((road.id, i1, i2));
7171
*count_per_road.entry(road.id).or_insert(0) += 1;
72-
shortcut_length += road.linestring.length::<Euclidean>();
72+
shortcut_length += Euclidean.length(&road.linestring);
7373
}
7474

7575
// How long is the shortest route through the original router, using this
@@ -79,7 +79,7 @@ impl Shortcuts {
7979
map.get_i(*start).point.into(),
8080
map.get_i(*end).point.into(),
8181
) {
82-
Some(route) => route.to_linestring(map).length::<Euclidean>(),
82+
Some(route) => Euclidean.length(&route.to_linestring(map)),
8383
None => {
8484
warn!("Found a shortcut from {start} to {end}, but not a route using the whole map");
8585
shortcut_length
@@ -123,7 +123,7 @@ impl Path {
123123
}
124124
let linestring = LineString::new(pts);
125125

126-
let length = linestring.length::<Euclidean>();
126+
let length = Euclidean.length(&linestring);
127127
let mut f = map.mercator.to_wgs84_gj(&linestring);
128128
f.set_property("directness", self.directness);
129129
f.set_property("length_meters", length);

tests/output/bristol_east.geojson

+1-1
Large diffs are not rendered by default.

tests/output/bristol_west.geojson

+1-1
Large diffs are not rendered by default.

tests/output/strasbourg.geojson

+1-1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)