diff --git a/game/src/render/traffic_signal.rs b/game/src/render/traffic_signal.rs index d56ebacb3a..f5f97d6ff9 100644 --- a/game/src/render/traffic_signal.rs +++ b/game/src/render/traffic_signal.rs @@ -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)), ) } diff --git a/geom/src/line.rs b/geom/src/line.rs index cbe46b3c68..7cd6684ddf 100644 --- a/geom/src/line.rs +++ b/geom/src/line.rs @@ -165,6 +165,14 @@ impl Line { self.percent_along(dist / len) } + pub fn safe_dist_along(&self, dist: Distance) -> Option { + if dist > self.length() { + None + } else { + Some(self.dist_along(dist)) + } + } + pub fn middle(&self) -> Pt2D { self.dist_along(self.length() / 2.0) }