force some intersections with similar angles between incident roads to use the line projection fix too. now things are looking great mostly \o/
@@ -10,6 +10,7 @@ pub fn intersection_polygon(
// Turn all of the incident roads into the center PolyLine, always pointing at the intersection
// (endpoint is pt). The f64's are the width to shift without transforming the points, and then
// the width to shift when reversing the points.
+ // TODO Simplify code by just stashing the two transformed PolyLines here. ;)
let mut center_lines: Vec<(PolyLine, RoadID, f64, f64)> = road_ids
.into_iter()
.map(|id| {
@@ -48,9 +49,19 @@ pub fn intersection_polygon(
.reversed();
let pl2 = center2.shift(*width2_normal).unwrap();
+ // If the two lines are too close in angle, they'll either not hit or even if they do, it
+ // won't be right.
+ let angle_diff = (pl1.last_line().angle().opposite().normalized_degrees()
+ - pl2.last_line().angle().normalized_degrees()).abs();
+
+ if angle_diff > 5.0 {
+ // The easy case!
if let Some(hit) = pl1.intersection(&pl2) {
endpoints.push(hit);
- } else {
+ continue;
+ }
+ }
+
let mut ok = true;
// Use the next adjacent road, doing line to line segment intersection instead.
@@ -91,7 +102,6 @@ pub fn intersection_polygon(
);
}
}
- }
// Close off the polygon
let first_pt = endpoints[0].clone();
