fix some epsilon issues with deadends and walking turns to get entire

krakow map to import. closes #143
This commit is contained in:
Dustin Carlino 2020-07-06 14:24:31 -07:00
parent cac35319b2
commit fbff30a869
4 changed files with 42 additions and 27 deletions

View File

@ -311,6 +311,13 @@ pub fn make_crosswalk(batch: &mut GeomBatch, turn: &Turn, map: &Map, cs: &ColorS
let line = {
// The middle line in the crosswalk geometry is the main crossing line.
let pts = turn.geom.points();
if pts.len() < 3 {
println!(
"Not rendering crosswalk for {}; its geometry was squished earlier",
turn.id
);
return;
}
Line::new(pts[1], pts[2])
};

View File

@ -89,6 +89,12 @@ impl PolyLine {
PolyLine { pts, length }
}
// First dedupes adjacent points. If the result is only 1 point, will panic.
pub fn deduping_new(mut pts: Vec<Pt2D>) -> PolyLine {
pts.dedup();
PolyLine::new(pts)
}
pub fn to_thick_boundary(
&self,
self_width: Distance,

View File

@ -360,30 +360,32 @@ fn deadend(
let pt2 = pl_b.reversed().safe_dist_along(len).map(|(pt, _)| pt);
if let (Some(pt1), Some(pt2)) = (pt1, pt2) {
let r = roads.get_mut(&id).unwrap();
if r.src_i == i {
r.trimmed_center_pts = r
.trimmed_center_pts
.exact_slice(len, r.trimmed_center_pts.length());
} else {
r.trimmed_center_pts = r
.trimmed_center_pts
.exact_slice(Distance::ZERO, r.trimmed_center_pts.length() - len);
}
if r.trimmed_center_pts.length() >= len + 3.0 * geom::EPSILON_DIST {
if r.src_i == i {
r.trimmed_center_pts = r
.trimmed_center_pts
.exact_slice(len, r.trimmed_center_pts.length());
} else {
r.trimmed_center_pts = r
.trimmed_center_pts
.exact_slice(Distance::ZERO, r.trimmed_center_pts.length() - len);
}
(
close_off_polygon(vec![pt1, pt2, pl_b.last_pt(), pl_a.last_pt()]),
Vec::new(),
)
} else {
timer.warn(format!(
"{} is a dead-end for {}, which is too short to make degenerate intersection geometry",
i, id
));
(
vec![pl_a.last_pt(), pl_b.last_pt(), pl_a.last_pt()],
Vec::new(),
)
return (
close_off_polygon(vec![pt1, pt2, pl_b.last_pt(), pl_a.last_pt()]),
Vec::new(),
);
}
}
timer.warn(format!(
"{} is a dead-end for {}, which is too short to make degenerate intersection geometry",
i, id
));
(
vec![pl_a.last_pt(), pl_b.last_pt(), pl_a.last_pt()],
Vec::new(),
)
}
fn close_off_polygon(mut pts: Vec<Pt2D>) -> Vec<Pt2D> {

View File

@ -450,7 +450,7 @@ fn make_crosswalks(i: IntersectionID, l1: &Lane, l2: &Lane) -> Vec<Turn> {
// Jut out a bit into the intersection, cross over, then jut back in. Assumes sidewalks are the
// same width.
let line = Line::new(l1_pt, l2_pt).shift_either_direction(direction * l1.width / 2.0);
let geom_fwds = PolyLine::new(vec![l1_pt, line.pt1(), line.pt2(), l2_pt]);
let geom_fwds = PolyLine::deduping_new(vec![l1_pt, line.pt1(), line.pt2(), l2_pt]);
vec![
Turn {
@ -499,25 +499,25 @@ fn make_degenerate_crosswalks(
id: turn_id(i, l1_in.id, l1_out.id),
turn_type: TurnType::Crosswalk,
other_crosswalk_ids: all_ids.clone(),
geom: PolyLine::new(vec![l1_in.last_pt(), pt1, pt2, l1_out.first_pt()]),
geom: PolyLine::deduping_new(vec![l1_in.last_pt(), pt1, pt2, l1_out.first_pt()]),
},
Turn {
id: turn_id(i, l1_out.id, l1_in.id),
turn_type: TurnType::Crosswalk,
other_crosswalk_ids: all_ids.clone(),
geom: PolyLine::new(vec![l1_out.first_pt(), pt2, pt1, l1_in.last_pt()]),
geom: PolyLine::deduping_new(vec![l1_out.first_pt(), pt2, pt1, l1_in.last_pt()]),
},
Turn {
id: turn_id(i, l2_in.id, l2_out.id),
turn_type: TurnType::Crosswalk,
other_crosswalk_ids: all_ids.clone(),
geom: PolyLine::new(vec![l2_in.last_pt(), pt2, pt1, l2_out.first_pt()]),
geom: PolyLine::deduping_new(vec![l2_in.last_pt(), pt2, pt1, l2_out.first_pt()]),
},
Turn {
id: turn_id(i, l2_out.id, l2_in.id),
turn_type: TurnType::Crosswalk,
other_crosswalk_ids: all_ids.clone(),
geom: PolyLine::new(vec![l2_out.first_pt(), pt1, pt2, l2_in.last_pt()]),
geom: PolyLine::deduping_new(vec![l2_out.first_pt(), pt1, pt2, l2_in.last_pt()]),
},
]
.into_iter()