mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 01:15:12 +03:00
Filter intersections when freehand draw crosses them. Closes #875
This commit is contained in:
parent
25ebb627be
commit
e7bcb12b84
@ -1,6 +1,8 @@
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
use geom::{Angle, ArrowCap, Distance, PolyLine};
|
||||
use map_gui::tools::ColorNetwork;
|
||||
use map_model::Perimeter;
|
||||
use map_model::{IntersectionID, Perimeter};
|
||||
use widgetry::mapspace::{ToggleZoomed, World};
|
||||
use widgetry::tools::PolyLineLasso;
|
||||
use widgetry::{
|
||||
@ -11,7 +13,7 @@ use widgetry::{
|
||||
use crate::filters::auto::Heuristic;
|
||||
use crate::per_neighborhood::{FilterableObj, Tab};
|
||||
use crate::rat_runs::find_rat_runs;
|
||||
use crate::{after_edit, colors, App, Neighborhood, NeighborhoodID, Transition};
|
||||
use crate::{after_edit, colors, App, DiagonalFilter, Neighborhood, NeighborhoodID, Transition};
|
||||
|
||||
pub struct Viewer {
|
||||
top_panel: Panel,
|
||||
@ -307,6 +309,7 @@ struct FreehandFilters {
|
||||
lasso: PolyLineLasso,
|
||||
id: NeighborhoodID,
|
||||
perimeter: Perimeter,
|
||||
interior_intersections: BTreeSet<IntersectionID>,
|
||||
instructions: Text,
|
||||
instructions_at: ScreenPt,
|
||||
}
|
||||
@ -321,19 +324,45 @@ impl FreehandFilters {
|
||||
lasso: PolyLineLasso::new(),
|
||||
id: neighborhood.id,
|
||||
perimeter: neighborhood.orig_perimeter.clone(),
|
||||
interior_intersections: neighborhood.interior_intersections.clone(),
|
||||
instructions_at,
|
||||
instructions: Text::from_all(vec![
|
||||
Line("Click and drag").fg(ctx.style().text_hotkey_color),
|
||||
Line(" across the roads you want to flter"),
|
||||
Line(" across the roads you want to filter"),
|
||||
]),
|
||||
})
|
||||
}
|
||||
|
||||
fn make_filters_along_path(&self, ctx: &mut EventCtx, app: &mut App, path: PolyLine) {
|
||||
app.session.modal_filters.before_edit();
|
||||
for r in &self.perimeter.interior {
|
||||
if app.session.modal_filters.roads.contains_key(r) {
|
||||
continue;
|
||||
}
|
||||
let road = app.map.get_r(*r);
|
||||
if let Some((pt, _)) = road.center_pts.intersection(&path) {
|
||||
let dist = road
|
||||
.center_pts
|
||||
.dist_along_of_point(pt)
|
||||
.map(|pair| pair.0)
|
||||
.unwrap_or(road.center_pts.length() / 2.0);
|
||||
app.session.modal_filters.roads.insert(*r, dist);
|
||||
}
|
||||
}
|
||||
for i in &self.interior_intersections {
|
||||
if app.map.get_i(*i).polygon.intersects_polyline(&path) {
|
||||
// We probably won't guess the right one, but make an attempt
|
||||
DiagonalFilter::cycle_through_alternatives(ctx, app, *i);
|
||||
}
|
||||
}
|
||||
after_edit(ctx, app);
|
||||
}
|
||||
}
|
||||
|
||||
impl State<App> for FreehandFilters {
|
||||
fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition {
|
||||
if let Some(pl) = self.lasso.event(ctx) {
|
||||
make_filters_along_path(ctx, app, &self.perimeter, pl);
|
||||
self.make_filters_along_path(ctx, app, pl);
|
||||
return Transition::Multi(vec![
|
||||
Transition::Pop,
|
||||
Transition::Replace(Viewer::new_state(ctx, app, self.id)),
|
||||
@ -352,27 +381,3 @@ impl State<App> for FreehandFilters {
|
||||
DrawBaselayer::PreviousState
|
||||
}
|
||||
}
|
||||
|
||||
fn make_filters_along_path(
|
||||
ctx: &mut EventCtx,
|
||||
app: &mut App,
|
||||
perimeter: &Perimeter,
|
||||
path: PolyLine,
|
||||
) {
|
||||
app.session.modal_filters.before_edit();
|
||||
for r in &perimeter.interior {
|
||||
if app.session.modal_filters.roads.contains_key(r) {
|
||||
continue;
|
||||
}
|
||||
let road = app.map.get_r(*r);
|
||||
if let Some((pt, _)) = road.center_pts.intersection(&path) {
|
||||
let dist = road
|
||||
.center_pts
|
||||
.dist_along_of_point(pt)
|
||||
.map(|pair| pair.0)
|
||||
.unwrap_or(road.center_pts.length() / 2.0);
|
||||
app.session.modal_filters.roads.insert(*r, dist);
|
||||
}
|
||||
}
|
||||
after_edit(ctx, app);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user