package toffee
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/compute_grid/Compute_grid/Cell_occupancy/index.html
Module Compute_grid.Cell_occupancySource
Cell 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.
Grid Expansion
The matrix expands automatically in all four directions when items are placed outside current bounds. Track counts update accordingly to maintain correct coordinate mappings.
Key Invariants
- Out-of-bounds cells are treated as unoccupied
- Track counts must accurately reflect the matrix dimensions after expansion
- Coordinate conversions depend on track counts being synchronized with matrix size
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:
- Calculate required expansion in all four directions
- Allocate new matrix with expanded dimensions
- Copy existing cells with offset for negative expansion
- Update track counts to reflect new implicit tracks
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.