Compute_grid.Cell_occupancySourceCell occupancy tracking for CSS Grid auto-placement.
Tracks which grid cells are occupied during auto-placement using a dynamically expanding 2D matrix. Maintains counts of implicit and explicit tracks in both axes.
Coordinates use the OriginZero system where negative implicit tracks have negative indices, explicit tracks start at 0, and positive implicit tracks follow the explicit ones.
The matrix expands automatically in all four directions when items are placed outside current bounds. Track counts update accordingly to maintain correct coordinate mappings.
with_track_counts columns rows creates an occupancy matrix with provisional track counts.
is_area_in_range t primary_axis primary_range secondary_range checks if the specified area fits within current matrix bounds.
Ranges are (start, end) pairs in track indices.
expand_to_fit_range t row_range col_range expands the matrix to accommodate the specified ranges, adding implicit tracks as needed.
Algorithm:
Mutates t.inner, t.rows, and t.columns.
val mark_area_as :
t ->
Geometry.Absolute_axis.t ->
int Geometry.Line.t ->
int Geometry.Line.t ->
cell_occupancy_state ->
unitmark_area_as t primary_axis primary_span secondary_span value marks the specified area as occupied, expanding the matrix if necessary.
Spans are in OriginZero line coordinates. Automatically resolves to track ranges and expands the grid if the area extends beyond current bounds. Re-resolves coordinates after expansion since track indices may shift.
val track_area_is_unoccupied :
t ->
Geometry.Absolute_axis.t ->
(int * int) ->
(int * int) ->
booltrack_area_is_unoccupied t primary_axis primary_range secondary_range checks if all cells in the area are unoccupied.
Ranges are (start, end) pairs in track indices. Out-of-bounds cells are treated as unoccupied.
val line_area_is_unoccupied :
t ->
Geometry.Absolute_axis.t ->
int Geometry.Line.t ->
int Geometry.Line.t ->
boolline_area_is_unoccupied t primary_axis primary_span secondary_span checks if all cells in the area are unoccupied.
Spans are in OriginZero line coordinates. Converts to track ranges before checking occupancy.
row_is_occupied t row_index checks if the specified row contains any occupied cells.
Returns false if row_index is out of bounds.
column_is_occupied t column_index checks if the specified column contains any occupied cells.
Returns false if column_index is out of bounds.
track_counts t track_type returns the track counts for the specified axis.
last_of_type t track_type start_at kind searches backwards from the end of the specified track to find the last cell matching kind.
Returns the OriginZero line index of the matching cell, or None if no match is found or the track is out of bounds.