mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +03:00
Incorporate intersection corners in the around-the-block polygon. #230
This commit is contained in:
parent
1b6af3dfb1
commit
c96f84341a
@ -115,7 +115,7 @@ fn glue_to_boundary(result_pl: PolyLine, boundary: &Ring) -> Option<Polygon> {
|
||||
}
|
||||
|
||||
let trimmed_result = result_pl.trim_to_endpts(hits[0], hits[1]);
|
||||
let boundary_glue = boundary.get_shorter_slice_btwn(hits[0], hits[1]);
|
||||
let boundary_glue = boundary.get_shorter_slice_btwn(hits[0], hits[1]).unwrap();
|
||||
|
||||
let mut trimmed_pts = trimmed_result.points().clone();
|
||||
if trimmed_result.last_pt() == boundary_glue.first_pt() {
|
||||
|
@ -808,22 +808,28 @@ fn trace_block(app: &App, start: LaneID) -> Option<Polygon> {
|
||||
let mut visited = HashSet::new();
|
||||
loop {
|
||||
let l = map.get_l(current);
|
||||
if fwd {
|
||||
pts.extend(
|
||||
l.lane_center_pts
|
||||
.shift_left(l.width / 2.0)
|
||||
.unwrap()
|
||||
.into_points(),
|
||||
);
|
||||
let lane_pts = if fwd {
|
||||
l.lane_center_pts.shift_left(l.width / 2.0)
|
||||
} else {
|
||||
pts.extend(
|
||||
l.lane_center_pts
|
||||
.reversed()
|
||||
.shift_left(l.width / 2.0)
|
||||
.unwrap()
|
||||
.into_points(),
|
||||
);
|
||||
l.lane_center_pts.reversed().shift_left(l.width / 2.0)
|
||||
}
|
||||
.unwrap()
|
||||
.into_points();
|
||||
if let Some(last_pt) = pts.last().cloned() {
|
||||
if last_pt != lane_pts[0] {
|
||||
let last_i = if fwd { l.src_i } else { l.dst_i };
|
||||
if let Some(pl) = map
|
||||
.get_i(last_i)
|
||||
.polygon
|
||||
.clone()
|
||||
.into_ring()
|
||||
.get_shorter_slice_btwn(last_pt, lane_pts[0])
|
||||
{
|
||||
pts.extend(pl.into_points());
|
||||
}
|
||||
}
|
||||
}
|
||||
pts.extend(lane_pts);
|
||||
// Imagine pointing down this lane to the intersection. Rotate left -- which road is next?
|
||||
let i = if fwd { l.dst_i } else { l.src_i };
|
||||
println!("{}, fwd={}, pointing to {}", current, fwd, i);
|
||||
@ -853,5 +859,5 @@ fn trace_block(app: &App, start: LaneID) -> Option<Polygon> {
|
||||
}
|
||||
pts.push(pts[0]);
|
||||
pts.dedup();
|
||||
Some(Ring::new(pts).unwrap().to_polygon())
|
||||
Some(Ring::new(pts).ok()?.to_polygon())
|
||||
}
|
||||
|
@ -83,12 +83,16 @@ impl Ring {
|
||||
hits
|
||||
}
|
||||
|
||||
pub fn get_both_slices_btwn(&self, pt1: Pt2D, pt2: Pt2D) -> Option<(PolyLine, PolyLine)> {
|
||||
pub(crate) fn get_both_slices_btwn(
|
||||
&self,
|
||||
pt1: Pt2D,
|
||||
pt2: Pt2D,
|
||||
) -> Option<(PolyLine, PolyLine)> {
|
||||
assert!(pt1 != pt2);
|
||||
let pl = PolyLine::unchecked_new(self.pts.clone());
|
||||
|
||||
let mut dist1 = pl.dist_along_of_point(pt1).unwrap().0;
|
||||
let mut dist2 = pl.dist_along_of_point(pt2).unwrap().0;
|
||||
let mut dist1 = pl.dist_along_of_point(pt1)?.0;
|
||||
let mut dist2 = pl.dist_along_of_point(pt2)?.0;
|
||||
if dist1 > dist2 {
|
||||
std::mem::swap(&mut dist1, &mut dist2);
|
||||
}
|
||||
@ -104,12 +108,12 @@ impl Ring {
|
||||
Some((candidate1, candidate2))
|
||||
}
|
||||
|
||||
pub fn get_shorter_slice_btwn(&self, pt1: Pt2D, pt2: Pt2D) -> PolyLine {
|
||||
let (candidate1, candidate2) = self.get_both_slices_btwn(pt1, pt2).unwrap();
|
||||
pub fn get_shorter_slice_btwn(&self, pt1: Pt2D, pt2: Pt2D) -> Option<PolyLine> {
|
||||
let (candidate1, candidate2) = self.get_both_slices_btwn(pt1, pt2)?;
|
||||
if candidate1.length() < candidate2.length() {
|
||||
candidate1
|
||||
Some(candidate1)
|
||||
} else {
|
||||
candidate2
|
||||
Some(candidate2)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -408,7 +408,9 @@ fn make_shared_sidewalk_corner(
|
||||
|
||||
// TODO Something like this will be MUCH simpler and avoid going around the long way sometimes.
|
||||
if false {
|
||||
return Ring::must_new(i.polygon.points().clone()).get_shorter_slice_btwn(corner1, corner2);
|
||||
return Ring::must_new(i.polygon.points().clone())
|
||||
.get_shorter_slice_btwn(corner1, corner2)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
// The order of the points here seems backwards, but it's because we scan from corner2
|
||||
|
Loading…
Reference in New Issue
Block a user