ped trace_routes were wrong for contraflow steps

This commit is contained in:
Dustin Carlino 2018-10-22 12:50:41 -07:00
parent a1ac8cf7dd
commit 9c1ae28bf8
5 changed files with 16 additions and 14 deletions

View File

@ -21,7 +21,9 @@ impl Plugin for DiffAllState {
fn event(&mut self, ctx: PluginCtx) -> bool {
let active = match self {
DiffAllState::Inactive => {
ctx.secondary.is_some() && ctx.input.key_pressed(Key::D, "Diff all trips")
ctx.secondary.is_some()
&& ctx.primary.current_selection.is_none()
&& ctx.input.key_pressed(Key::D, "Diff all trips")
}
DiffAllState::Active(_) => {
!ctx.input.key_pressed(Key::Return, "Stop diffing all trips")

View File

@ -59,7 +59,7 @@ impl PolyLine {
// Returns the excess distance left over from the end.
pub fn slice(&self, start: si::Meter<f64>, end: si::Meter<f64>) -> (PolyLine, si::Meter<f64>) {
if start >= end {
if start >= end || start < 0.0 * si::M || end < 0.0 * si::M {
panic!("Can't get a polyline slice [{}, {}]", start, end);
}

View File

@ -55,11 +55,15 @@ impl Traversable {
start: si::Meter<f64>,
end: si::Meter<f64>,
) -> (Trace, si::Meter<f64>) {
assert!(start <= end);
assert!(start >= 0.0 * si::M);
assert!(end >= 0.0 * si::M);
match self {
&Traversable::Lane(id) => if reverse {
let pts = &map.get_l(id).lane_center_pts;
let len = pts.length();
let (polyline, remainder) = pts.reversed().slice(start, end);
let (polyline, remainder) = pts.reversed().slice(len - start, end);
let actual_len = polyline.length();
(
Trace {

View File

@ -167,9 +167,8 @@ impl Router {
map: &Map,
dist_along: Distance,
) -> Trace {
let (mut result, mut dist_left) = start
// TODO will this break if we pass in max for dist_along?
.slice(false, map, start_dist, start_dist + dist_along);
let (mut result, mut dist_left) =
start.slice(false, map, start_dist, start_dist + dist_along);
let mut last_lane = start.maybe_lane();
let mut idx = 0;

View File

@ -566,9 +566,8 @@ impl WalkingSimState {
pub fn trace_route(&self, id: PedestrianID, map: &Map, dist_ahead: Distance) -> Option<Trace> {
let p = self.peds.get(&id)?;
let (mut result, mut dist_left) = p.on
// TODO will this break if we pass in max for dist_along?
.slice(p.contraflow, map, p.dist_along, p.dist_along + dist_ahead);
let (mut result, mut dist_left) =
p.on.slice(p.contraflow, map, p.dist_along, p.dist_along + dist_ahead);
let mut last_lane = p.on.maybe_lane();
let mut idx = 0;
@ -595,10 +594,8 @@ impl WalkingSimState {
// TODO ooh this is _really_ cheating. ;) but sometimes we don't cross a lane either
// direction. urgh.
let (pt1, pt2) = {
let l = map.get_l(next_lane);
(l.first_pt(), l.last_pt())
};
let (pt1, pt2) = (l.first_pt(), l.last_pt());
let last_pt = result.endpoints().1;
if last_pt == pt1 {
if contraflow {
@ -612,7 +609,7 @@ impl WalkingSimState {
} else if last_pt == pt2 {
if contraflow {
let (piece, new_dist_left) =
Traversable::Lane(next_lane).slice(true, map, 0.0 * si::M, dist_left);
Traversable::Lane(next_lane).slice(true, map, l.length(), dist_left);
result = result.extend(piece);
dist_left = new_dist_left;
} else {