From 0be8aef479a343a9589b483229b164f36eb973af Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Fri, 29 Mar 2019 19:56:53 +0100 Subject: [PATCH] Re-enable and improve SVG output --- src/display.rs | 17 ++++++----------- src/main.rs | 34 +++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/display.rs b/src/display.rs index fd8e99c..077a3d6 100644 --- a/src/display.rs +++ b/src/display.rs @@ -74,7 +74,6 @@ pub(crate) fn dump_latex_code(route: &[RunState], polys: &[Polygon]) { println!("\\end{{tikzpicture}}"); } -/* pub(crate) fn dump_route(house: Point, polys: &[Polygon], route: &Vec) { let (points, lines, route1, route2_start) = gen_params(house, route); print!( @@ -101,13 +100,9 @@ fn gen_params( Vec, Point, ) { - let first = route.first().unwrap(); let last = route.last().unwrap(); - let best_delay = last.delay; let points = vec![ (house, "red"), - (first.bus.translate(0.0.into(), best_delay), "yellow"), - (last.bus, "orange"), ]; let lines = route .iter() @@ -118,7 +113,7 @@ fn gen_params( .collect::>(); let route1 = route.iter().map(|x| x.pos).collect::>(); - let route2_start = first.bus.translate(0.0.into(), best_delay); + let route2_start = last.pos.translate(0.0, -last.total_distance * 2.0); (points, lines, route1, route2_start) } @@ -129,11 +124,12 @@ pub(crate) fn generate_svg( route1: &[Point], route2_start: Point, ) -> String { + let dot_radius = 25.2; let mut document = Document::new() // view box at (x,y), (w,h) .set( "viewBox", - (0.0, route2_start.y(), 2100.0, -route2_start.y() + 1000.0), + (-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), ) .set("xmlns:xlink", "http://www.w3.org/1999/xlink"); @@ -141,7 +137,7 @@ pub(crate) fn generate_svg( Circle::new() .set("cx", f64::from(p.x())) .set("cy", f64::from(-p.y())) - .set("r", 25.2) + .set("r", dot_radius) .set("opacity", 0.5) .set("fill", *color) }) { @@ -205,7 +201,7 @@ pub(crate) fn generate_svg( let mut dot1 = Circle::new() .set("cx", 0.0) .set("cy", 0.0) - .set("r", 25.2) + .set("r", dot_radius) .set("opacity", 0.75) .set("fill", "gray"); let mut motion1 = AnimateMotion::new() @@ -231,7 +227,7 @@ pub(crate) fn generate_svg( let mut dot1 = Circle::new() .set("cx", 0.0) .set("cy", 0.0) - .set("r", 25.2) + .set("r", dot_radius) .set("opacity", 0.75) .set("fill", "gray"); let mut motion1 = AnimateMotion::new() @@ -244,4 +240,3 @@ pub(crate) fn generate_svg( document.to_string() } -*/ diff --git a/src/main.rs b/src/main.rs index 5bb12b5..7bb9178 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,17 +14,21 @@ mod input; type Point = geo::Point; type Line = geo::Line; +type LineString = geo::LineString; type Polygon = geo::Polygon; -// 30 km/h = 8+1/3 m/s -// 15 km/h = 4+1/6 m/s - -#[derive(Debug, StructOpt)] +#[derive(StructOpt)] #[structopt(name = "aufgabe1", about = "Implementierung für Aufgabe 1")] struct Opt { /// Debug-Modus aktivieren #[structopt(short = "d", long = "debug")] debug: bool, + /// Zwischenlösungen speichern + #[structopt(short = "s", long = "save")] + save_intermediates: bool, + /// Beste Lösung als tkz-Code ausgeben + #[structopt(short = "t", long = "tkz")] + tkz: bool, /// Geschwindigkeit von Lisa (in km/h) #[structopt(short = "l", long = "lisa", default_value = "15")] lisa: f64, @@ -172,14 +176,14 @@ fn main() { best = route; best.reverse(); best_delay = delay; - /* - display::save_svg( - &format!("{}{}.svg", save_prefix, save_counter), - house, - &polys, - &best, - ); - */ + if opt.save_intermediates { + display::save_svg( + &format!("{}{}.svg", save_prefix, save_counter), + house, + &polys, + &best, + ); + } save_counter += 1; } } @@ -219,7 +223,11 @@ fn main() { let seconds = last.total_distance / (15.0 / 3.6); eprintln!("Dauer: {:02.0}:{:02.0}", seconds / 60.0, seconds % 60.0); // beste Route grafisch ausgeben - display::dump_latex_code(&route, &polys); + if opt.tkz { + display::dump_latex_code(&route, &polys); + } else { + display::dump_route(house, &polys, &route); + } } fn none_intersect(polys: &[Polygon], line: &Line) -> bool {