dashed polylines for yielding turns

This commit is contained in:
Dustin Carlino 2018-12-03 13:26:32 -08:00
parent a790fec6a1
commit 7c53e9bb4a
4 changed files with 67 additions and 24 deletions

View File

@ -2,12 +2,12 @@ use dimensioned::si;
use ezgui::{Color, GfxCtx}; use ezgui::{Color, GfxCtx};
use geom::Circle; use geom::Circle;
use map_model::{ use map_model::{
ControlTrafficSignal, IntersectionID, LaneID, TurnPriority, TurnType, LANE_THICKNESS, ControlTrafficSignal, IntersectionID, LaneID, Turn, TurnPriority, TurnType, LANE_THICKNESS,
}; };
use objects::{Ctx, ID}; use objects::{Ctx, ID};
use piston::input::Key; use piston::input::Key;
use plugins::{Plugin, PluginCtx}; use plugins::{Plugin, PluginCtx};
use render::{DrawTurn, BIG_ARROW_THICKNESS}; use render::{BIG_ARROW_THICKNESS, BIG_ARROW_TIP_LENGTH};
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum TurnCyclerState { pub enum TurnCyclerState {
@ -75,13 +75,7 @@ impl Plugin for TurnCyclerState {
match current_turn_index { match current_turn_index {
Some(idx) => { Some(idx) => {
let turn = relevant_turns[idx % relevant_turns.len()]; let turn = relevant_turns[idx % relevant_turns.len()];
DrawTurn::draw_full( draw_full(turn, g, ctx.cs.get("current selected turn", Color::RED));
turn.id,
ctx.map,
g,
ctx.cs.get("current selected turn", Color::RED),
BIG_ARROW_THICKNESS,
);
} }
None => for turn in &relevant_turns { None => for turn in &relevant_turns {
let color = match turn.turn_type { let color = match turn.turn_type {
@ -93,7 +87,7 @@ impl Plugin for TurnCyclerState {
TurnType::Right => ctx.cs.get("right turn", Color::GREEN), TurnType::Right => ctx.cs.get("right turn", Color::GREEN),
TurnType::Left => ctx.cs.get("left turn", Color::RED), TurnType::Left => ctx.cs.get("left turn", Color::RED),
}.alpha(0.5); }.alpha(0.5);
DrawTurn::draw_full(turn.id, ctx.map, g, color, BIG_ARROW_THICKNESS); draw_full(turn, g, color);
}, },
} }
} }
@ -169,13 +163,28 @@ fn draw_traffic_signal(signal: &ControlTrafficSignal, g: &mut GfxCtx, ctx: Ctx)
} }
for t in &cycle.priority_turns { for t in &cycle.priority_turns {
if !ctx.map.get_t(*t).between_sidewalks() { let turn = ctx.map.get_t(*t);
DrawTurn::draw_full(*t, ctx.map, g, priority_color, BIG_ARROW_THICKNESS); if !turn.between_sidewalks() {
draw_full(turn, g, priority_color);
} }
} }
for t in &cycle.yield_turns { for t in &cycle.yield_turns {
if !ctx.map.get_t(*t).between_sidewalks() { let turn = ctx.map.get_t(*t);
DrawTurn::draw_full(*t, ctx.map, g, yield_color, BIG_ARROW_THICKNESS / 2.0); if !turn.between_sidewalks() {
for poly in turn
.geom
.dashed_polygons(BIG_ARROW_THICKNESS, 1.0 * si::M, 0.5 * si::M)
.into_iter()
{
g.draw_polygon(yield_color, &poly);
}
// And a cap on the arrow
g.draw_rounded_arrow(
yield_color,
BIG_ARROW_THICKNESS / 2.0,
BIG_ARROW_TIP_LENGTH,
&turn.geom.last_line(),
);
} }
} }
} }
@ -225,3 +234,17 @@ fn draw_traffic_signal(signal: &ControlTrafficSignal, g: &mut GfxCtx, ctx: Ctx)
} }
} }
} }
fn draw_full(t: &Turn, g: &mut GfxCtx, color: Color) {
g.draw_polygon(
color,
&t.geom.make_polygons(2.0 * BIG_ARROW_THICKNESS).unwrap(),
);
// And a cap on the arrow
g.draw_rounded_arrow(
color,
BIG_ARROW_THICKNESS,
BIG_ARROW_TIP_LENGTH,
&t.geom.last_line(),
);
}

