Organize LTN code a bit, moving the auto heuristics under the filters module

This commit is contained in:
Dustin Carlino 2022-02-23 13:53:44 +00:00
parent 2a1b1283f2
commit 8e076eb9ae
13 changed files with 37 additions and 43 deletions

View File

@ -11,9 +11,8 @@ use widgetry::{
State, Text, TextExt, Toggle, VerticalAlignment, Widget,
};
use super::auto::Heuristic;
use super::{Neighborhood, NeighborhoodID};
use crate::{App, Transition};
use crate::filters::auto::Heuristic;
use crate::{App, Neighborhood, NeighborhoodID, Transition};
pub struct BrowseNeighborhoods {
panel: Panel,
@ -110,7 +109,7 @@ impl State<App> for BrowseNeighborhoods {
match self.panel.event(ctx) {
Outcome::Clicked(x) => match x.as_ref() {
"Export to GeoJSON" => {
let result = super::export::write_geojson_file(ctx, app);
let result = crate::export::write_geojson_file(ctx, app);
return Transition::Push(match result {
Ok(path) => PopupMsg::new_state(
ctx,
@ -123,7 +122,7 @@ impl State<App> for BrowseNeighborhoods {
});
}
"Calculate" | "Show impact" => {
return Transition::Push(super::impact::ShowResults::new_state(ctx, app));
return Transition::Push(crate::impact::ShowResults::new_state(ctx, app));
}
"Automatically stop rat-runs" => {
ctx.loading_screen("automatically filter all neighborhoods", |ctx, timer| {
@ -168,7 +167,7 @@ impl State<App> for BrowseNeighborhoods {
}
if let WorldOutcome::ClickedObject(id) = self.world.event(ctx) {
return Transition::Push(super::connectivity::Viewer::new_state(ctx, app, id));
return Transition::Push(crate::connectivity::Viewer::new_state(ctx, app, id));
}
Transition::Keep
@ -211,7 +210,7 @@ fn make_world(ctx: &mut EventCtx, app: &App, timer: &mut Timer) -> World<Neighbo
// TODO The cell colors are confusing alongside the other neighborhood colors. I
// tried greying out everything else, but then the view is too jumpy.
let neighborhood = Neighborhood::new(ctx, app, *id);
let render_cells = super::draw_cells::RenderCells::new(map, &neighborhood);
let render_cells = crate::draw_cells::RenderCells::new(map, &neighborhood);
let hovered_batch = render_cells.draw();
world
.add(*id)
@ -223,7 +222,7 @@ fn make_world(ctx: &mut EventCtx, app: &App, timer: &mut Timer) -> World<Neighbo
}
Style::Quietness => {
let neighborhood = Neighborhood::new(ctx, app, *id);
let rat_runs = super::rat_runs::find_rat_runs(app, &neighborhood, timer);
let rat_runs = crate::rat_runs::find_rat_runs(app, &neighborhood, timer);
let (quiet_streets, total_streets) =
rat_runs.quiet_and_total_streets(&neighborhood);
let pct = if total_streets == 0 {
@ -265,7 +264,7 @@ fn draw_over_roads(ctx: &mut EventCtx, app: &App, timer: &mut Timer) -> ToggleZo
for id in app.session.partitioning.all_neighborhoods().keys() {
let neighborhood = Neighborhood::new(ctx, app, *id);
let rat_runs = super::rat_runs::find_rat_runs(app, &neighborhood, timer);
let rat_runs = crate::rat_runs::find_rat_runs(app, &neighborhood, timer);
count_per_road.extend(rat_runs.count_per_road);
count_per_intersection.extend(rat_runs.count_per_intersection);
}

View File

@ -5,10 +5,9 @@ use widgetry::{
Widget,
};
use super::auto::Heuristic;
use super::per_neighborhood::{FilterableObj, Tab};
use super::{Neighborhood, NeighborhoodID};
use crate::{App, Transition};
use crate::filters::auto::Heuristic;
use crate::per_neighborhood::{FilterableObj, Tab};
use crate::{App, Neighborhood, NeighborhoodID, Transition};
pub struct Viewer {
panel: Panel,
@ -129,7 +128,7 @@ impl State<App> for Viewer {
}
let world_outcome = self.world.event(ctx);
if super::per_neighborhood::handle_world_outcome(ctx, app, world_outcome) {
if crate::per_neighborhood::handle_world_outcome(ctx, app, world_outcome) {
self.neighborhood = Neighborhood::new(ctx, app, self.neighborhood.id);
self.update(ctx, app);
}
@ -165,13 +164,13 @@ fn make_world(
let map = &app.map;
let mut world = World::bounded(map.get_bounds());
super::per_neighborhood::populate_world(ctx, app, neighborhood, &mut world, |id| id, 0);
crate::per_neighborhood::populate_world(ctx, app, neighborhood, &mut world, |id| id, 0);
// The world is drawn in between areas and roads, but some things need to be drawn on top of
// roads
let mut draw_top_layer = GeomBatch::new();
let render_cells = super::draw_cells::RenderCells::new(map, neighborhood);
let render_cells = crate::draw_cells::RenderCells::new(map, neighborhood);
if app.session.draw_cells_as_areas {
world.draw_master_batch(ctx, render_cells.draw());
} else {

View File

@ -5,7 +5,7 @@ use map_gui::tools::Grid;
use map_model::Map;
use widgetry::{Color, GeomBatch};
use super::Neighborhood;
use crate::Neighborhood;
lazy_static::lazy_static! {
static ref COLORS: [Color; 6] = [

View File

@ -3,8 +3,7 @@ use anyhow::Result;
use geom::{PolyLine, Pt2D};
use widgetry::EventCtx;
use super::Neighborhood;
use crate::App;
use crate::{App, Neighborhood};
/// Returns the path where the file was written
pub fn write_geojson_file(ctx: &EventCtx, app: &App) -> Result<String> {
@ -69,7 +68,7 @@ fn geojson_string(ctx: &EventCtx, app: &App) -> Result<String> {
// Cells per neighborhood
let render_cells =
super::draw_cells::RenderCells::new(map, &Neighborhood::new(ctx, app, *id));
crate::draw_cells::RenderCells::new(map, &Neighborhood::new(ctx, app, *id));
for (idx, multipolygon) in render_cells.to_multipolygons().into_iter().enumerate() {
let mut feature = Feature {
bbox: None,

View File

@ -1,3 +1,4 @@
pub mod auto;
mod existing;
use std::collections::{BTreeMap, BTreeSet};

View File

@ -8,7 +8,7 @@ use widgetry::{
Slider, State, Text, TextExt, Toggle, VerticalAlignment, Widget,
};
use super::{end_of_day, Filters, Impact};
use crate::impact::{end_of_day, Filters, Impact};
use crate::{App, BrowseNeighborhoods, Transition};
// TODO Share structure or pieces with Ungap's predict mode

View File

@ -16,7 +16,6 @@ extern crate anyhow;
#[macro_use]
extern crate log;
mod auto;
mod browse;
mod connectivity;
mod draw_cells;
@ -72,7 +71,7 @@ fn run(mut settings: Settings) {
draw_neighborhood_style: browse::Style::SimpleColoring,
draw_cells_as_areas: true,
draw_borders_as_arrows: true,
heuristic: auto::Heuristic::OnlyOneBorder,
heuristic: filters::auto::Heuristic::OnlyOneBorder,
main_road_penalty: 1.0,
current_trip_name: None,
@ -141,7 +140,7 @@ pub struct Session {
// Connectivity:
pub draw_cells_as_areas: bool,
pub draw_borders_as_arrows: bool,
pub heuristic: auto::Heuristic,
pub heuristic: filters::auto::Heuristic,
// Pathfinding
pub main_road_penalty: f64,

View File

@ -9,9 +9,8 @@ use widgetry::{
Color, EventCtx, GfxCtx, Line, Outcome, Panel, RoundedF64, Spinner, State, Text, Widget,
};
use super::per_neighborhood::{FilterableObj, Tab};
use super::{Neighborhood, NeighborhoodID};
use crate::{App, Transition};
use crate::per_neighborhood::{FilterableObj, Tab};
use crate::{App, Neighborhood, NeighborhoodID, Transition};
pub struct RoutePlanner {
panel: Panel,
@ -104,7 +103,7 @@ impl RoutePlanner {
self.panel = panel;
let mut world = World::bounded(app.map.get_bounds());
super::per_neighborhood::populate_world(
crate::per_neighborhood::populate_world(
ctx,
app,
&self.neighborhood,
@ -242,7 +241,7 @@ impl State<App> for RoutePlanner {
Obj::Filterable(id) => Some(id),
_ => None,
}) {
if super::per_neighborhood::handle_world_outcome(ctx, app, outcome) {
if crate::per_neighborhood::handle_world_outcome(ctx, app, outcome) {
self.neighborhood = Neighborhood::new(ctx, app, self.neighborhood.id);
self.update_everything(ctx, app);
return Transition::Keep;

View File

@ -82,7 +82,7 @@ impl Tab {
Transition::Replace(BrowseNeighborhoods::new_state(ctx, app))
}
"Adjust boundary" => Transition::Replace(
super::select_boundary::SelectBoundary::new_state(ctx, app, id),
crate::select_boundary::SelectBoundary::new_state(ctx, app, id),
),
"Connectivity" => Tab::Connectivity.switch_to_state(ctx, app, id),
"Rat runs" => Tab::RatRuns.switch_to_state(ctx, app, id),
@ -116,9 +116,9 @@ impl Tab {
id: NeighborhoodID,
) -> Transition {
Transition::Replace(match self {
Tab::Connectivity => super::connectivity::Viewer::new_state(ctx, app, id),
Tab::RatRuns => super::rat_run_viewer::BrowseRatRuns::new_state(ctx, app, id),
Tab::Pathfinding => super::pathfinding::RoutePlanner::new_state(ctx, app, id),
Tab::Connectivity => crate::connectivity::Viewer::new_state(ctx, app, id),
Tab::RatRuns => crate::rat_run_viewer::BrowseRatRuns::new_state(ctx, app, id),
Tab::Pathfinding => crate::pathfinding::RoutePlanner::new_state(ctx, app, id),
})
}

View File

@ -6,10 +6,9 @@ use widgetry::{
Color, EventCtx, GfxCtx, Key, Line, Outcome, Panel, State, Text, TextExt, Toggle, Widget,
};
use super::per_neighborhood::{FilterableObj, Tab};
use super::rat_runs::{find_rat_runs, RatRuns};
use super::{Neighborhood, NeighborhoodID};
use crate::{App, Transition};
use crate::per_neighborhood::{FilterableObj, Tab};
use crate::rat_runs::{find_rat_runs, RatRuns};
use crate::{App, Neighborhood, NeighborhoodID, Transition};
pub struct BrowseRatRuns {
panel: Panel,
@ -177,7 +176,7 @@ impl State<App> for BrowseRatRuns {
// TODO Bit weird to allow this while showing individual paths, since we don't draw the
// world
let world_outcome = self.world.event(ctx);
if super::per_neighborhood::handle_world_outcome(ctx, app, world_outcome) {
if crate::per_neighborhood::handle_world_outcome(ctx, app, world_outcome) {
// TODO We could be a bit more efficient here, but simplest to just start over with a
// new state
return Transition::Replace(BrowseRatRuns::new_state(ctx, app, self.neighborhood.id));
@ -217,7 +216,7 @@ fn make_world(
let map = &app.map;
let mut world = World::bounded(map.get_bounds());
super::per_neighborhood::populate_world(ctx, app, neighborhood, &mut world, |id| id, 0);
crate::per_neighborhood::populate_world(ctx, app, neighborhood, &mut world, |id| id, 0);
// Bit hacky. Go through and fill out tooltips for the objects just added to the world.
for r in &neighborhood.orig_perimeter.interior {

View File

@ -6,8 +6,7 @@ use map_model::{
PathfinderCaching, Position, RoadID,
};
use super::{Cell, Neighborhood};
use crate::App;
use crate::{App, Cell, Neighborhood};
pub struct RatRuns {
pub paths: Vec<Path>,

View File

@ -190,12 +190,12 @@ impl State<App> for SelectBoundary {
// back to a different neighborhood than we started with. And also the original
// partitioning will have been lost!!!
app.session.partitioning = self.orig_partitioning.clone();
return Transition::Replace(super::connectivity::Viewer::new_state(
return Transition::Replace(crate::connectivity::Viewer::new_state(
ctx, app, self.id,
));
}
"Confirm" => {
return Transition::Replace(super::connectivity::Viewer::new_state(
return Transition::Replace(crate::connectivity::Viewer::new_state(
ctx, app, self.id,
));
}