Make the first 3 nearest/pick.feature scenarios pass

This commit is contained in:
Dennis
2024-05-31 21:07:10 +02:00
parent 59cbb08c0e
commit 5cf37a0c7c
9 changed files with 122 additions and 29 deletions
+5 -1
View File
@@ -1,4 +1,8 @@
use std::{collections::VecDeque, fs, path::{Path, PathBuf}};
use std::{
collections::VecDeque,
fs,
path::{Path, PathBuf},
};
// TODO: port into toolbox-rs
pub struct LexicographicFileWalker {
+1
View File
@@ -1,4 +1,5 @@
pub mod lexicographic_file_walker;
pub mod nearest_response;
pub mod osm;
pub mod osm_db;
pub mod osrm_world;
+23
View File
@@ -0,0 +1,23 @@
use geo_types::{point, Point};
use serde::Deserialize;
#[derive(Deserialize, Debug)]
pub struct Waypoint {
hint: String,
nodes: Vec<u64>,
distance: f64,
name: String,
location: [f64; 2],
}
impl Waypoint {
pub fn location(&self) -> Point {
point!(self.location)
}
}
#[derive(Deserialize, Debug)]
pub struct NearestResponse {
code: String,
pub waypoints: Vec<Waypoint>,
}
+2 -2
View File
@@ -1,5 +1,5 @@
use xml_builder::{XMLBuilder, XMLElement, XMLVersion};
use super::osm::{OSMNode, OSMWay};
use xml_builder::{XMLBuilder, XMLElement, XMLVersion};
// TODO: better error handling in XML creation
#[derive(Debug, Default)]
@@ -124,4 +124,4 @@ mod tests {
println!("{actual}");
assert_eq!(actual, expected);
}
}
}
+12 -5
View File
@@ -1,6 +1,6 @@
use std::{collections::HashMap, fs::File, path::PathBuf};
use crate::Point;
use cucumber::World;
use std::{collections::HashMap, fs::File, path::PathBuf};
use super::{osm::OSMNode, osm_db::OSMDb};
@@ -58,10 +58,17 @@ impl OSRMWorld {
pub fn get_location(&self, name: char) -> Point {
match name {
// TODO: move lookup to world
'0'..='9' => self.known_locations.get(&name).expect("test case specifies unknown location: {name}"),
'a'..='z' => self.known_osm_nodes.get(&name).expect("test case specifies unknown osm node: {name}"),
'0'..='9' => self
.known_locations
.get(&name)
.expect("test case specifies unknown location: {name}"),
'a'..='z' => self
.known_osm_nodes
.get(&name)
.expect("test case specifies unknown osm node: {name}"),
_ => unreachable!("nodes have to be name in [0-9][a-z]"),
}.clone()
}
.clone()
}
pub fn add_location(&mut self, name: char, location: Point) {
@@ -70,4 +77,4 @@ impl OSRMWorld {
}
self.known_locations.insert(name, location);
}
}
}