mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 03:35:51 +03:00
fix most of the angle inversion mess!
This commit is contained in:
parent
c66564dd9d
commit
4dd2835cd4
@ -14,6 +14,7 @@ use ezgui::{
|
||||
VerticalAlignment, Widget, GUI,
|
||||
};
|
||||
use geom::{Angle, Duration, Polygon, Pt2D, Time};
|
||||
use std::collections::HashSet;
|
||||
|
||||
fn main() {
|
||||
// Control flow surrendered here. App implements State, which has an event handler and a draw
|
||||
@ -73,13 +74,18 @@ impl App {
|
||||
}]),
|
||||
Widget::row(vec![
|
||||
// Examples of styling widgets
|
||||
Widget::col(col1).outline(3.0, Color::BLACK).margin(5),
|
||||
Widget::col(col2).outline(3.0, Color::BLACK).margin(5),
|
||||
Widget::col(col3).outline(3.0, Color::BLACK).margin(5),
|
||||
Widget::col(col1)
|
||||
.outline(3.0, Color::BLACK)
|
||||
.padding(5)
|
||||
.margin_right(5),
|
||||
Widget::col(col2)
|
||||
.outline(3.0, Color::BLACK)
|
||||
.padding(5)
|
||||
.margin_right(5),
|
||||
Widget::col(col3).outline(3.0, Color::BLACK).padding(5),
|
||||
]),
|
||||
LinePlot::new(
|
||||
ctx,
|
||||
"timeseries",
|
||||
vec![
|
||||
Series {
|
||||
label: "Linear".to_string(),
|
||||
@ -100,10 +106,12 @@ impl App {
|
||||
},
|
||||
],
|
||||
PlotOptions {
|
||||
filterable: false,
|
||||
// Without this, the plot doesn't stretch to cover times in between whole
|
||||
// seconds.
|
||||
max_x: Some(Time::START_OF_DAY + self.elapsed),
|
||||
max_y: None,
|
||||
disabled: HashSet::new(),
|
||||
},
|
||||
),
|
||||
])
|
||||
@ -232,7 +240,7 @@ fn setup_scrollable_canvas(ctx: &mut EventCtx) -> Drawable {
|
||||
.render_to_batch(&ctx.prerender)
|
||||
.scale(2.0)
|
||||
.centered_on(Pt2D::new(600.0, 500.0))
|
||||
.rotate(Angle::new_degs(30.0)),
|
||||
.rotate(Angle::new_degs(-30.0)),
|
||||
);
|
||||
// This is a bit of a hack; it's needed so that zooming in/out has reasonable limits.
|
||||
ctx.canvas.map_dims = (5000.0, 5000.0);
|
||||
|
@ -99,7 +99,7 @@ impl CompareTimes {
|
||||
.rotate(Angle::new_degs(90.0))
|
||||
.autocrop();
|
||||
// The text is already scaled; don't use Widget::draw_batch and scale it again.
|
||||
JustDraw::wrap(ctx, label).centered_vert()
|
||||
JustDraw::wrap(ctx, label).centered_vert().margin_right(5)
|
||||
};
|
||||
|
||||
let x_axis = Widget::row(
|
||||
|
@ -31,11 +31,7 @@ impl AlmostDrawLane {
|
||||
GeomBatch::mapspace_svg(prerender, "../data/system/assets/map/bus_only.svg")
|
||||
.scale(0.06)
|
||||
.centered_on(pt)
|
||||
.rotate(
|
||||
angle
|
||||
.shortest_rotation_towards(Angle::new_degs(-90.0))
|
||||
.invert_y(),
|
||||
),
|
||||
.rotate(angle.shortest_rotation_towards(Angle::new_degs(-90.0))),
|
||||
);
|
||||
dist += btwn;
|
||||
}
|
||||
@ -51,11 +47,7 @@ impl AlmostDrawLane {
|
||||
GeomBatch::mapspace_svg(prerender, "../data/system/assets/meters/bike.svg")
|
||||
.scale(0.06)
|
||||
.centered_on(pt)
|
||||
.rotate(
|
||||
angle
|
||||
.shortest_rotation_towards(Angle::new_degs(-90.0))
|
||||
.invert_y(),
|
||||
),
|
||||
.rotate(angle.shortest_rotation_towards(Angle::new_degs(-90.0))),
|
||||
);
|
||||
dist += btwn;
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ impl Renderable for DrawRoad {
|
||||
txt.render_to_batch(g.prerender)
|
||||
.scale(0.1)
|
||||
.centered_on(pt)
|
||||
.rotate(angle.invert_y()),
|
||||
.rotate(angle),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -282,9 +282,7 @@ 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.angle()
|
||||
.shortest_rotation_towards(Angle::new_degs(90.0))
|
||||
.invert_y(),
|
||||
l.angle().shortest_rotation_towards(Angle::new_degs(90.0)),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ impl Angle {
|
||||
Angle::new_rads(self.0 + std::f64::consts::PI)
|
||||
}
|
||||
|
||||
pub fn invert_y(self) -> Angle {
|
||||
pub(crate) fn invert_y(self) -> Angle {
|
||||
Angle::new_rads(2.0 * std::f64::consts::PI - self.0)
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ impl Polygon {
|
||||
.iter()
|
||||
.map(|pt| {
|
||||
let origin_pt = Pt2D::new(pt.x() - center.x(), pt.y() - center.y());
|
||||
let (sin, cos) = angle.invert_y().normalized_radians().sin_cos();
|
||||
let (sin, cos) = angle.normalized_radians().sin_cos();
|
||||
Pt2D::new(
|
||||
center.x() + origin_pt.x() * cos - origin_pt.y() * sin,
|
||||
center.y() + origin_pt.y() * cos + origin_pt.x() * sin,
|
||||
|
Loading…
Reference in New Issue
Block a user