From c6ebab1e9cdf0b29d956f309d4fd47adf9f40bf2 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Sun, 8 Jul 2018 13:59:55 -0700 Subject: [PATCH] move some sim code --- docs/TODO_phase1.md | 11 +++++++ editor/src/plugins/sim_controls.rs | 4 +-- sim/src/common.rs | 51 ------------------------------ sim/src/lib.rs | 47 +++++++++++++++++++++++++-- sim/src/straw_intersections.rs | 2 +- sim/src/straw_model.rs | 2 +- 6 files changed, 60 insertions(+), 57 deletions(-) delete mode 100644 sim/src/common.rs diff --git a/docs/TODO_phase1.md b/docs/TODO_phase1.md index 3ddd9c3ada..c97a0fd94c 100644 --- a/docs/TODO_phase1.md +++ b/docs/TODO_phase1.md @@ -60,3 +60,14 @@ - https://www.politesi.polimi.it/bitstream/10589/112826/4/2015_10_TOPTAS.pdf pg38 - just make polygons around center lines, then intersect? + + + + + + +morning thoughts! + +- trim lines based on outermost POLYGON border line, not lane center lines or anything +- the ascending angle and skipping existing lines in the thesis seems to make sense +- find where infinite line intersects line segment for some cases? diff --git a/editor/src/plugins/sim_controls.rs b/editor/src/plugins/sim_controls.rs index c618c6ec8d..04d623b22f 100644 --- a/editor/src/plugins/sim_controls.rs +++ b/editor/src/plugins/sim_controls.rs @@ -5,7 +5,7 @@ use control::ControlMap; use ezgui::input::UserInput; use map_model::Map; use piston::input::{Key, UpdateEvent}; -use sim::common; +use sim; use sim::straw_model; use std::time::{Duration, Instant}; @@ -67,7 +67,7 @@ impl SimController { // TODO https://gafferongames.com/post/fix_your_timestep/ let dt = tick.elapsed(); let dt_s = dt.as_secs() as f64 + f64::from(dt.subsec_nanos()) * 1e-9; - if dt_s >= common::TIMESTEP.value_unsafe / self.desired_speed { + if dt_s >= sim::TIMESTEP.value_unsafe / self.desired_speed { self.sim.step(map, control_map); self.last_step = Some(Instant::now()); } diff --git a/sim/src/common.rs b/sim/src/common.rs deleted file mode 100644 index 1e3daebf7a..0000000000 --- a/sim/src/common.rs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0 - -use dimensioned::si; - -#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] -pub struct CarID(pub usize); - -use std; -pub const TIMESTEP: si::Second = si::Second { - value_unsafe: 0.1, - _marker: std::marker::PhantomData, -}; -pub const SPEED_LIMIT: si::MeterPerSecond = si::MeterPerSecond { - value_unsafe: 8.9408, - _marker: std::marker::PhantomData, -}; - -#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] -pub struct Tick(u32); - -impl Tick { - pub fn zero() -> Tick { - Tick(0) - } - - pub fn as_time(&self) -> si::Second { - (self.0 as f64) * TIMESTEP - } - - pub fn increment(&mut self) { - self.0 += 1; - } -} - -use std::fmt; -use std::ops::Sub; - -impl Sub for Tick { - type Output = Tick; - - fn sub(self, other: Tick) -> Tick { - Tick(self.0 - other.0) - } -} - -impl fmt::Display for Tick { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - // TODO switch to minutes and hours when this gets big - write!(f, "{0:.1}s", (self.0 as f64) * TIMESTEP.value_unsafe) - } -} diff --git a/sim/src/lib.rs b/sim/src/lib.rs index a0b94d328c..c89d7f1065 100644 --- a/sim/src/lib.rs +++ b/sim/src/lib.rs @@ -14,8 +14,51 @@ extern crate serde; #[macro_use] extern crate serde_derive; -pub mod common; mod straw_intersections; pub mod straw_model; -pub use common::CarID; +use dimensioned::si; + +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] +pub struct CarID(pub usize); + +pub const TIMESTEP: si::Second = si::Second { + value_unsafe: 0.1, + _marker: std::marker::PhantomData, +}; +pub const SPEED_LIMIT: si::MeterPerSecond = si::MeterPerSecond { + value_unsafe: 8.9408, + _marker: std::marker::PhantomData, +}; + +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] +pub struct Tick(u32); + +impl Tick { + pub fn zero() -> Tick { + Tick(0) + } + + pub fn as_time(&self) -> si::Second { + (self.0 as f64) * TIMESTEP + } + + pub fn increment(&mut self) { + self.0 += 1; + } +} + +impl std::ops::Sub for Tick { + type Output = Tick; + + fn sub(self, other: Tick) -> Tick { + Tick(self.0 - other.0) + } +} + +impl std::fmt::Display for Tick { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + // TODO switch to minutes and hours when this gets big + write!(f, "{0:.1}s", (self.0 as f64) * TIMESTEP.value_unsafe) + } +} diff --git a/sim/src/straw_intersections.rs b/sim/src/straw_intersections.rs index bc8c3f4478..7c36a16d01 100644 --- a/sim/src/straw_intersections.rs +++ b/sim/src/straw_intersections.rs @@ -1,11 +1,11 @@ // Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0 -use common::{CarID, Tick, SPEED_LIMIT}; use control::ControlMap; use control::stop_signs::{ControlStopSign, TurnPriority}; use dimensioned::si; use map_model::{IntersectionID, Map, TurnID}; use std::collections::HashMap; +use {CarID, Tick, SPEED_LIMIT}; use std; const WAIT_AT_STOP_SIGN: si::Second = si::Second { diff --git a/sim/src/straw_model.rs b/sim/src/straw_model.rs index cbf69cab2a..195dc66ae0 100644 --- a/sim/src/straw_model.rs +++ b/sim/src/straw_model.rs @@ -1,6 +1,5 @@ // Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0 -use common::{CarID, Tick, SPEED_LIMIT}; use control::ControlMap; use dimensioned::si; use ezgui::GfxCtx; @@ -15,6 +14,7 @@ use std::collections::{BTreeMap, HashSet}; use std::f64; use std::time::{Duration, Instant}; use straw_intersections::{IntersectionPolicy, StopSign, TrafficSignal}; +use {CarID, Tick, SPEED_LIMIT}; use std; const FOLLOWING_DISTANCE: si::Meter = si::Meter {