Skip to content

Commit

Permalink
Regenerate tests with the boundary, and accept all changes. #127
Browse files Browse the repository at this point in the history
Also plumb through the boundary when actually calling osm2streets.
  • Loading branch information
dabreegster committed Dec 12, 2022
1 parent db64e89 commit 857e2bb
Show file tree
Hide file tree
Showing 54 changed files with 49,023 additions and 103,865 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions experimental/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::units::{Direction, DrivingSide, Meters, Side, TrafficDirections};
/// let mut net = load_road_network(String::from("tests/src/aurora_sausage_link/input.osm"), &mut timer).unwrap();
/// println!("{}", net.to_dot());
pub fn load_road_network(osm_path: String, timer: &mut Timer) -> Result<RoadNetwork> {
// TODO Use the same clip
let clip_pts = None;

let (mut street_network, _) = streets_reader::osm_to_street_network(
Expand Down
23 changes: 20 additions & 3 deletions osm2streets-js/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::BTreeMap;

use abstutil::{Tags, Timer};
use geom::{Distance, PolyLine, Polygon};
use geom::{Distance, LonLat, PolyLine, Polygon};
use serde::{Deserialize, Serialize};
use wasm_bindgen::prelude::*;

Expand All @@ -24,8 +24,13 @@ pub struct JsStreetNetwork {

#[wasm_bindgen]
impl JsStreetNetwork {
// TODO clip_pts_geojson should be Option. Empty means None.
#[wasm_bindgen(constructor)]
pub fn new(osm_xml_input: &str, input: &JsValue) -> Result<JsStreetNetwork, JsValue> {
pub fn new(
osm_xml_input: &str,
clip_pts_geojson: &str,
input: &JsValue,
) -> Result<JsStreetNetwork, JsValue> {
abstutil::logger::setup();
// Panics shouldn't happen, but if they do, console.log them.
console_error_panic_hook::set_once();
Expand All @@ -34,11 +39,23 @@ impl JsStreetNetwork {
.into_serde()
.map_err(|err| JsValue::from_str(&err.to_string()))?;

let clip_pts = if clip_pts_geojson.is_empty() {
None
} else {
let mut list = LonLat::parse_geojson_polygons(clip_pts_geojson.to_string())
.map_err(|err| JsValue::from_str(&err.to_string()))?;
if list.len() != 1 {
return Err(JsValue::from_str(&format!(
"{clip_pts_geojson} doesn't contain exactly one polygon"
)));
}
Some(list.pop().unwrap().0)
};

let mut cfg = MapConfig::default();
cfg.inferred_sidewalks = input.inferred_sidewalks;
cfg.osm2lanes = input.osm2lanes;

let clip_pts = None;
let mut timer = Timer::throwaway();
let (mut street_network, doc) =
streets_reader::osm_to_street_network(osm_xml_input, clip_pts, cfg, &mut timer)
Expand Down
3 changes: 2 additions & 1 deletion street-explorer/www/js/lane_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ export class LaneEditor {

importButton.innerText = "Importing OSM data...";

this.network = new JsStreetNetwork(osmXML, {
const clipPts = "";
this.network = new JsStreetNetwork(osmXML, clipPts, {
debug_each_step: false,
dual_carriageway_experiment: false,
cycletrack_snapping_experiment: false,
Expand Down
46 changes: 21 additions & 25 deletions street-explorer/www/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,31 +121,32 @@ export class StreetExplorer {
}

class TestCase {
constructor(app, name, osmXML, bounds) {
constructor(app, name, osmXML, bounds, boundary) {
this.app = app;
this.name = name;
this.osmXML = osmXML;
this.bounds = bounds;
this.boundary = boundary;
}

static async loadFromServer(app, name) {
const prefix = `tests/${name}/`;
const osmInput = await loadFile(prefix + "input.osm");
const geometry = await loadFile(prefix + "geometry.json");
const network = await loadFile(prefix + "road_network.dot");
const boundary = await loadFile(prefix + "boundary.json");
const boundary = JSON.parse(await loadFile(prefix + "boundary.json"));

const geometryLayer = makePlainGeoJsonLayer(geometry);
const bounds = geometryLayer.getBounds();

var group = new LayerGroup("built-in test case", app.map);
group.addLayer("Boundary", makeBoundaryLayer(JSON.parse(boundary)));
group.addLayer("Boundary", makeBoundaryLayer(boundary));
group.addLayer("OSM", makeOsmLayer(osmInput), { enabled: false });
group.addLayer("Network", await makeDotLayer(network, { bounds }));
group.addLayer("Geometry", geometryLayer);
app.layers.addGroup(group);

return new TestCase(app, name, osmInput, bounds);
return new TestCase(app, name, osmInput, bounds, boundary);
}

static async importBoundary(app, importButton, boundaryGeojson) {
Expand Down Expand Up @@ -183,7 +184,7 @@ class TestCase {
fixURL.searchParams.delete("test");
window.history.pushState({}, "", fixURL);

return new TestCase(app, null, osmInput, bounds);
return new TestCase(app, null, osmInput, bounds, boundaryGeojson);
} catch (err) {
window.alert(`Import failed: ${err}`);
// There won't be a currentTest
Expand All @@ -206,15 +207,8 @@ class TestCase {
this.app.layers.removeGroups((name) => name != "built-in test case");
// Then disable the original group. Seeing dueling geometry isn't a good default.
this.app.layers.getGroup("built-in test case").setEnabled(false);
// But keep the boundary on
const boundaryLayer = this.app.layers.getLayer(
"built-in test case",
"Boundary"
);
boundaryLayer.enabled = true;
this.app.map.addLayer(boundaryLayer.getData());

importOSM("Details", this.app, this.osmXML, false, null);

importOSM("Details", this.app, this.osmXML, false, this.boundary);
};
}

Expand All @@ -236,18 +230,20 @@ class TestCase {
function importOSM(groupName, app, osmXML, addOSMLayer, boundaryGeojson) {
try {
const importSettings = app.getImportSettings();
const network = new JsStreetNetwork(osmXML, {
debug_each_step: !!importSettings.debugEachStep,
dual_carriageway_experiment: !!importSettings.dualCarriagewayExperiment,
cycletrack_snapping_experiment:
!!importSettings.cycletrackSnappingExperiment,
inferred_sidewalks: importSettings.sidewalks === "infer",
osm2lanes: !!importSettings.osm2lanes,
});
const network = new JsStreetNetwork(
osmXML,
JSON.stringify(boundaryGeojson),
{
debug_each_step: !!importSettings.debugEachStep,
dual_carriageway_experiment: !!importSettings.dualCarriagewayExperiment,
cycletrack_snapping_experiment:
!!importSettings.cycletrackSnappingExperiment,
inferred_sidewalks: importSettings.sidewalks === "infer",
osm2lanes: !!importSettings.osm2lanes,
}
);
var group = new LayerGroup(groupName, app.map);
if (boundaryGeojson) {
group.addLayer("Boundary", makeBoundaryLayer(boundaryGeojson));
}
group.addLayer("Boundary", makeBoundaryLayer(boundaryGeojson));
if (addOSMLayer) {
group.addLayer("OSM", makeOsmLayer(osmXML), { enabled: false });
}
Expand Down
1 change: 1 addition & 0 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
[dependencies]
abstutil = { git = "https://github.com/a-b-street/abstreet" }
anyhow = "1.0.38"
geom = { git = "https://github.com/a-b-street/abstreet" }
streets_reader = { path = "../streets_reader" }
serde = "1.0.123"
serde_json = "1.0.61"
Expand Down
Loading

0 comments on commit 857e2bb

Please sign in to comment.