finally flushed out one of the common crashes: shifting some car bodies

to make wheels breaks sometimes. just skip the wheels.
This commit is contained in:
Dustin Carlino 2020-07-11 17:10:36 -07:00
parent 4a92841dc9
commit faedffae99
6 changed files with 35 additions and 20 deletions

View File

@ -26,7 +26,10 @@ impl DrawCar {
for side in vec![
input.body.shift_right(CAR_WIDTH / 2.0),
input.body.shift_left(CAR_WIDTH / 2.0),
] {
]
.into_iter()
.flatten()
{
let len = side.length();
if len <= Distance::meters(2.0) {
// The original body may be fine, but sometimes shifting drastically shortens the

View File

@ -385,12 +385,12 @@ fn make_rainbow_crosswalk(batch: &mut GeomBatch, turn: &Turn, map: &Map) -> bool
let slice = turn
.geom
.exact_slice(total_width, turn.geom.length() - total_width)
.shift_left(total_width / 2.0 - band_width / 2.0);
.must_shift_left(total_width / 2.0 - band_width / 2.0);
for (idx, color) in colors.into_iter().enumerate() {
batch.push(
color,
slice
.shift_right(band_width * (idx as f64))
.must_shift_right(band_width * (idx as f64))
.make_polygons(band_width),
);
}

View File

@ -78,13 +78,13 @@ impl DrawLane {
draw.push(
app.cs.road_center_line,
lane.lane_center_pts
.shift_right(lane.width / 2.0)
.must_shift_right(lane.width / 2.0)
.make_polygons(Distance::meters(0.25)),
);
draw.push(
app.cs.road_center_line,
lane.lane_center_pts
.shift_left(lane.width / 2.0)
.must_shift_left(lane.width / 2.0)
.make_polygons(Distance::meters(0.25)),
);
}
@ -94,13 +94,13 @@ impl DrawLane {
draw.push(
app.cs.light_rail_track,
lane.lane_center_pts
.shift_right((lane.width - track_width) / 2.5)
.must_shift_right((lane.width - track_width) / 2.5)
.make_polygons(track_width),
);
draw.push(
app.cs.light_rail_track,
lane.lane_center_pts
.shift_left((lane.width - track_width) / 2.5)
.must_shift_left((lane.width - track_width) / 2.5)
.make_polygons(track_width),
);

View File

@ -361,30 +361,30 @@ impl PolyLine {
Line::must_new(self.pts[self.pts.len() - 2], self.pts[self.pts.len() - 1])
}
pub fn shift_right(&self, width: Distance) -> PolyLine {
pub fn shift_right(&self, width: Distance) -> Result<PolyLine, Box<dyn Error>> {
self.shift_with_corrections(width)
}
pub fn must_shift_right(&self, width: Distance) -> PolyLine {
self.shift_right(width).unwrap()
}
pub fn shift_left(&self, width: Distance) -> PolyLine {
pub fn shift_left(&self, width: Distance) -> Result<PolyLine, Box<dyn Error>> {
self.shift_with_corrections(-width)
}
pub fn must_shift_left(&self, width: Distance) -> PolyLine {
self.shift_left(width).unwrap()
}
// Things to remember about shifting polylines:
// - the length before and after probably don't match up
// - the number of points may not match
fn shift_with_corrections(&self, width: Distance) -> PolyLine {
fn shift_with_corrections(&self, width: Distance) -> Result<PolyLine, Box<dyn Error>> {
let raw = self.shift_with_sharp_angles(width, MITER_THRESHOLD);
let result = match PolyLine::deduping_new(raw) {
Ok(pl) => pl,
Err(err) => panic!("shifting by {} broke {}: {}", width, self, err),
};
let result = PolyLine::deduping_new(raw)?;
if result.pts.len() == self.pts.len() {
match fix_angles(self, result) {
Ok(pl) => pl,
Err(err) => panic!("shifting by {} broke {}: {}", width, self, err),
}
fix_angles(self, result)
} else {
result
Ok(result)
}
}

View File

@ -389,10 +389,12 @@ impl DrivingSide {
// "right" and "left" here are in terms of DrivingSide::Right, what I'm used to reasoning about
// in the USA. They invert appropriately for DrivingSide::Left.
pub fn right_shift(self, pl: PolyLine, width: Distance) -> PolyLine {
// TODO Plumb through the error further
match self {
DrivingSide::Right => pl.shift_right(width),
DrivingSide::Left => pl.shift_left(width),
}
.unwrap()
}
pub fn left_shift(self, pl: PolyLine, width: Distance) -> PolyLine {
@ -400,6 +402,7 @@ impl DrivingSide {
DrivingSide::Right => pl.shift_left(width),
DrivingSide::Left => pl.shift_right(width),
}
.unwrap()
}
pub fn right_shift_line(self, line: Line, width: Distance) -> Line {

View File

@ -134,7 +134,16 @@ impl Car {
} else {
-width
};
raw_body.shift_right(shift)
match raw_body.shift_right(shift) {
Ok(pl) => pl,
Err(err) => {
println!(
"Body for onstreet {} at {} broken: {}",
self.vehicle.id, now, err
);
raw_body.clone()
}
}
}
_ => {
let driveway = match spot {