mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 01:15:12 +03:00
Clean up the old MergeIntersections experiment in the uber-turn viewer. The map_editor can now live-debug intersection geometry and merge short roads; faster to iterate there. #114
This commit is contained in:
parent
6d2587c0f9
commit
81678822bc
@ -1,10 +1,10 @@
|
|||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
use geom::{ArrowCap, Polygon};
|
use geom::ArrowCap;
|
||||||
use map_gui::render::{DrawOptions, BIG_ARROW_THICKNESS};
|
use map_gui::render::{DrawOptions, BIG_ARROW_THICKNESS};
|
||||||
use map_gui::tools::PopupMsg;
|
use map_gui::tools::PopupMsg;
|
||||||
use map_gui::ID;
|
use map_gui::ID;
|
||||||
use map_model::{IntersectionCluster, IntersectionID, Map, PathConstraints, RoadID};
|
use map_model::{IntersectionCluster, IntersectionID, PathConstraints};
|
||||||
use widgetry::{
|
use widgetry::{
|
||||||
Color, DrawBaselayer, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line,
|
Color, DrawBaselayer, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line,
|
||||||
Panel, SimpleState, State, Text, TextExt, Toggle, VerticalAlignment, Widget,
|
Panel, SimpleState, State, Text, TextExt, Toggle, VerticalAlignment, Widget,
|
||||||
@ -49,11 +49,6 @@ impl UberTurnPicker {
|
|||||||
.text("Detect all clusters")
|
.text("Detect all clusters")
|
||||||
.hotkey(Key::D)
|
.hotkey(Key::D)
|
||||||
.build_def(ctx),
|
.build_def(ctx),
|
||||||
ctx.style()
|
|
||||||
.btn_outline
|
|
||||||
.text("Preview merged intersection")
|
|
||||||
.hotkey(Key::P)
|
|
||||||
.build_def(ctx),
|
|
||||||
]))
|
]))
|
||||||
.aligned(HorizontalAlignment::Center, VerticalAlignment::Top)
|
.aligned(HorizontalAlignment::Center, VerticalAlignment::Top)
|
||||||
.build(ctx);
|
.build(ctx);
|
||||||
@ -96,13 +91,6 @@ impl SimpleState<App> for UberTurnPicker {
|
|||||||
}
|
}
|
||||||
Transition::Keep
|
Transition::Keep
|
||||||
}
|
}
|
||||||
"Preview merged intersection" => {
|
|
||||||
return Transition::Replace(MergeIntersections::new(
|
|
||||||
ctx,
|
|
||||||
app,
|
|
||||||
self.members.clone(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -284,69 +272,3 @@ impl SimpleState<App> for UberTurnViewer {
|
|||||||
g.redraw(&self.draw);
|
g.redraw(&self.draw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MergeIntersections {
|
|
||||||
draw: Drawable,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MergeIntersections {
|
|
||||||
fn new(ctx: &mut EventCtx, app: &App, merge: BTreeSet<IntersectionID>) -> Box<dyn State<App>> {
|
|
||||||
let panel = Panel::new(Widget::row(vec![
|
|
||||||
Line("Merged intersections").small_heading().draw(ctx),
|
|
||||||
ctx.style().btn_close_widget(ctx),
|
|
||||||
]))
|
|
||||||
.aligned(HorizontalAlignment::Center, VerticalAlignment::TopInset)
|
|
||||||
.build(ctx);
|
|
||||||
|
|
||||||
// Just take the concave hull of all the original intersection polygons and the interior
|
|
||||||
// roads
|
|
||||||
let map = &app.primary.map;
|
|
||||||
let mut polygons = Vec::new();
|
|
||||||
for r in find_interior_roads(map, &merge) {
|
|
||||||
polygons.push(map.get_r(r).get_thick_polygon(map));
|
|
||||||
}
|
|
||||||
for i in merge {
|
|
||||||
polygons.push(map.get_i(i).polygon.clone());
|
|
||||||
}
|
|
||||||
let merged = Polygon::concave_hull(polygons, 0.1);
|
|
||||||
let batch = GeomBatch::from(vec![(Color::RED.alpha(0.8), merged)]);
|
|
||||||
|
|
||||||
SimpleState::new(
|
|
||||||
panel,
|
|
||||||
Box::new(MergeIntersections {
|
|
||||||
draw: ctx.upload(batch),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SimpleState<App> for MergeIntersections {
|
|
||||||
fn on_click(&mut self, _: &mut EventCtx, _: &mut App, x: &str, _: &Panel) -> Transition {
|
|
||||||
match x {
|
|
||||||
"close" => Transition::Pop,
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn other_event(&mut self, ctx: &mut EventCtx, _: &mut App) -> Transition {
|
|
||||||
ctx.canvas_movement();
|
|
||||||
Transition::Keep
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw(&self, g: &mut GfxCtx, _: &App) {
|
|
||||||
g.redraw(&self.draw);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_interior_roads(map: &Map, intersections: &BTreeSet<IntersectionID>) -> BTreeSet<RoadID> {
|
|
||||||
let mut roads = BTreeSet::new();
|
|
||||||
for i in intersections {
|
|
||||||
for r in &map.get_i(*i).roads {
|
|
||||||
let road = map.get_r(*r);
|
|
||||||
if intersections.contains(&road.src_i) && intersections.contains(&road.dst_i) {
|
|
||||||
roads.insert(road.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
roads
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user