Skip to main content

CellOccupancyMatrix

Struct CellOccupancyMatrix 

Source
pub(crate) struct CellOccupancyMatrix {
    columns: TrackCounts,
    rows: TrackCounts,
    row_intervals: Vec<TrackIntervals>,
    column_intervals: Vec<TrackIntervals>,
}
Expand description

A dynamically sized matrix (2d grid) which tracks the occupancy of each grid cell during auto-placement. It also keeps tabs on how many tracks there are and which tracks are implicit and which are explicit.

Occupancy is stored sparsely as per-track interval lists (in both orientations), so memory usage is proportional to the number of placed items rather than the total number of grid cells.

Fields§

§columns: TrackCounts

The counts of implicit and explicit columns

§rows: TrackCounts

The counts of implicit and explicit rows

§row_intervals: Vec<TrackIntervals>

For each row track: the occupied intervals within that row (in column coordinates)

§column_intervals: Vec<TrackIntervals>

For each column track: the occupied intervals within that column (in row coordinates)

Implementations§

Source§

impl CellOccupancyMatrix

Source

pub fn with_track_counts(columns: TrackCounts, rows: TrackCounts) -> Self

Create a CellOccupancyMatrix given a set of provisional track counts. The grid can expand as needed to fit more tracks, the provisional track counts represent a best effort attempt to avoid the extra allocations this requires.

Source

fn track_lists(&self, track_axis: AbsoluteAxis) -> &[TrackIntervals]

The per-track interval lists for tracks in the specified axis. Each row track’s intervals are in column coordinates and vice versa.

Source

fn expand_to_fit_range( &mut self, row_span: Line<OriginZeroLine>, col_span: Line<OriginZeroLine>, )

Expands the grid (potentially in all 4 directions) in order to ensure that the specified spans (in OriginZero coordinates) fit within the tracked tracks

Source

pub fn mark_area_as( &mut self, primary_axis: AbsoluteAxis, primary_span: Line<OriginZeroLine>, secondary_span: Line<OriginZeroLine>, value: CellOccupancyState, )

Mark an area of the matrix as occupied, expanding the allocated space as necessary to accommodate the passed area.

Source

pub fn line_area_collision_jump( &self, primary_axis: AbsoluteAxis, primary_span: Line<OriginZeroLine>, secondary_span: Line<OriginZeroLine>, reversed: bool, ) -> Option<OriginZeroLine>

Checks the specified area for occupied cells (primary_span and secondary_span are bounding grid lines in OriginZero coordinates). Returns None if the area is entirely unoccupied. Otherwise returns the next search position (in OriginZero coordinates, along primary_axis) that is not guaranteed to collide with the occupied cells found in the area. This allows the auto-placement search cursor to jump past collisions rather than advancing one track at a time.

Source

pub fn occupied_track_jump( &self, axis: AbsoluteAxis, span: Line<OriginZeroLine>, reversed: bool, ) -> Option<OriginZeroLine>

Given a span of tracks in axis (in OriginZero coordinates), returns the next search position past all non-empty tracks within the span, or None if all tracks within the span are entirely unoccupied. Used to place items which span every track in the other axis (such items can only fit in a stripe of entirely unoccupied tracks).

Source

pub fn row_is_occupied(&self, row_index: usize) -> bool

Determines whether the specified row contains any items

Source

pub fn column_is_occupied(&self, column_index: usize) -> bool

Determines whether the specified column contains any items

Source

pub fn track_counts(&self, track_type: AbsoluteAxis) -> &TrackCounts

Returns the track counts of this CellOccunpancyMatrix in the relevant axis

Source

pub fn last_of_type( &self, track_type: AbsoluteAxis, start_at: OriginZeroLine, kind: CellOccupancyState, ) -> Option<OriginZeroLine>

Given an axis and a track index Search backwards from the end of the track and find the last grid cell matching the specified state (if any) Return the index of that cell or None.

Source

pub fn first_of_type( &self, track_type: AbsoluteAxis, start_at: OriginZeroLine, kind: CellOccupancyState, ) -> Option<OriginZeroLine>

Given an axis and a track index Search forwards from the start of the track and find the first grid cell matching the specified state (if any) Return the index of that cell or None.

Trait Implementations§

Source§

impl Debug for CellOccupancyMatrix

Debug impl that represents the matrix in a compact 2d text format

Source§

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

Formats the value using the given formatter. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

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.