Various fixes for non-standard speeds

This commit is contained in:
Arne Keller 2019-03-30 22:39:56 +01:00
parent affe26209f
commit ca53032e54
2 changed files with 20 additions and 11 deletions

View File

@ -74,16 +74,16 @@ pub(crate) fn dump_latex_code(route: &[RunState], polys: &[Polygon]) {
println!("\\end{{tikzpicture}}");
}
pub(crate) fn dump_route(house: Point, polys: &[Polygon], route: &[RunState]) {
let (points, lines, route1, route2_start) = gen_params(house, route);
pub(crate) fn dump_route(opt: Opt, house: Point, polys: &[Polygon], route: &[RunState]) {
let (points, lines, route1, route2_start) = gen_params(opt, house, route);
print!(
"{}",
generate_svg(&points, &lines, polys, &route1, route2_start)
);
}
pub(crate) fn save_svg(filename: &str, house: Point, polys: &[Polygon], route: &[RunState]) {
let (points, lines, route1, route2_start) = gen_params(house, route);
pub(crate) fn save_svg(opt: Opt, filename: &str, house: Point, polys: &[Polygon], route: &[RunState]) {
let (points, lines, route1, route2_start) = gen_params(opt, house, route);
fs::write(
filename,
generate_svg(&points, &lines, polys, &route1, route2_start),
@ -93,6 +93,7 @@ pub(crate) fn save_svg(filename: &str, house: Point, polys: &[Polygon], route: &
#[allow(clippy::type_complexity)]
fn gen_params(
opt: Opt,
house: Point,
route: &[RunState],
) -> (
@ -114,7 +115,7 @@ fn gen_params(
.collect::<Vec<_>>();
let route1 = route.iter().map(|x| x.pos).collect::<Vec<_>>();
let route2_start = last.pos.translate(0.0, -last.total_distance * 2.0);
let route2_start = last.pos.translate(0.0, -last.total_distance * (opt.bus/opt.lisa));
(points, lines, route1, route2_start)
}
@ -126,11 +127,18 @@ pub(crate) fn generate_svg(
route2_start: Point,
) -> String {
let dot_radius = 25.2;
let width = route1.iter().map(|p| p.x()).chain(polys.iter().map(|x| x.exterior().0.iter().map(|p| p.x)).flatten()).max_by(|a, b| a.partial_cmp(b).unwrap()).unwrap() + dot_radius * 2.0;
let upper_y = polys.iter().map(|x| x.exterior().0.iter().map(|p| p.y)).flatten().chain(Some(route1.last().unwrap().y())).max_by(|a, b| a.partial_cmp(b).unwrap()).unwrap();
let mut document = Document::new()
// view box at (x,y), (w,h)
.set(
"viewBox",
(-dot_radius, -route1.last().unwrap().y() - dot_radius, route1.iter().map(|p| p.x()).max_by(|a, b| a.partial_cmp(b).unwrap()).unwrap() + dot_radius * 2.0, -route2_start.y() + route1.last().unwrap().y() + dot_radius * 2.0),
(
-dot_radius,
-upper_y - dot_radius,
width,
-route2_start.y() + upper_y + dot_radius * 2.0
)
)
.set("xmlns:xlink", "http://www.w3.org/1999/xlink");

View File

@ -16,7 +16,7 @@ type Line = geo::Line<f64>;
type LineString = geo::LineString<f64>;
type Polygon = geo::Polygon<f64>;
#[derive(StructOpt)]
#[derive(StructOpt, Clone, Copy)]
#[structopt(name = "aufgabe1", about = "Implementierung für Aufgabe 1")]
struct Opt {
/// Debug-Modus aktivieren
@ -66,7 +66,7 @@ fn main() {
// Startzeitpunkt berechnen
let calc_time = |total_distance, y| {
NaiveTime::from_hms(7, 30, 0)
- Duration::seconds(((total_distance * 2.0 - y) / bus_speed) as i64)
- Duration::seconds(((total_distance * (opt.bus/opt.lisa) - y) / bus_speed) as i64)
};
// Ankuftszeit berechnen
let calc_end_time = |total_distance, y| {
@ -150,7 +150,7 @@ fn main() {
// Lisa trifft Bus mit 60°-Winkel
let next = Point::new(
0.0,
last.pos.y() + 30.0f64.to_radians().tan() * last.pos.x(),
last.pos.y() + (opt.lisa/opt.bus).asin().tan() * last.pos.x(),
);
let line = Line::new(last.pos, next);
// freier Weg?
@ -180,6 +180,7 @@ fn main() {
best_delay = delay;
if opt.save_intermediates {
display::save_svg(
opt,
&format!("{}{}.svg", save_prefix, save_counter),
house,
&polys,
@ -228,7 +229,7 @@ fn main() {
if opt.tkz {
display::dump_latex_code(&route, &polys);
} else {
display::dump_route(house, &polys, &route);
display::dump_route(opt, house, &polys, &route);
}
}
@ -273,5 +274,5 @@ fn distance(a: Point, b: Point) -> f64 {
fn max_possible_delay(opt: &Opt, total_distance: f64, lisa: Point) -> f64 {
let x_l = lisa.x();
let y_l = lisa.y();
y_l - (3.0 * x_l.powi(2)).sqrt() - total_distance * (opt.bus/opt.lisa)
y_l - (((opt.bus/opt.lisa).powi(2) - 1.0) * x_l.powi(2)).sqrt() - total_distance * (opt.bus/opt.lisa)
}