also retain the logical pieces of a Trace, so we can next find chokepoints

This commit is contained in:
Dustin Carlino 2018-10-13 11:15:19 -07:00
parent fddc56dca5
commit 99559fa578
9 changed files with 74 additions and 22 deletions

View File

@ -1,11 +1,11 @@
use colors::{ColorScheme, Colors};
use dimensioned::si;
use ezgui::{GfxCtx, UserInput};
use map_model::{Map, LANE_THICKNESS};
use map_model::{Map, Trace, LANE_THICKNESS};
use objects::ID;
use piston::input::Key;
use plugins::Colorizer;
use sim::{AgentID, Sim, Trace};
use sim::{AgentID, Sim};
use std::f64;
pub enum ShowRouteState {
@ -71,7 +71,7 @@ impl ShowRouteState {
if let ShowRouteState::Active(_, trace) = self {
g.draw_polygon(
cs.get(Colors::Queued),
&trace.make_polygons_blindly(LANE_THICKNESS),
&trace.polyline.make_polygons_blindly(LANE_THICKNESS),
);
}
}

View File

@ -32,7 +32,7 @@ impl DrawCar {
let stopping_buffer = input
.stopping_trace
.map(|t| t.make_polygons_blindly(CAR_WIDTH));
.map(|t| t.polyline.make_polygons_blindly(CAR_WIDTH));
let front_window_length_gap = 0.2;
let front_window_thickness = 0.3;

View File

@ -42,7 +42,7 @@ pub use map::Map;
pub use parcel::{Parcel, ParcelID};
pub use pathfind::Pathfinder;
pub use road::{Road, RoadID};
pub use traversable::Traversable;
pub use traversable::{Trace, TraceSegment, Traversable};
pub use turn::{Turn, TurnID};
pub const LANE_THICKNESS: f64 = 2.5;

View File

@ -55,12 +55,36 @@ impl Traversable {
map: &Map,
start: si::Meter<f64>,
end: si::Meter<f64>,
) -> Option<(PolyLine, si::Meter<f64>)> {
) -> Option<(Trace, si::Meter<f64>)> {
match self {
&Traversable::Lane(id) => if reverse {
Some(map.get_l(id).lane_center_pts.reversed().slice(start, end))
let pts = &map.get_l(id).lane_center_pts;
let len = pts.length();
let (polyline, remainder) = pts.reversed().slice(start, end);
Some((
Trace {
polyline,
segments: vec![TraceSegment {
on: *self,
start_dist: len - start,
end_dist: len - end,
}],
},
remainder,
))
} else {
Some(map.get_l(id).lane_center_pts.slice(start, end))
let (polyline, remainder) = map.get_l(id).lane_center_pts.slice(start, end);
Some((
Trace {
polyline,
segments: vec![TraceSegment {
on: *self,
start_dist: start,
end_dist: end,
}],
},
remainder,
))
},
&Traversable::Turn(id) => {
assert!(!reverse);
@ -68,7 +92,19 @@ impl Traversable {
if t.line.length() <= EPSILON_DIST {
None
} else {
Some(PolyLine::new(vec![t.line.pt1(), t.line.pt2()]).slice(start, end))
let (polyline, remainder) =
PolyLine::new(vec![t.line.pt1(), t.line.pt2()]).slice(start, end);
Some((
Trace {
polyline,
segments: vec![TraceSegment {
on: *self,
start_dist: start,
end_dist: end,
}],
},
remainder,
))
}
}
}
@ -88,3 +124,21 @@ impl Traversable {
}
}
}
pub struct TraceSegment {
pub on: Traversable,
pub start_dist: si::Meter<f64>,
pub end_dist: si::Meter<f64>,
}
pub struct Trace {
pub polyline: PolyLine,
pub segments: Vec<TraceSegment>,
}
impl Trace {
pub fn extend(&mut self, other: Trace) {
self.polyline.extend(other.polyline);
self.segments.extend(other.segments);
}
}

View File

@ -5,7 +5,7 @@ use geom::EPSILON_DIST;
use intersections::{IntersectionSimState, Request};
use kinematics;
use kinematics::Vehicle;
use map_model::{LaneID, Map, Traversable, TurnID, LANE_THICKNESS};
use map_model::{LaneID, Map, Trace, Traversable, TurnID, LANE_THICKNESS};
use multimap::MultiMap;
use ordered_float::NotNaN;
use parking::ParkingSimState;
@ -17,7 +17,7 @@ use transit::TransitSimState;
use view::{AgentView, WorldView};
use {
Acceleration, AgentID, CarID, CarState, Distance, DrawCarInput, Event, ParkedCar, ParkingSpot,
Speed, Tick, Time, Trace,
Speed, Tick, Time,
};
const TIME_TO_PARK_OR_DEPART: Time = si::Second {

View File

@ -55,10 +55,10 @@ use abstutil::Cloneable;
use dimensioned::si;
pub use edits::MapEdits;
pub use events::Event;
use geom::{Angle, PolyLine, Pt2D};
use geom::{Angle, Pt2D};
pub use helpers::{load, SimFlags};
pub use instrument::save_backtraces;
use map_model::{LaneID, TurnID};
use map_model::{LaneID, Trace, TurnID};
pub use scenario::{Neighborhood, Scenario, SeedParkedCars, SpawnOverTime};
pub use sim::{Benchmark, Sim};
use std::fmt;
@ -322,5 +322,3 @@ impl Cloneable for Scenario {}
impl Cloneable for Tick {}
impl Cloneable for MapEdits {}
impl Cloneable for ABTest {}
pub type Trace = PolyLine;

View File

@ -2,13 +2,13 @@ use dimensioned::si;
use driving::Action;
use kinematics;
use kinematics::Vehicle;
use map_model::{BuildingID, LaneID, Map, Traversable, TurnID};
use map_model::{BuildingID, LaneID, Map, Trace, Traversable, TurnID};
use parking::ParkingSimState;
use rand::Rng;
use std::collections::VecDeque;
use transit::TransitSimState;
use view::AgentView;
use {Distance, Event, ParkingSpot, Tick, Trace};
use {Distance, Event, ParkingSpot, Tick};
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
enum Goal {

View File

@ -7,7 +7,7 @@ use dimensioned::si;
use driving::DrivingSimState;
use instrument::capture_backtrace;
use intersections::IntersectionSimState;
use map_model::{IntersectionID, LaneID, LaneType, Map, Turn, TurnID};
use map_model::{IntersectionID, LaneID, LaneType, Map, Trace, Turn, TurnID};
use parking::ParkingSimState;
use rand::{FromEntropy, SeedableRng, XorShiftRng};
use spawn::Spawner;
@ -21,7 +21,7 @@ use view::WorldView;
use walking::WalkingSimState;
use {
AgentID, CarID, CarState, Distance, DrawCarInput, DrawPedestrianInput, Event, PedestrianID,
ScoreSummary, Tick, Trace, TIMESTEP,
ScoreSummary, Tick, TIMESTEP,
};
#[derive(Serialize, Deserialize, Derivative)]

View File

@ -4,7 +4,7 @@ use dimensioned::si;
use geom::{Line, Pt2D};
use instrument::capture_backtrace;
use intersections::{IntersectionSimState, Request};
use map_model::{BuildingID, BusStopID, Lane, LaneID, Map, Traversable, Turn, TurnID};
use map_model::{BuildingID, BusStopID, Lane, LaneID, Map, Trace, Traversable, Turn, TurnID};
use multimap::MultiMap;
use parking::ParkingSimState;
use std;
@ -13,7 +13,7 @@ use trips::TripManager;
use view::{AgentView, WorldView};
use {
AgentID, Distance, DrawPedestrianInput, Event, ParkingSpot, PedestrianID, Speed, Tick, Time,
Trace, TIMESTEP,
TIMESTEP,
};
// TODO tune these!
@ -599,7 +599,7 @@ impl WalkingSimState {
let l = map.get_l(next_lane);
(l.first_pt(), l.last_pt())
};
let last_pt = *result.points().last().unwrap();
let last_pt = *result.polyline.points().last().unwrap();
if last_pt == pt1 {
if contraflow {
// Already done!