Optimize last route segment
This commit is contained in:
parent
6de816f6a4
commit
37544b09aa
@ -64,7 +64,10 @@ pub(crate) fn generate_svg(
|
||||
) -> String {
|
||||
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))
|
||||
.set(
|
||||
"viewBox",
|
||||
(0.0, route2_start.y(), 2100.0, -route2_start.y() + 1000.0),
|
||||
)
|
||||
.set("xmlns:xlink", "http://www.w3.org/1999/xlink");
|
||||
|
||||
for circle in points.iter().map(|(p, color)| {
|
||||
|
@ -57,7 +57,7 @@ fn read_stdin() -> InputData {
|
||||
}
|
||||
}
|
||||
|
||||
fn custom_input() -> InputData {
|
||||
fn _custom_input() -> InputData {
|
||||
let mut polys = vec![];
|
||||
polys.push(Polygon::new(
|
||||
vec![
|
||||
|
24
src/main.rs
24
src/main.rs
@ -4,6 +4,7 @@ use chrono::{Duration, NaiveTime};
|
||||
|
||||
use std::cmp;
|
||||
use std::collections::BinaryHeap;
|
||||
use std::f64;
|
||||
|
||||
mod display;
|
||||
mod input;
|
||||
@ -113,16 +114,15 @@ fn main() {
|
||||
let bus = last.bus;
|
||||
let range = to_bus(bus, last.pos);
|
||||
if range.len() == 2 {
|
||||
let range = Line::new(range[0], range[1]);
|
||||
for next_y in float_range(range.start.y, range.end.y) {
|
||||
let mut next = range.start;
|
||||
next.y = next_y;
|
||||
let next = Point::from(next);
|
||||
let next = Point::new(
|
||||
0.0,
|
||||
last.pos.y() + 30.0f64.to_radians().tan() * last.pos.x(),
|
||||
);
|
||||
let line = Line::new(last.pos, next);
|
||||
if none_intersect(&polys, &line) {
|
||||
let delay =
|
||||
line.end.y
|
||||
- bus.y() - line.end_point().euclidean_distance(&line.start_point()) * 2.0;
|
||||
let delay = line.end.y
|
||||
- bus.y() - line.end_point().euclidean_distance(&line.start_point())
|
||||
* 2.0;
|
||||
if delay > best_delay {
|
||||
// neue beste Wartezeit
|
||||
let mut route = s.clone();
|
||||
@ -151,7 +151,6 @@ fn main() {
|
||||
save_counter += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
states.extend(all);
|
||||
}
|
||||
}
|
||||
@ -164,13 +163,6 @@ fn main() {
|
||||
display::dump_route(house, &polys, &route);
|
||||
}
|
||||
|
||||
/// [a; b]
|
||||
fn float_range(a: f64, b: f64) -> impl Iterator<Item = f64> {
|
||||
const STEPS: usize = 1337;
|
||||
let d = b - a;
|
||||
(0..=STEPS).map(move |s| a + ((s as f64) * d) / STEPS as f64)
|
||||
}
|
||||
|
||||
fn none_intersect(polys: &[Polygon], line: &Line) -> bool {
|
||||
let mut middle = line.start;
|
||||
middle.x += line.dx() / 2.0;
|
||||
|
Loading…
Reference in New Issue
Block a user