mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 20:29:04 +03:00
drawing a traffic signal, no good colors yet
This commit is contained in:
parent
fb24efe1f1
commit
92f8aeff1e
@ -115,6 +115,9 @@ wait slow down even more -- before any of this change, lanes on adjacent roads s
|
||||
- waiting on https://github.com/paholg/dimensioned/issues/31 to release
|
||||
|
||||
|
||||
- remove different colors for changed intersections
|
||||
- tune traffic light colors
|
||||
- draw stop signs as rounded ellipse (hard without using rotations in GfxCtx)
|
||||
|
||||
|
||||
- move map_model geometry stuff elsewhere (sim stuff also needs it though)
|
||||
@ -126,8 +129,6 @@ wait slow down even more -- before any of this change, lanes on adjacent roads s
|
||||
- https://www.politesi.polimi.it/bitstream/10589/112826/4/2015_10_TOPTAS.pdf
|
||||
- just make polygons around center lines, then intersect?
|
||||
- shift turn icons and stop markings and such away from crosswalk
|
||||
- draw stop signs as rounded ellipse (hard without using rotations in GfxCtx)
|
||||
- depict traffic lights (3 colored circles on a black rectangle)
|
||||
- figure out what to do about yellow center lines
|
||||
- yellow and white lines intersect cars and turn icons and such
|
||||
- who should own drawing them?
|
||||
|
@ -7,7 +7,7 @@ OSM, elevation data, King Country GIS data, etc, and also manual edits.
|
||||
|
||||
- Polygons shouldn't overlap
|
||||
- Can export to various formats and announce for anyone's use (though waiting for the editor might be wiser)
|
||||
- Have fun with themed rendering: halloween, winter, jungle, 8bit
|
||||
- Have fun with themed rendering: halloween, winter, jungle, 8bit, organic (deform buildings)
|
||||
|
||||
## Phase 2: Editor
|
||||
|
||||
|
@ -245,6 +245,30 @@
|
||||
0.0,
|
||||
0.0,
|
||||
1.0
|
||||
],
|
||||
"TrafficSignalBox": [
|
||||
0.8439573,
|
||||
0.49223435,
|
||||
0.26289922,
|
||||
1.0
|
||||
],
|
||||
"TrafficSignalGreen": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
1.0
|
||||
],
|
||||
"TrafficSignalYellow": [
|
||||
1.0,
|
||||
1.0,
|
||||
0.0,
|
||||
1.0
|
||||
],
|
||||
"TrafficSignalRed": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0
|
||||
]
|
||||
}
|
||||
}
|
@ -55,6 +55,11 @@ pub enum Colors {
|
||||
|
||||
MovingCar,
|
||||
StuckCar,
|
||||
|
||||
TrafficSignalBox,
|
||||
TrafficSignalGreen,
|
||||
TrafficSignalYellow,
|
||||
TrafficSignalRed,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
|
@ -20,6 +20,7 @@ pub struct DrawIntersection {
|
||||
|
||||
pub polygon: Vec<Vec2d>,
|
||||
crosswalks: Vec<Vec<(Vec2d, Vec2d)>>,
|
||||
traffic_signal_center: Option<Pt2D>,
|
||||
}
|
||||
|
||||
impl DrawIntersection {
|
||||
@ -49,12 +50,20 @@ impl DrawIntersection {
|
||||
});
|
||||
let first_pt = pts[0].clone();
|
||||
pts.push(first_pt);
|
||||
let traffic_signal_center = if inter.has_traffic_signal {
|
||||
Some(geometry::center(&pts.iter()
|
||||
.map(|pt| Pt2D::new(pt[0], pt[1]))
|
||||
.collect()))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
DrawIntersection {
|
||||
id: inter.id,
|
||||
center: [center.x(), center.y()],
|
||||
polygon: pts,
|
||||
crosswalks: calculate_crosswalks(inter, map),
|
||||
traffic_signal_center,
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,6 +86,10 @@ impl DrawIntersection {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(center) = self.traffic_signal_center {
|
||||
self.draw_traffic_signal(center, g, cs);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn contains_pt(&self, x: f64, y: f64) -> bool {
|
||||
@ -86,6 +99,47 @@ impl DrawIntersection {
|
||||
pub fn get_bbox(&self) -> Rect {
|
||||
geometry::get_bbox_for_polygons(&[self.polygon.clone()])
|
||||
}
|
||||
|
||||
fn draw_traffic_signal(&self, center: Pt2D, g: &mut GfxCtx, cs: &ColorScheme) {
|
||||
let radius = 0.5;
|
||||
|
||||
let bg = graphics::Rectangle::new(cs.get(Colors::TrafficSignalBox));
|
||||
bg.draw(
|
||||
[
|
||||
center.x() - (2.0 * radius),
|
||||
center.y() - (4.0 * radius),
|
||||
4.0 * radius,
|
||||
8.0 * radius,
|
||||
],
|
||||
&g.ctx.draw_state,
|
||||
g.ctx.transform,
|
||||
g.gfx,
|
||||
);
|
||||
|
||||
let yellow = graphics::Ellipse::new(cs.get(Colors::TrafficSignalYellow));
|
||||
yellow.draw(
|
||||
geometry::circle(center.x(), center.y(), radius),
|
||||
&g.ctx.draw_state,
|
||||
g.ctx.transform,
|
||||
g.gfx,
|
||||
);
|
||||
|
||||
let green = graphics::Ellipse::new(cs.get(Colors::TrafficSignalGreen));
|
||||
green.draw(
|
||||
geometry::circle(center.x(), center.y() + (radius * 2.0), radius),
|
||||
&g.ctx.draw_state,
|
||||
g.ctx.transform,
|
||||
g.gfx,
|
||||
);
|
||||
|
||||
let red = graphics::Ellipse::new(cs.get(Colors::TrafficSignalRed));
|
||||
red.draw(
|
||||
geometry::circle(center.x(), center.y() - (radius * 2.0), radius),
|
||||
&g.ctx.draw_state,
|
||||
g.ctx.transform,
|
||||
g.gfx,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn calculate_crosswalks(
|
||||
|
@ -89,3 +89,14 @@ pub fn circle_to_bbox(c: &[f64; 4]) -> Rect {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn center(pts: &Vec<Pt2D>) -> Pt2D {
|
||||
let mut x = 0.0;
|
||||
let mut y = 0.0;
|
||||
for pt in pts {
|
||||
x += pt.x();
|
||||
y += pt.y();
|
||||
}
|
||||
let len = pts.len() as f64;
|
||||
Pt2D::new(x / len, y / len)
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
use geo;
|
||||
use geom::{Bounds, Line, Pt2D};
|
||||
use geometry;
|
||||
use ordered_float::NotNaN;
|
||||
use raw_data;
|
||||
use std::collections::HashMap;
|
||||
@ -36,7 +37,7 @@ fn find_front_path(
|
||||
|
||||
if let Some(street_name) = bldg_osm_tags.get("addr:street") {
|
||||
// TODO start from the side of the building, not the center
|
||||
let bldg_center = center(bldg_points);
|
||||
let bldg_center = geometry::center(bldg_points);
|
||||
let center_pt = geo::Point::new(bldg_center.x(), bldg_center.y());
|
||||
|
||||
// Find all matching sidewalks with that street name, then find the closest point on
|
||||
@ -69,17 +70,6 @@ fn find_front_path(
|
||||
None
|
||||
}
|
||||
|
||||
fn center(pts: &Vec<Pt2D>) -> Pt2D {
|
||||
let mut x = 0.0;
|
||||
let mut y = 0.0;
|
||||
for pt in pts {
|
||||
x += pt.x();
|
||||
y += pt.y();
|
||||
}
|
||||
let len = pts.len() as f64;
|
||||
Pt2D::new(x / len, y / len)
|
||||
}
|
||||
|
||||
fn road_to_line_string(r: &Road) -> geo::LineString<f64> {
|
||||
let pts: Vec<geo::Point<f64>> = r.lane_center_pts
|
||||
.points()
|
||||
|
Loading…
Reference in New Issue
Block a user