View File

@ -35,7 +35,7 @@ const EXTRA_SHAPE_POINT_RADIUS: f64 = 1.0;
pub const BIG_ARROW_THICKNESS: f64 = 0.5; pub const BIG_ARROW_THICKNESS: f64 = 0.5;
const TURN_ICON_ARROW_THICKNESS: f64 = BIG_ARROW_THICKNESS / 3.0; const TURN_ICON_ARROW_THICKNESS: f64 = BIG_ARROW_THICKNESS / 3.0;
const BIG_ARROW_TIP_LENGTH: f64 = 1.0; pub const BIG_ARROW_TIP_LENGTH: f64 = 1.0;
const TURN_ICON_ARROW_TIP_LENGTH: f64 = BIG_ARROW_TIP_LENGTH * 0.8; const TURN_ICON_ARROW_TIP_LENGTH: f64 = BIG_ARROW_TIP_LENGTH * 0.8;
const TURN_ICON_ARROW_LENGTH: f64 = 2.0; const TURN_ICON_ARROW_LENGTH: f64 = 2.0;
pub const CROSSWALK_LINE_THICKNESS: f64 = 0.25; pub const CROSSWALK_LINE_THICKNESS: f64 = 0.25;

View File

@ -4,8 +4,8 @@ use geom::{Bounds, Circle, Line, Pt2D};
use map_model::{Map, Turn, TurnID, LANE_THICKNESS}; use map_model::{Map, Turn, TurnID, LANE_THICKNESS};
use objects::{Ctx, ID}; use objects::{Ctx, ID};
use render::{ use render::{
RenderOptions, Renderable, BIG_ARROW_TIP_LENGTH, CROSSWALK_LINE_THICKNESS, RenderOptions, Renderable, CROSSWALK_LINE_THICKNESS, TURN_ICON_ARROW_LENGTH,
TURN_ICON_ARROW_LENGTH, TURN_ICON_ARROW_THICKNESS, TURN_ICON_ARROW_TIP_LENGTH, TURN_ICON_ARROW_THICKNESS, TURN_ICON_ARROW_TIP_LENGTH,
}; };
use std::f64; use std::f64;
@ -39,13 +39,6 @@ impl DrawTurn {
icon_arrow, icon_arrow,
} }
} }
pub fn draw_full(id: TurnID, map: &Map, g: &mut GfxCtx, color: Color, thickness: f64) {
let t = map.get_t(id);
g.draw_polygon(color, &t.geom.make_polygons(2.0 * thickness).unwrap());
// And a cap on the arrow
g.draw_rounded_arrow(color, thickness, BIG_ARROW_TIP_LENGTH, &t.geom.last_line());
}
} }
// Little weird, but this is focused on the turn icon, not the full visualization // Little weird, but this is focused on the turn icon, not the full visualization

View File

@ -305,6 +305,33 @@ impl PolyLine {
poly poly
} }
pub fn dashed_polygons(
&self,
width: f64,
dash_len: si::Meter<f64>,
dash_separation: si::Meter<f64>,
) -> Vec<Polygon> {
let mut polygons: Vec<Polygon> = Vec::new();
let total_length = self.length();
let mut start = 0.0 * si::M;
loop {
if start + dash_len >= total_length {
break;
}
polygons.push(
self.slice(start, start + dash_len)
.0
.make_polygons_blindly(width),
);
start += dash_len + dash_separation;
}
polygons
}
pub fn intersection(&self, other: &PolyLine) -> Option<Pt2D> { pub fn intersection(&self, other: &PolyLine) -> Option<Pt2D> {
assert_ne!(self, other); assert_ne!(self, other);