diff --git a/docs/lanes.md b/docs/lanes.md index 00c1e4e7be..9a4a6662d9 100644 --- a/docs/lanes.md +++ b/docs/lanes.md @@ -120,11 +120,8 @@ wait slow down even more -- before any of this change, lanes on adjacent roads s - make final Map serializable too - useful to precompute sidewalk paths - waiting on https://github.com/paholg/dimensioned/issues/31 to release - - cant easily serialize ordered float, so move away from it first? - - isolate vec2d - - turn's slope() and vecmath::normalized - split out geometry crate again - let ezgui stuff depend on it too - also a polygon struct? for parcels and buildings diff --git a/editor/Cargo.toml b/editor/Cargo.toml index 652b1f4a75..377b62ce5f 100644 --- a/editor/Cargo.toml +++ b/editor/Cargo.toml @@ -23,4 +23,3 @@ sim = { path = "../sim" } structopt = "0.2" strum = "0.9.0" strum_macros = "0.9.0" -vecmath = "0.3.1" diff --git a/editor/src/main.rs b/editor/src/main.rs index 2badc63f6e..a0af258003 100644 --- a/editor/src/main.rs +++ b/editor/src/main.rs @@ -21,7 +21,6 @@ extern crate structopt; extern crate strum; #[macro_use] extern crate strum_macros; -extern crate vecmath; use ezgui::input::UserInput; use glutin_window::GlutinWindow; diff --git a/editor/src/render/turn.rs b/editor/src/render/turn.rs index 4ee14ad46e..6cb55e4839 100644 --- a/editor/src/render/turn.rs +++ b/editor/src/render/turn.rs @@ -13,7 +13,6 @@ use map_model::geometry; use render::{BIG_ARROW_TIP_LENGTH, TURN_ICON_ARROW_LENGTH, TURN_ICON_ARROW_THICKNESS, TURN_ICON_ARROW_TIP_LENGTH}; use std::f64; -use vecmath; #[derive(Debug)] pub struct DrawTurn { @@ -27,23 +26,21 @@ pub struct DrawTurn { impl DrawTurn { pub fn new(map: &map_model::Map, turn: &map_model::Turn, offset_along_road: usize) -> DrawTurn { let offset_along_road = offset_along_road as f64; - let src_pt = map.get_r(turn.src).last_pt(); - let dst_pt = map.get_r(turn.dst).first_pt(); - let slope = vecmath::vec2_normalized([dst_pt.x() - src_pt.x(), dst_pt.y() - src_pt.y()]); + let src_pt = turn.line.pt1(); + let dst_pt = turn.line.pt2(); + let angle = turn.line.angle(); let last_line = map.get_r(turn.src).last_line(); // Start the distance from the intersection let icon_center = last_line .reverse() .unbounded_dist_along((offset_along_road + 0.5) * TURN_ICON_ARROW_LENGTH * si::M); - let icon_src = [ - icon_center.x() - (TURN_ICON_ARROW_LENGTH / 2.0) * slope[0], - icon_center.y() - (TURN_ICON_ARROW_LENGTH / 2.0) * slope[1], - ]; - let icon_dst = [ - icon_center.x() + (TURN_ICON_ARROW_LENGTH / 2.0) * slope[0], - icon_center.y() + (TURN_ICON_ARROW_LENGTH / 2.0) * slope[1], - ]; + let icon_src = icon_center + .project_away(TURN_ICON_ARROW_LENGTH / 2.0, angle.opposite()) + .to_vec(); + let icon_dst = icon_center + .project_away(TURN_ICON_ARROW_LENGTH / 2.0, angle) + .to_vec(); let icon_circle = geometry::circle( icon_center.x(), diff --git a/map_model/Cargo.toml b/map_model/Cargo.toml index acada2faf0..97b91c915f 100644 --- a/map_model/Cargo.toml +++ b/map_model/Cargo.toml @@ -13,4 +13,3 @@ piston2d-graphics = "*" rand = "0.5.1" serde = "1.0" serde_derive = "1.0" -vecmath = "0.3.1" diff --git a/map_model/src/lib.rs b/map_model/src/lib.rs index 00543f7435..b2c4546136 100644 --- a/map_model/src/lib.rs +++ b/map_model/src/lib.rs @@ -10,7 +10,6 @@ extern crate rand; extern crate serde; #[macro_use] extern crate serde_derive; -extern crate vecmath; mod building; pub mod geometry; diff --git a/map_model/src/turn.rs b/map_model/src/turn.rs index 20045cb775..58f11d4df4 100644 --- a/map_model/src/turn.rs +++ b/map_model/src/turn.rs @@ -7,7 +7,6 @@ use Pt2D; use RoadID; use dimensioned::si; use std::f64; -use vecmath; // TODO reconsider pub usize. maybe outside world shouldnt know. #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] @@ -49,12 +48,4 @@ impl Turn { pub fn length(&self) -> si::Meter { self.line.length() } - - // TODO rethink this one - pub fn slope(&self) -> [f64; 2] { - vecmath::vec2_normalized([ - self.line.pt2().x() - self.line.pt1().x(), - self.line.pt2().y() - self.line.pt1().y(), - ]) - } } diff --git a/sim/Cargo.toml b/sim/Cargo.toml index 4913923ce6..75a05c5df7 100644 --- a/sim/Cargo.toml +++ b/sim/Cargo.toml @@ -15,4 +15,3 @@ piston2d-graphics = "*" rand = { version = "0.5.1", features = ["serde1"] } serde = "1.0" serde_derive = "1.0" -vecmath = "0.3.1" diff --git a/sim/src/lib.rs b/sim/src/lib.rs index 99ab557f13..54c016a004 100644 --- a/sim/src/lib.rs +++ b/sim/src/lib.rs @@ -12,7 +12,6 @@ extern crate rand; extern crate serde; #[macro_use] extern crate serde_derive; -extern crate vecmath; pub mod common; mod straw_intersections; diff --git a/sim/src/straw_model.rs b/sim/src/straw_model.rs index a6b466bdaa..7c41cbeabd 100644 --- a/sim/src/straw_model.rs +++ b/sim/src/straw_model.rs @@ -495,13 +495,9 @@ impl Sim { let mut cars = self.roads[r.0].get_draw_cars(&self, map); for c in &mut cars { if let Some(on) = self.cars[&c.id].waiting_for { - let slope = map.get_t(on.as_turn()).slope(); - c.turn_arrow = Some([ - c.front.x() - (CAR_LENGTH / 2.0) * slope[0], - c.front.y() - (CAR_LENGTH / 2.0) * slope[1], - c.front.x(), - c.front.y(), - ]); + let angle = map.get_t(on.as_turn()).line.angle(); + let arrow_pt = c.front.project_away(CAR_LENGTH / 2.0, angle.opposite()); + c.turn_arrow = Some([arrow_pt.x(), arrow_pt.y(), c.front.x(), c.front.y()]); } } cars