From af280353cc479ced788e3535a801dc7d97237689 Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Sun, 27 Jan 2019 12:52:21 +0100 Subject: [PATCH] Cleanup --- src/main.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4a6972e..0eb5303 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,7 +63,7 @@ fn main() { let mut states = BinaryHeap::new(); states.push(vec![start]); - let mut best_delay = f32::from(0.0); + let mut best_delay = 0.0; let mut best = vec![]; while states.peek().map(|x| x[0].delay > best_delay) == Some(true) { @@ -102,13 +102,13 @@ fn main() { } // attempt to go to the bus, with varying delays let mut bus_reached = false; - for delay in float_range(last.delay.into(), 0.0).map(f32::from) { + for delay in float_range(last.delay.into(), 0.0) { let bus = last.bus.translate(0.0.into(), delay); let range = to_bus(bus, last.pos); if range.len() == 2 { bus_reached = true; // TODO: what if effectively unreachable? let range = Line::new(range[0], range[1]); - for percent in float_range(0.0, 1.0).map(f32::from) { + for percent in float_range(0.0, 1.0) { let mut next = range.start; next.x += range.dx() * percent; next.y += range.dy() * percent; @@ -228,7 +228,7 @@ fn max_possible_delay(bus: Point, start: Point) -> f32 { assert_eq!(c, 0.0); let d = bus.y(); - b - ((a.powi(2)) * f32::from(3.0)).sqrt() - d + b - ((a.powi(2)) * (3.0)).sqrt() - d } // Go straight to the bus. Returns the points where the bus can be reached. @@ -238,15 +238,15 @@ fn to_bus(bus: Point, start: Point) -> Vec { let c = bus.x(); let d = bus.y(); - let v: f32 = -a.powi(2) * f32::from(3.0) + f32::from(6.0) * a * c + b.powi(2) - f32::from(2.0) * b * d - f32::from(3.0) * c.powi(2) + d.powi(2); + let v = -a.powi(2) * (3.0) + (6.0) * a * c + b.powi(2) - (2.0) * b * d - (3.0) * c.powi(2) + d.powi(2); if v >= 0.0 { // v = sqrt(-3 A^2 + 6 A C + B^2 - 2 B D - 3 C^2 + D^2) let v = v.sqrt(); // x = 1/3 (+-v + 2 B - 2 D) - let x1: f32 = (v + f32::from(2.0) * b - f32::from(2.0) * d) / f32::from(3.0); - let x2: f32 = (-v + f32::from(2.0) * b - f32::from(2.0) * d) / f32::from(3.0); - if x1 > f32::from(0.0) && x2 > f32::from(0.0) { - vec![bus.translate(0.0.into(), f32::from(2.0) * x1), bus.translate(0.0.into(), f32::from(2.0) * x2)] + let x1 = (v + 2.0 * b - 2.0 * d) / 3.0; + let x2 = (-v + 2.0 * b - 2.0 * d) / 3.0; + if x1 > (0.0) && x2 > (0.0) { + vec![bus.translate(0.0, (2.0) * x1), bus.translate(0.0, (2.0) * x2)] } else { vec![] }