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}}");
}
/*
pub(crate) fn dump_route(house: Point, polys: &[Polygon], route: &Vec<RunState>) {
let (points, lines, route1, route2_start) = gen_params(house, route);
print!(
@ -101,13 +100,9 @@ fn gen_params(
Vec<Point>,
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::<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)
}
@ -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()
}
*/

View File

@ -14,17 +14,21 @@ mod input;
type Point = geo::Point<f64>;
type Line = geo::Line<f64>;
type LineString = geo::LineString<f64>;
type Polygon = geo::Polygon<f64>;
// 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 {