fix rendering crash

This commit is contained in:
Dustin Carlino 2020-07-08 15:57:19 -07:00
parent 6304abdcc8
commit 95626d5b64
2 changed files with 9 additions and 1 deletions

View File

@ -284,7 +284,7 @@ pub fn draw_signal_phase(
fn crosswalk_icon(geom: &PolyLine) -> (Pt2D, Angle) {
let l = Line::new(geom.points()[1], geom.points()[2]);
(
l.dist_along(Distance::meters(1.0)),
l.safe_dist_along(Distance::meters(1.0)).unwrap_or(l.pt1()),
l.angle().shortest_rotation_towards(Angle::new_degs(90.0)),
)
}

View File

@ -165,6 +165,14 @@ impl Line {
self.percent_along(dist / len)
}
pub fn safe_dist_along(&self, dist: Distance) -> Option<Pt2D> {
if dist > self.length() {
None
} else {
Some(self.dist_along(dist))
}
}
pub fn middle(&self) -> Pt2D {
self.dist_along(self.length() / 2.0)
}