pub struct Perimeter {
pub roads: Vec<RoadSideID>,
pub interior: BTreeSet<RoadID>,
}
Expand description
A sequence of roads in order, beginning and ending at the same place. No “crossings” – tracing along this sequence should geometrically yield a simple polygon.
Fields§
§roads: Vec<RoadSideID>
§interior: BTreeSet<RoadID>
These roads exist entirely within the perimeter
Implementations§
Source§impl Perimeter
impl Perimeter
Sourcepub fn single_block(
map: &Map,
start: LaneID,
skip: &HashSet<RoadID>,
) -> Result<Perimeter>
pub fn single_block( map: &Map, start: LaneID, skip: &HashSet<RoadID>, ) -> Result<Perimeter>
Starting at any lane, snap to the nearest side of that road, then begin tracing a single
block, with no interior roads. This will fail if a map boundary is reached. The results are
unusual when crossing the entrance to a tunnel or bridge, and so skip
is used to avoid
tracing there.
Sourcepub fn find_all_single_blocks(map: &Map) -> Vec<Perimeter>
pub fn find_all_single_blocks(map: &Map) -> Vec<Perimeter>
This calculates all single block perimeters for the entire map. The resulting list does not cover roads near the map boundary.
Sourcepub fn find_roads_to_skip_tracing(map: &Map) -> HashSet<RoadID>
pub fn find_roads_to_skip_tracing(map: &Map) -> HashSet<RoadID>
Blockfinding is specialized for the LTN tool, so non-driveable roads (cycleways and light rail) are considered invisible and can’t be on a perimeter. Previously, there were also some heuristics here to try to skip certain bridges/tunnels that break the planarity of blocks.
Sourcepub(crate) fn undo_invariant(&mut self)
pub(crate) fn undo_invariant(&mut self)
A perimeter has the first and last road matching up, but that’s confusing to work with. Temporarily undo that.
Sourcepub(crate) fn restore_invariant(&mut self)
pub(crate) fn restore_invariant(&mut self)
Restore the first=last invariant. Methods may temporarily break this, but must restore it before returning.
Sourcepub(crate) fn try_to_merge(
&mut self,
map: &Map,
other: &mut Perimeter,
debug_failures: bool,
) -> Result<()>
pub(crate) fn try_to_merge( &mut self, map: &Map, other: &mut Perimeter, debug_failures: bool, ) -> Result<()>
Try to merge two blocks. This’ll only succeed when the blocks are adjacent, but the merge wouldn’t create an interior “hole”.
Note this always modifies both perimeters, even upon failure. The caller should copy the input and only use the output upon success.
pub(crate) fn check_continuity(&self, map: &Map) -> Result<()>
Sourcepub(crate) fn reverse_to_fix_winding_order(
&self,
map: &Map,
other: &Perimeter,
) -> bool
pub(crate) fn reverse_to_fix_winding_order( &self, map: &Map, other: &Perimeter, ) -> bool
Should we reverse one perimeter to match the winding order?
This is only meant to be called in the middle of try_to_merge. It assumes both perimeters have already been rotated so the common roads are at the end. The invariant of first=last is not true.
Sourcepub fn merge_all(
map: &Map,
input: Vec<Perimeter>,
stepwise_debug: bool,
) -> Vec<Perimeter>
pub fn merge_all( map: &Map, input: Vec<Perimeter>, stepwise_debug: bool, ) -> Vec<Perimeter>
Try to merge all given perimeters. If successful, only one perimeter will be returned.
Perimeters are never “destroyed” – if not merged, they’ll appear in the results. If
stepwise_debug
is true, returns after performing just one merge.
Sourcepub fn collapse_deadends(&mut self)
pub fn collapse_deadends(&mut self)
If the perimeter follows any dead-end roads, “collapse” them and instead make the perimeter contain the dead-end.
Sourcepub fn partition_by_predicate<F: Fn(RoadID) -> bool>(
input: Vec<Perimeter>,
predicate: F,
) -> Vec<Vec<Perimeter>>
pub fn partition_by_predicate<F: Fn(RoadID) -> bool>( input: Vec<Perimeter>, predicate: F, ) -> Vec<Vec<Perimeter>>
Consider the perimeters as a graph, with adjacency determined by sharing any road in common.
Partition adjacent perimeters, subject to the predicate. Each partition should produce a
single result with merge_all
.
Sourcepub fn calculate_coloring(
input: &[Perimeter],
num_colors: usize,
) -> Option<Vec<usize>>
pub fn calculate_coloring( input: &[Perimeter], num_colors: usize, ) -> Option<Vec<usize>>
Assign each perimeter one of num_colors
, such that no two adjacent perimeters share the
same color. May fail. The resulting colors are expressed as [0, num_colors)
.
pub fn to_block(self, map: &Map) -> Result<Block>
Sourcepub fn contains(&self, other: &Perimeter) -> bool
pub fn contains(&self, other: &Perimeter) -> bool
Does this perimeter completely enclose the other?
Sourcepub fn flip_side_of_road(self) -> Self
pub fn flip_side_of_road(self) -> Self
Shrinks or expands the perimeter by tracing the opposite side of the road.
Sourcepub fn merge_holes(map: &Map, perims: Vec<Perimeter>) -> Vec<Perimeter>
pub fn merge_holes(map: &Map, perims: Vec<Perimeter>) -> Vec<Perimeter>
Looks for perimeters that’re completely surrounded by other perimeters, aka, holes. Attempts to merge them with the surrounding perimeter. This can be useful for applications trying to incrementally merge adjacent blocks without creating splits, because it’s often impossible to do this in one merge when there are holes.
This should never “lose” any of the input. It may not be fast or guaranteed to find and fix every hole.