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: TrackCountsThe counts of implicit and explicit columns
rows: TrackCountsThe 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
impl CellOccupancyMatrix
Sourcepub fn with_track_counts(columns: TrackCounts, rows: TrackCounts) -> Self
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.
Sourcefn track_lists(&self, track_axis: AbsoluteAxis) -> &[TrackIntervals]
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.
Sourcefn expand_to_fit_range(
&mut self,
row_span: Line<OriginZeroLine>,
col_span: Line<OriginZeroLine>,
)
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
Sourcepub fn mark_area_as(
&mut self,
primary_axis: AbsoluteAxis,
primary_span: Line<OriginZeroLine>,
secondary_span: Line<OriginZeroLine>,
value: CellOccupancyState,
)
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.
Sourcepub fn line_area_collision_jump(
&self,
primary_axis: AbsoluteAxis,
primary_span: Line<OriginZeroLine>,
secondary_span: Line<OriginZeroLine>,
reversed: bool,
) -> Option<OriginZeroLine>
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.
Sourcepub fn occupied_track_jump(
&self,
axis: AbsoluteAxis,
span: Line<OriginZeroLine>,
reversed: bool,
) -> Option<OriginZeroLine>
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).
Sourcepub fn row_is_occupied(&self, row_index: usize) -> bool
pub fn row_is_occupied(&self, row_index: usize) -> bool
Determines whether the specified row contains any items
Sourcepub fn column_is_occupied(&self, column_index: usize) -> bool
pub fn column_is_occupied(&self, column_index: usize) -> bool
Determines whether the specified column contains any items
Sourcepub fn track_counts(&self, track_type: AbsoluteAxis) -> &TrackCounts
pub fn track_counts(&self, track_type: AbsoluteAxis) -> &TrackCounts
Returns the track counts of this CellOccunpancyMatrix in the relevant axis
Sourcepub fn last_of_type(
&self,
track_type: AbsoluteAxis,
start_at: OriginZeroLine,
kind: CellOccupancyState,
) -> Option<OriginZeroLine>
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.
Sourcepub fn first_of_type(
&self,
track_type: AbsoluteAxis,
start_at: OriginZeroLine,
kind: CellOccupancyState,
) -> Option<OriginZeroLine>
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.