WIP new simple idea for intersection geometry

This commit is contained in:
Dustin Carlino 2019-01-10 08:31:03 -08:00
parent 0522829d9a
commit 087e3ad492
3 changed files with 40 additions and 7 deletions

View File

@ -149,11 +149,11 @@ pub fn make_half_map(
i.polygon = make::intersections::initial_intersection_polygon(i, &m.roads); i.polygon = make::intersections::initial_intersection_polygon(i, &m.roads);
} }
timer.start_iter("trim lanes at each intersection", m.intersections.len()); /*timer.start_iter("trim lanes at each intersection", m.intersections.len());
for i in &m.intersections { for i in &m.intersections {
timer.next(); timer.next();
make::trim_lines::trim_lines(&mut m.lanes, i); make::trim_lines::trim_lines(&mut m.lanes, i);
} }*/
for i in m.intersections.iter_mut() { for i in m.intersections.iter_mut() {
for t in for t in
@ -171,13 +171,13 @@ pub fn make_half_map(
} }
// Recalculate all intersection polygons again, using the lanes' "teeth" this time. // Recalculate all intersection polygons again, using the lanes' "teeth" this time.
for i in m.intersections.iter_mut() { /*for i in m.intersections.iter_mut() {
if i.incoming_lanes.is_empty() && i.outgoing_lanes.is_empty() { if i.incoming_lanes.is_empty() && i.outgoing_lanes.is_empty() {
panic!("{:?} is orphaned!", i); panic!("{:?} is orphaned!", i);
} }
i.polygon = make::intersections::toothy_intersection_polygon(i, &m.lanes); i.polygon = make::intersections::toothy_intersection_polygon(i, &m.lanes);
} }*/
m m
} }

View File

@ -13,8 +13,9 @@ const DEGENERATE_INTERSECTION_HALF_LENGTH: si::Meter<f64> = si::Meter {
// carves up part of that space, doesn't reach past it. // carves up part of that space, doesn't reach past it.
pub fn initial_intersection_polygon(i: &Intersection, roads: &Vec<Road>) -> Vec<Pt2D> { pub fn initial_intersection_polygon(i: &Intersection, roads: &Vec<Road>) -> Vec<Pt2D> {
// Turn all of the incident roads into two PolyLines (the "forwards" and "backwards" borders of // Turn all of the incident roads into two PolyLines (the "forwards" and "backwards" borders of
// the road), both ending at the intersection (which may be different points for merged // the road, if the roads were oriented to both be incoming to the intersection), both ending
// intersections!), and the angle of the last segment of the center line. // at the intersection (which may be different points for merged intersections!), and the angle
// of the last segment of the center line.
let mut lines: Vec<(RoadID, Angle, PolyLine, PolyLine)> = i let mut lines: Vec<(RoadID, Angle, PolyLine, PolyLine)> = i
.roads .roads
.iter() .iter()
@ -91,6 +92,37 @@ pub fn initial_intersection_polygon(i: &Intersection, roads: &Vec<Road>) -> Vec<
]); ]);
} }
} else { } else {
// Find the two corners of each road
let mut ok = true;
for idx in 0..lines.len() as isize {
let (id, _, fwd_pl, back_pl) = wraparound_get(&lines, idx);
let (_, _, adj_back_pl, _) = wraparound_get(&lines, idx + 1);
let (_, _, _, adj_fwd_pl) = wraparound_get(&lines, idx - 1);
// Which hit is farther back along the original line?
// TODO Why are intersections not working with dist_along? :(
let dist1 = if let Some(dist) = fwd_pl.intersection(adj_fwd_pl).and_then(|hit| fwd_pl.dist_along_of_point(hit)) {
dist
} else {
ok = false;
break;
};
let dist2 = if let Some(dist) = back_pl.intersection(adj_back_pl).and_then(|hit| back_pl.dist_along_of_point(hit)) {
dist
} else {
ok = false;
break;
};
let dist = if dist1 <= dist2 { dist1 } else { dist2 };
// Trim back the road center points based on the smaller distance, and use that as the
// endpoints.
endpoints.push(fwd_pl.dist_along(dist).0);
endpoints.push(back_pl.dist_along(dist).0);
}
if !ok {
endpoints.clear();
// Look at adjacent pairs of these polylines... // Look at adjacent pairs of these polylines...
for idx1 in 0..lines.len() as isize { for idx1 in 0..lines.len() as isize {
let idx2 = idx1 + 1; let idx2 = idx1 + 1;
@ -142,6 +174,7 @@ pub fn initial_intersection_polygon(i: &Intersection, roads: &Vec<Road>) -> Vec<
); );
} }
} }
}
} }
// Close off the polygon // Close off the polygon

View File

@ -77,7 +77,7 @@ impl ControlTrafficSignal {
assert!(!cycle.yield_turns.contains(&t.id)); assert!(!cycle.yield_turns.contains(&t.id));
} }
TurnType::SharedSidewalkCorner => { TurnType::SharedSidewalkCorner => {
assert!(cycle.priority_turns.contains(&t.id)); //assert!(cycle.priority_turns.contains(&t.id));
} }
_ => {} _ => {}
} }