diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 25a63a6..7a0f811 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -664,7 +664,7 @@ checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] name = "graph" version = "0.1.0" -source = "git+https://github.com/a-b-street/15m#290eb3d843bfeeeb5e27c40b08876f6bd547aede" +source = "git+https://github.com/a-b-street/15m#d094b01a78fbda56c46fd5358b03e9e0c290e8ab" dependencies = [ "anyhow", "chrono", diff --git a/backend/src/heatmap.rs b/backend/src/heatmap.rs index 5f511c3..115dd27 100644 --- a/backend/src/heatmap.rs +++ b/backend/src/heatmap.rs @@ -5,7 +5,7 @@ use geojson::FeatureCollection; use graph::IntersectionID; use rstar::{primitives::GeomWithData, RTree}; -use crate::{CompareRouteRequest, MapModel, RoadKind}; +use crate::{MapModel, RoadKind}; // Walk along severances. Every X meters, try to cross from one side to the other. // @@ -17,7 +17,7 @@ pub fn along_severances(map: &MapModel) -> FeatureCollection { for r in &map.graph.roads { if map.road_kinds[r.id.0] == Some(RoadKind::Severance) { for line in make_perpendicular_offsets(&r.linestring, 25.0, 15.0) { - requests.push(line.into()); + requests.push((line.start, line.end)); } } } @@ -50,26 +50,21 @@ pub fn nearby_footway_intersections(map: &MapModel, dist_meters: f64) -> Feature // For every intersection, try to go to every nearby intersection let mut requests = Vec::new(); for i1 in &footway_intersections { - let i1_pt = map.graph.intersections[i1.0].point; + let i1_pt: Coord = map.graph.intersections[i1.0].point.into(); for i2 in rtree.locate_within_distance(i1_pt.into(), dist_meters) { // TODO Skip trivial things connected by a road - let i2_pt = map.graph.intersections[i2.data.0].point; - requests.push(CompareRouteRequest { - x1: i1_pt.x(), - y1: i1_pt.y(), - x2: i2_pt.x(), - y2: i2_pt.y(), - }); + let i2_pt = map.graph.intersections[i2.data.0].point.into(); + requests.push((i1_pt, i2_pt)); } } calculate(map, requests) } -fn calculate(map: &MapModel, requests: Vec) -> FeatureCollection { +fn calculate(map: &MapModel, requests: Vec<(Coord, Coord)>) -> FeatureCollection { let mut samples = Vec::new(); let mut max_score = 0.0_f64; - for req in requests { - if let Ok((mut f, fc)) = crate::route::do_route(map, req) { + for (start, end) in requests { + if let Ok((mut f, fc)) = crate::route::do_route(map, start, end) { let direct = fc .foreign_members .as_ref() diff --git a/backend/src/lib.rs b/backend/src/lib.rs index 06445d2..e9d3aa4 100644 --- a/backend/src/lib.rs +++ b/backend/src/lib.rs @@ -3,7 +3,7 @@ extern crate log; use std::sync::Once; -use geo::{Coord, Line}; +use geo::Coord; use geojson::GeoJson; use graph::{Direction, Graph, Mode, Road, Timer}; use serde::Deserialize; @@ -95,24 +95,15 @@ impl MapModel { #[wasm_bindgen(js_name = compareRoute)] pub fn compare_route(&self, input: JsValue) -> Result { let req: CompareRouteRequest = serde_wasm_bindgen::from_value(input)?; - let pt1 = self.graph.mercator.pt_to_mercator(Coord { + let start = self.graph.mercator.pt_to_mercator(Coord { x: req.x1, y: req.y1, }); - let pt2 = self.graph.mercator.pt_to_mercator(Coord { + let end = self.graph.mercator.pt_to_mercator(Coord { x: req.x2, y: req.y2, }); - let (_, gj) = route::do_route( - self, - CompareRouteRequest { - x1: pt1.x, - y1: pt1.y, - x2: pt2.x, - y2: pt2.y, - }, - ) - .map_err(err_to_js)?; + let (_, gj) = route::do_route(self, start, end).map_err(err_to_js)?; let out = serde_json::to_string(&gj).map_err(err_to_js)?; Ok(out) } @@ -163,17 +154,6 @@ pub struct CompareRouteRequest { y2: f64, } -impl From for CompareRouteRequest { - fn from(line: Line) -> Self { - Self { - x1: line.start.x, - y1: line.start.y, - x2: line.end.x, - y2: line.end.y, - } - } -} - fn err_to_js(err: E) -> JsValue { JsValue::from_str(&err.to_string()) } diff --git a/backend/src/route.rs b/backend/src/route.rs index ce48b03..216a292 100644 --- a/backend/src/route.rs +++ b/backend/src/route.rs @@ -4,24 +4,12 @@ use geojson::{Feature, FeatureCollection, Geometry}; use graph::{Mode, PathStep}; use serde::Serialize; -use crate::{CompareRouteRequest, MapModel}; +use crate::MapModel; // Also returns the line of the snapped request (in WGS84) -pub fn do_route(map: &MapModel, req: CompareRouteRequest) -> Result<(Feature, FeatureCollection)> { - let start = map.graph.snap_to_road( - Coord { - x: req.x1, - y: req.y1, - }, - Mode::Foot, - ); - let end = map.graph.snap_to_road( - Coord { - x: req.x2, - y: req.y2, - }, - Mode::Foot, - ); +pub fn do_route(map: &MapModel, start: Coord, end: Coord) -> Result<(Feature, FeatureCollection)> { + let start = map.graph.snap_to_road(start, Mode::Foot); + let end = map.graph.snap_to_road(end, Mode::Foot); let route = map.graph.router[Mode::Foot].route(&map.graph, start, end)?; let route_linestring = route.linestring(&map.graph);