Re-enable and improve SVG output

This commit is contained in:
Arne Keller 2019-03-29 19:56:53 +01:00
parent ae4ac1732e
commit 0be8aef479
2 changed files with 27 additions and 24 deletions

View File

@ -74,7 +74,6 @@ pub(crate) fn dump_latex_code(route: &[RunState], polys: &[Polygon]) {
println!("\\end{{tikzpicture}}"); println!("\\end{{tikzpicture}}");
} }
/*
pub(crate) fn dump_route(house: Point, polys: &[Polygon], route: &Vec<RunState>) { pub(crate) fn dump_route(house: Point, polys: &[Polygon], route: &Vec<RunState>) {
let (points, lines, route1, route2_start) = gen_params(house, route); let (points, lines, route1, route2_start) = gen_params(house, route);
print!( print!(
@ -101,13 +100,9 @@ fn gen_params(
Vec<Point>, Vec<Point>,
Point, Point,
) { ) {
let first = route.first().unwrap();
let last = route.last().unwrap(); let last = route.last().unwrap();
let best_delay = last.delay;
let points = vec![ let points = vec![
(house, "red"), (house, "red"),
(first.bus.translate(0.0.into(), best_delay), "yellow"),
(last.bus, "orange"),
]; ];
let lines = route let lines = route
.iter() .iter()
@ -118,7 +113,7 @@ fn gen_params(
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let route1 = route.iter().map(|x| x.pos).collect::<Vec<_>>(); let route1 = route.iter().map(|x| x.pos).collect::<Vec<_>>();
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) (points, lines, route1, route2_start)
} }
@ -129,11 +124,12 @@ pub(crate) fn generate_svg(
route1: &[Point], route1: &[Point],
route2_start: Point, route2_start: Point,
) -> String { ) -> String {
let dot_radius = 25.2;
let mut document = Document::new() let mut document = Document::new()
// view box at (x,y), (w,h) // view box at (x,y), (w,h)
.set( .set(
"viewBox", "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"); .set("xmlns:xlink", "http://www.w3.org/1999/xlink");
@ -141,7 +137,7 @@ pub(crate) fn generate_svg(
Circle::new() Circle::new()
.set("cx", f64::from(p.x())) .set("cx", f64::from(p.x()))
.set("cy", f64::from(-p.y())) .set("cy", f64::from(-p.y()))
.set("r", 25.2) .set("r", dot_radius)
.set("opacity", 0.5) .set("opacity", 0.5)
.set("fill", *color) .set("fill", *color)
}) { }) {
@ -205,7 +201,7 @@ pub(crate) fn generate_svg(
let mut dot1 = Circle::new() let mut dot1 = Circle::new()
.set("cx", 0.0) .set("cx", 0.0)
.set("cy", 0.0) .set("cy", 0.0)
.set("r", 25.2) .set("r", dot_radius)
.set("opacity", 0.75) .set("opacity", 0.75)
.set("fill", "gray"); .set("fill", "gray");
let mut motion1 = AnimateMotion::new() let mut motion1 = AnimateMotion::new()
@ -231,7 +227,7 @@ pub(crate) fn generate_svg(
let mut dot1 = Circle::new() let mut dot1 = Circle::new()
.set("cx", 0.0) .set("cx", 0.0)
.set("cy", 0.0) .set("cy", 0.0)
.set("r", 25.2) .set("r", dot_radius)
.set("opacity", 0.75) .set("opacity", 0.75)
.set("fill", "gray"); .set("fill", "gray");
let mut motion1 = AnimateMotion::new() let mut motion1 = AnimateMotion::new()
@ -244,4 +240,3 @@ pub(crate) fn generate_svg(
document.to_string() document.to_string()
} }
*/

View File

@ -14,17 +14,21 @@ mod input;
type Point = geo::Point<f64>; type Point = geo::Point<f64>;
type Line = geo::Line<f64>; type Line = geo::Line<f64>;
type LineString = geo::LineString<f64>;
type Polygon = geo::Polygon<f64>; type Polygon = geo::Polygon<f64>;
// 30 km/h = 8+1/3 m/s #[derive(StructOpt)]
// 15 km/h = 4+1/6 m/s
#[derive(Debug, StructOpt)]
#[structopt(name = "aufgabe1", about = "Implementierung für Aufgabe 1")] #[structopt(name = "aufgabe1", about = "Implementierung für Aufgabe 1")]
struct Opt { struct Opt {
/// Debug-Modus aktivieren /// Debug-Modus aktivieren
#[structopt(short = "d", long = "debug")] #[structopt(short = "d", long = "debug")]
debug: bool, 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) /// Geschwindigkeit von Lisa (in km/h)
#[structopt(short = "l", long = "lisa", default_value = "15")] #[structopt(short = "l", long = "lisa", default_value = "15")]
lisa: f64, lisa: f64,
@ -172,14 +176,14 @@ fn main() {
best = route; best = route;
best.reverse(); best.reverse();
best_delay = delay; best_delay = delay;
/* if opt.save_intermediates {
display::save_svg( display::save_svg(
&format!("{}{}.svg", save_prefix, save_counter), &format!("{}{}.svg", save_prefix, save_counter),
house, house,
&polys, &polys,
&best, &best,
); );
*/ }
save_counter += 1; save_counter += 1;
} }
} }
@ -219,7 +223,11 @@ fn main() {
let seconds = last.total_distance / (15.0 / 3.6); let seconds = last.total_distance / (15.0 / 3.6);
eprintln!("Dauer: {:02.0}:{:02.0}", seconds / 60.0, seconds % 60.0); eprintln!("Dauer: {:02.0}:{:02.0}", seconds / 60.0, seconds % 60.0);
// beste Route grafisch ausgeben // beste Route grafisch ausgeben
if opt.tkz {
display::dump_latex_code(&route, &polys); display::dump_latex_code(&route, &polys);
} else {
display::dump_route(house, &polys, &route);
}
} }
fn none_intersect(polys: &[Polygon], line: &Line) -> bool { fn none_intersect(polys: &[Polygon], line: &Line) -> bool {