drawing parking markings too

This commit is contained in:
Dustin Carlino 2018-06-26 10:44:14 -07:00
parent 736d143b30
commit 50aa53e9a9
6 changed files with 102 additions and 22 deletions

View File

@ -107,7 +107,6 @@ wait slow down even more -- before any of this change, lanes on adjacent roads s
- debug impossibly long derived roads, like the horizontal E McGraw. try to detect by comparing length of original points with length of derived center pts. - debug impossibly long derived roads, like the horizontal E McGraw. try to detect by comparing length of original points with length of derived center pts.
- big maps start centered over emptiness - big maps start centered over emptiness
- some bldg paths are quite long. - some bldg paths are quite long.
- draw parking markings
- make final Map serializable too - make final Map serializable too
- useful to precompute sidewalk paths - useful to precompute sidewalk paths
- reorg map making - reorg map making

View File

@ -25,9 +25,15 @@
1.0 1.0
], ],
"Parking": [ "Parking": [
0.5, 0.2,
0.0, 0.2,
0.5, 0.2,
1.0
],
"ParkingMarking": [
1.0,
1.0,
1.0,
1.0 1.0
], ],
"Sidewalk": [ "Sidewalk": [
@ -90,6 +96,12 @@
0.7, 0.7,
1.0 1.0
], ],
"BuildingPath": [
0.8,
0.8,
0.8,
1.0
],
"ParcelBoundary": [ "ParcelBoundary": [
0.3, 0.3,
0.3, 0.3,

View File

@ -15,6 +15,7 @@ pub enum Colors {
BrightDebug, BrightDebug,
Road, Road,
Parking, Parking,
ParkingMarking,
Sidewalk, Sidewalk,
SidewalkMarking, SidewalkMarking,
ChangedStopSignIntersection, ChangedStopSignIntersection,
@ -25,6 +26,7 @@ pub enum Colors {
Turn, Turn,
ConflictingTurn, ConflictingTurn,
Building, Building,
BuildingPath,
ParcelBoundary, ParcelBoundary,
ParcelInterior, ParcelInterior,
RoadOrientation, RoadOrientation,

View File

@ -30,13 +30,14 @@ impl DrawBuilding {
} }
// TODO it'd be cool to draw a thick border. how to expand a polygon? // TODO it'd be cool to draw a thick border. how to expand a polygon?
pub fn draw(&self, g: &mut GfxCtx, color: Color) { pub fn draw(&self, g: &mut GfxCtx, fill_color: Color, path_color: Color) {
if let Some(line) = self.front_path { if let Some(line) = self.front_path {
let path = graphics::Line::new_round([0.0, 0.6, 0.0, 1.0], 1.0); // TODO tune width
let path = graphics::Line::new_round(path_color, 1.0);
path.draw(line, &g.ctx.draw_state, g.ctx.transform, g.gfx); path.draw(line, &g.ctx.draw_state, g.ctx.transform, g.gfx);
} }
let poly = graphics::Polygon::new(color); let poly = graphics::Polygon::new(fill_color);
poly.draw(&self.polygon, &g.ctx.draw_state, g.ctx.transform, g.gfx); poly.draw(&self.polygon, &g.ctx.draw_state, g.ctx.transform, g.gfx);
} }

View File

@ -23,7 +23,9 @@ pub struct DrawRoad {
start_crossing: (Vec2d, Vec2d), start_crossing: (Vec2d, Vec2d),
end_crossing: (Vec2d, Vec2d), end_crossing: (Vec2d, Vec2d),
sidewalk_lines: Vec<(Vec2d, Vec2d)>, marking_lines: Vec<(Vec2d, Vec2d)>,
// Remember so we know how to color marking_lines
lane_type: map_model::LaneType,
} }
impl DrawRoad { impl DrawRoad {
@ -47,11 +49,12 @@ impl DrawRoad {
}, },
start_crossing: (start_1, start_2), start_crossing: (start_1, start_2),
end_crossing: (end_1, end_2), end_crossing: (end_1, end_2),
sidewalk_lines: if road.lane_type == map_model::LaneType::Sidewalk { marking_lines: match road.lane_type {
calculate_sidewalk_lines(road) map_model::LaneType::Sidewalk => calculate_sidewalk_lines(road),
} else { map_model::LaneType::Parking => calculate_parking_lines(road),
Vec::new() map_model::LaneType::Driving => Vec::new(),
}, },
lane_type: road.lane_type,
} }
} }
@ -77,13 +80,19 @@ impl DrawRoad {
); );
} }
let sidewalk_marking = graphics::Line::new( let extra_marking_color = match self.lane_type {
cs.get(Colors::SidewalkMarking), map_model::LaneType::Sidewalk => cs.get(Colors::SidewalkMarking),
map_model::LaneType::Parking => cs.get(Colors::ParkingMarking),
// this case doesn't matter yet, no dotted lines yet...
map_model::LaneType::Driving => cs.get(Colors::Road),
};
let extra_marking = graphics::Line::new(
extra_marking_color,
// TODO move this somewhere // TODO move this somewhere
0.25, 0.25,
); );
for pair in &self.sidewalk_lines { for pair in &self.marking_lines {
sidewalk_marking.draw( extra_marking.draw(
[pair.0[0], pair.0[1], pair.1[0], pair.1[1]], [pair.0[0], pair.0[1], pair.1[0], pair.1[1]],
&g.ctx.draw_state, &g.ctx.draw_state,
g.ctx.transform, g.ctx.transform,
@ -165,6 +174,13 @@ impl DrawRoad {
} }
} }
// TODO this always does it at pt1
fn perp_line(orig1: Pt2D, orig2: Pt2D, length: f64) -> (Vec2d, Vec2d) {
let (pt1, _) = map_model::shift_line(length / 2.0, orig1, orig2);
let (_, pt2) = map_model::shift_line(length / 2.0, orig2, orig1);
(pt1.to_vec(), pt2.to_vec())
}
fn calculate_sidewalk_lines(road: &map_model::Road) -> Vec<(Vec2d, Vec2d)> { fn calculate_sidewalk_lines(road: &map_model::Road) -> Vec<(Vec2d, Vec2d)> {
let tile_every = geometry::LANE_THICKNESS * si::M; let tile_every = geometry::LANE_THICKNESS * si::M;
@ -187,9 +203,55 @@ fn calculate_sidewalk_lines(road: &map_model::Road) -> Vec<(Vec2d, Vec2d)> {
result result
} }
// TODO this always does it at pt1 fn calculate_parking_lines(road: &map_model::Road) -> Vec<(Vec2d, Vec2d)> {
fn perp_line(orig1: Pt2D, orig2: Pt2D, length: f64) -> (Vec2d, Vec2d) { // TODO look up this value
let (pt1, _) = map_model::shift_line(length / 2.0, orig1, orig2); let tile_every = 10.0 * si::M;
let (_, pt2) = map_model::shift_line(length / 2.0, orig2, orig1); // meters, but the dims get annoying below to remove
(pt1.to_vec(), pt2.to_vec()) // TODO make Pt2D natively understand meters, projecting away by an angle
let leg_length = 1.0;
let pi = f64::consts::PI;
let length = road.length();
let mut result = Vec::new();
// Start away from the intersections
let mut dist_along = tile_every;
while dist_along < length - tile_every {
let (pt, lane_angle) = road.dist_along(dist_along);
let perp_angle = lane_angle.value_unsafe + (pi * 1.5);
// Find the outside of the lane. Actually, shift inside a little bit, since the line will
// have thickness, but shouldn't really intersect the adjacent line when drawn.
let t_pt = Pt2D::new(
pt.x() + (geometry::LANE_THICKNESS * 0.4) * perp_angle.cos(),
pt.y() + (geometry::LANE_THICKNESS * 0.4) * perp_angle.sin(),
);
// The perp leg
result.push((
[t_pt.x(), t_pt.y()],
[
t_pt.x() - leg_length * perp_angle.cos(),
t_pt.y() - leg_length * perp_angle.sin(),
],
));
// Upper leg
result.push((
[t_pt.x(), t_pt.y()],
[
t_pt.x() + leg_length * lane_angle.value_unsafe.cos(),
t_pt.y() + leg_length * lane_angle.value_unsafe.sin(),
],
));
// Lower leg
result.push((
[t_pt.x(), t_pt.y()],
[
t_pt.x() - leg_length * lane_angle.value_unsafe.cos(),
t_pt.y() - leg_length * lane_angle.value_unsafe.sin(),
],
));
dist_along += tile_every;
}
result
} }

View File

@ -536,7 +536,11 @@ impl gui::GUI for UI {
if self.show_buildings.is_enabled() { if self.show_buildings.is_enabled() {
for b in &self.draw_map.get_buildings_onscreen(screen_bbox) { for b in &self.draw_map.get_buildings_onscreen(screen_bbox) {
b.draw(g, self.color_building(b.id)); b.draw(
g,
self.color_building(b.id),
self.cs.get(Colors::BuildingPath),
);
} }
} }