working on calculating start/end crossings explicitly

This commit is contained in:
Dustin Carlino 2018-06-25 13:44:30 -07:00
parent fef18fbf2f
commit 7c747ea9ee
6 changed files with 33 additions and 14 deletions

View File

@ -100,6 +100,10 @@ wait slow down even more -- before any of this change, lanes on adjacent roads s
- CLEANUP: bldg front path should happen upfront, not in render
- rm old thick line
- rm old lane center lines, switch to pts
- THEN: express the proto -> runtime map loading as a sequence of phases
- keep doing the current road trimming for the moment
- later, this could be the same as the OSM conversion. just

View File

@ -3,8 +3,8 @@ use ezgui::GfxCtx;
use ezgui::canvas::Canvas;
use ezgui::input::UserInput;
use graphics;
use graphics::types::Color;
use graphics::math::Vec2d;
use graphics::types::Color;
use gui;
use map_model::{polygons_for_polyline, shift_polyline, Pt2D};
use piston::input::Key;

View File

@ -23,7 +23,7 @@ impl DrawParcel {
id: p.id,
boundary_polygons: map_model::polygons_for_polyline(
&p.points,
PARCEL_BOUNDARY_THICKNESS
PARCEL_BOUNDARY_THICKNESS,
),
fill_polygon: p.points.iter().map(|pt| [pt.x(), pt.y()]).collect(),
}

View File

@ -19,22 +19,37 @@ pub struct DrawRoad {
// Empty for one-ways and one side of two-ways.
// TODO ideally this could be done in the shader or something
yellow_center_lines: Vec<Pt2D>,
start_crossing: (Vec2d, Vec2d),
end_crossing: (Vec2d, Vec2d),
}
impl DrawRoad {
pub fn new(road: &map_model::Road) -> DrawRoad {
let thick_line =
geometry::ThickLine::Centered(geometry::LANE_THICKNESS);
let lane_center_pts: Vec<Pt2D> = road.lane_center_lines.iter().flat_map(|pair| vec![pair.0, pair.1]).collect();
let thick_line = geometry::ThickLine::Centered(geometry::LANE_THICKNESS);
let lane_center_pts: Vec<Pt2D> = road.lane_center_lines
.iter()
.flat_map(|pair| vec![pair.0, pair.1])
.collect();
let (first1, first2) = road.lane_center_lines[0];
let (start_1, _) = map_model::shift_line(geometry::LANE_THICKNESS / 2.0, first1, first2);
let (_, start_2) = map_model::shift_line(geometry::LANE_THICKNESS / 2.0, first2, first1);
let (last1, last2) = *road.lane_center_lines.last().unwrap();
let (_, end_1) = map_model::shift_line(geometry::LANE_THICKNESS / 2.0, last1, last2);
let (end_2, _) = map_model::shift_line(geometry::LANE_THICKNESS / 2.0, last2, last1);
DrawRoad {
id: road.id,
polygons: geometry::thick_multiline(&thick_line, &lane_center_pts),
//polygons: map_model::polygons_for_polyline(&lane_center_pts, geometry::LANE_THICKNESS),
yellow_center_lines: if road.use_yellow_center_lines {
road.unshifted_pts.clone()
} else {
Vec::new()
},
start_crossing: (start_1.to_vec(), start_2.to_vec()),
end_crossing: (end_1.to_vec(), end_2.to_vec()),
}
}
@ -123,13 +138,10 @@ impl DrawRoad {
// Get the line marking the end of the road, perpendicular to the direction of the road
pub(crate) fn get_end_crossing(&self) -> (Vec2d, Vec2d) {
(
self.polygons.last().unwrap()[2],
self.polygons.last().unwrap()[3],
)
self.end_crossing
}
pub(crate) fn get_start_crossing(&self) -> (Vec2d, Vec2d) {
(self.polygons[0][0], self.polygons[0][1])
self.start_crossing
}
}

View File

@ -30,7 +30,7 @@ pub use intersection::{Intersection, IntersectionID};
pub use map::Map;
use ordered_float::NotNaN;
pub use parcel::{Parcel, ParcelID};
pub use polyline::{polygons_for_polyline, shift_polyline};
pub use polyline::{polygons_for_polyline, shift_line, shift_polyline};
use protobuf::error::ProtobufError;
use protobuf::{CodedInputStream, CodedOutputStream, Message};
pub use road::{LaneType, Road, RoadID};

View File

@ -1,6 +1,6 @@
use Pt2D;
use std::f64;
use graphics::math::Vec2d;
use std::f64;
// TODO unsure why this doesn't work. maybe see if mouse is inside polygon to check it out?
/*fn polygon_for_polyline(center_pts: &Vec<(f64, f64)>, width: f64) -> Vec<[f64; 2]> {
@ -33,7 +33,10 @@ pub fn polygons_for_polyline(center_pts: &Vec<Pt2D>, width: f64) -> Vec<Vec<Vec2
]);
result.push(vec![side2[high_idx], side2[high_idx - 1], side1[high_idx]]);
}
result.iter().map(|pts| pts.iter().map(|pt| pt.to_vec()).collect()).collect()
result
.iter()
.map(|pts| pts.iter().map(|pt| pt.to_vec()).collect())
.collect()
}
pub fn shift_polyline(width: f64, pts: &Vec<Pt2D>) -> Vec<Pt2D> {
@ -74,7 +77,7 @@ pub fn shift_polyline(width: f64, pts: &Vec<Pt2D>) -> Vec<Pt2D> {
result
}
fn shift_line(width: f64, pt1: Pt2D, pt2: Pt2D) -> (Pt2D, Pt2D) {
pub fn shift_line(width: f64, pt1: Pt2D, pt2: Pt2D) -> (Pt2D, Pt2D) {
let x1 = pt1.x();
let y1 = pt1.y();
let x2 = pt2.x();