mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-23 17:07:12 +03:00
Draw filtered streets with two colors when there's a filter on them.
This actually revealed that find_cells was a bit wrong -- when a filter is in the middle of a cell, one half of it wasn't assigned anywhere
This commit is contained in:
parent
bffa469396
commit
b8f4550824
@ -1,5 +1,3 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use geom::Distance;
|
||||
use widgetry::mapspace::World;
|
||||
use widgetry::{
|
||||
@ -136,18 +134,16 @@ fn make_world(
|
||||
} else {
|
||||
let mut draw = GeomBatch::new();
|
||||
let mut debug_cell_borders = GeomBatch::new();
|
||||
let mut seen_roads = HashSet::new();
|
||||
for (idx, cell) in neighborhood.cells.iter().enumerate() {
|
||||
let color = super::draw_cells::COLORS[idx % super::draw_cells::COLORS.len()].alpha(0.9);
|
||||
for r in cell.roads.keys() {
|
||||
// TODO Roads with a filter belong to two cells. The drawn form (and the
|
||||
// intersections included) needs to be adjusted to use two colors.
|
||||
if seen_roads.contains(r) {
|
||||
continue;
|
||||
}
|
||||
seen_roads.insert(*r);
|
||||
|
||||
draw.push(color, map.get_r(*r).get_thick_polygon());
|
||||
for (r, interval) in &cell.roads {
|
||||
let road = map.get_r(*r);
|
||||
draw.push(
|
||||
color,
|
||||
road.center_pts
|
||||
.exact_slice(interval.start, interval.end)
|
||||
.make_polygons(road.get_width()),
|
||||
);
|
||||
}
|
||||
for i in
|
||||
crate::common::intersections_from_roads(&cell.roads.keys().cloned().collect(), map)
|
||||
|
@ -82,9 +82,9 @@ pub struct DiagonalFilter {
|
||||
|
||||
/// A partitioning of the interior of a neighborhood based on driving connectivity
|
||||
pub struct Cell {
|
||||
/// Most roads are fully in one cell. Roads with modal filters on them are split between two
|
||||
/// cells, and the DistanceInterval indicates the split. The distances are over the road's
|
||||
/// center line length.
|
||||
/// Most roads are fully in one cell. Roads with modal filters on them are sometimes split
|
||||
/// between two cells, and the DistanceInterval indicates the split. The distances are over the
|
||||
/// road's center line length.
|
||||
pub roads: BTreeMap<RoadID, DistanceInterval>,
|
||||
/// Intersections where this cell touches the boundary of the neighborhood.
|
||||
pub borders: BTreeSet<IntersectionID>,
|
||||
@ -297,9 +297,9 @@ fn floodfill(
|
||||
neighborhood_borders: &BTreeSet<IntersectionID>,
|
||||
modal_filters: &ModalFilters,
|
||||
) -> Cell {
|
||||
// We don't need a priority queue
|
||||
let mut visited_roads: BTreeMap<RoadID, DistanceInterval> = BTreeMap::new();
|
||||
let mut cell_borders = BTreeSet::new();
|
||||
// We don't need a priority queue
|
||||
let mut queue = vec![start];
|
||||
|
||||
// The caller should handle this case
|
||||
@ -331,20 +331,32 @@ fn floodfill(
|
||||
}
|
||||
}
|
||||
if let Some(filter_dist) = modal_filters.roads.get(next) {
|
||||
// Which end of the filtered road have we reached?
|
||||
let next_road = map.get_r(*next);
|
||||
// Which ends of the filtered road have we reached?
|
||||
let mut visited_start = next_road.src_i == i;
|
||||
let mut visited_end = next_road.dst_i == i;
|
||||
// We may have visited previously from the other side.
|
||||
if let Some(interval) = visited_roads.get(next) {
|
||||
if interval.start == Distance::ZERO {
|
||||
visited_start = true;
|
||||
}
|
||||
if interval.end == next_road.length() {
|
||||
visited_end = true;
|
||||
}
|
||||
}
|
||||
visited_roads.insert(
|
||||
*next,
|
||||
if next_road.src_i == i {
|
||||
DistanceInterval {
|
||||
start: Distance::ZERO,
|
||||
end: *filter_dist,
|
||||
}
|
||||
} else {
|
||||
DistanceInterval {
|
||||
start: *filter_dist,
|
||||
end: next_road.length(),
|
||||
}
|
||||
DistanceInterval {
|
||||
start: if visited_start {
|
||||
Distance::ZERO
|
||||
} else {
|
||||
*filter_dist
|
||||
},
|
||||
end: if visited_end {
|
||||
next_road.length()
|
||||
} else {
|
||||
*filter_dist
|
||||
},
|
||||
},
|
||||
);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user