rotate labels on buses, now that i figured out how to do it reasonably on roads

This commit is contained in:
Dustin Carlino 2020-06-26 11:31:27 -07:00
parent 77fa6eb43d
commit bfd1b9c190
3 changed files with 16 additions and 11 deletions

View File

@ -135,13 +135,14 @@ impl DrawCar {
}
if let Some(line) = input.label {
// TODO Would rotation make any sense? Or at least adjust position/size while turning.
// Buses are a constant length, so hardcoding this is fine.
let (pt, angle) = input.body.dist_along(Distance::meters(9.0));
draw_default.append(
Text::from(Line(line).fg(cs.bus_label))
.render_to_batch(prerender)
.scale(0.07)
.centered_on(input.body.dist_along(Distance::meters(9.0)).0),
.centered_on(pt)
.rotate(angle.reorient()),
);
}

View File

@ -77,19 +77,12 @@ impl Renderable for DrawRoad {
// even easier, just skip the center lines?
let txt = Text::from(Line(name).fg(app.cs.road_center_line))
.bg(app.cs.driving_lane);
let (pt, mut angle) = r.center_pts.dist_along(r.center_pts.length() / 2.0);
let theta = angle.normalized_degrees().rem_euclid(360.0);
if theta > 90.0 {
angle = angle.opposite();
}
if theta > 270.0 {
angle = angle.opposite();
}
let (pt, angle) = r.center_pts.dist_along(r.center_pts.length() / 2.0);
batch.append(
txt.render_to_batch(g.prerender)
.scale(0.1)
.centered_on(pt)
.rotate(angle),
.rotate(angle.reorient()),
);
}
}

View File

@ -58,6 +58,17 @@ impl Angle {
((self.normalized_degrees() - other.normalized_degrees() + 540.0) % 360.0) - 180.0;
rotation.abs() < within_degrees
}
// I don't know how to describe what this does. Use for rotating labels in map-space and making
// sure the text is never upside-down.
pub fn reorient(self) -> Angle {
let theta = self.normalized_degrees().rem_euclid(360.0);
if theta > 90.0 || theta > 270.0 {
self.opposite()
} else {
self
}
}
}
impl fmt::Display for Angle {