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