blockfinding

Struct Perimeter

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub(crate) fn restore_invariant(&mut self)

Restore the first=last invariant. Methods may temporarily break this, but must restore it before returning.

Source

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.

Source

pub(crate) fn check_continuity(&self, map: &Map) -> Result<()>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

pub fn to_block(self, map: &Map) -> Result<Block>

Source

pub fn contains(&self, other: &Perimeter) -> bool

Does this perimeter completely enclose the other?

Source

pub fn flip_side_of_road(self) -> Self

Shrinks or expands the perimeter by tracing the opposite side of the road.

Source

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.

Trait Implementations§

Source§

impl Clone for Perimeter

Source§

fn clone(&self) -> Perimeter

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Perimeter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Perimeter

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Perimeter

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

§

fn is_within(&self, b: &G2) -> bool

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,