Skip to content

Commit

Permalink
Improve estimate of grid size
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Jan 2, 2023
1 parent 3210220 commit cfec1b8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/compute/grid/implicit_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ pub(crate) fn compute_grid_size_estimate<'a>(
// Compute *track* count estimates for each axis from:
// - The explicit track counts
// - The origin-zero coordinate min and max grid line variables
let negative_implicit_inline_tracks = col_min.unsigned_abs();
let negative_implicit_inline_tracks = col_min.implied_negative_implicit_tracks();
let explicit_inline_tracks = explicit_col_count;
let mut positive_implicit_inline_tracks = max(explicit_col_count, col_max.unsigned_abs()) - explicit_col_count;
let negative_implicit_block_tracks = row_min.unsigned_abs();
let mut positive_implicit_inline_tracks = col_max.implied_positive_implicit_tracks(explicit_col_count);
let negative_implicit_block_tracks = row_min.implied_negative_implicit_tracks();
let explicit_block_tracks = explicit_row_count;
let mut positive_implicit_block_tracks = max(explicit_row_count, row_max.unsigned_abs()) - explicit_row_count;
let mut positive_implicit_block_tracks = row_max.implied_positive_implicit_tracks(explicit_row_count);

// In each axis, adjust positive track estimate if any items have a span that does not fit within
// the total number of tracks in the estimate
Expand Down
18 changes: 16 additions & 2 deletions src/compute/grid/types/coordinates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,22 @@ impl OriginZeroLine {
2 * ((self.0 + track_counts.negative_implicit as i16) as usize)
}

pub(crate) fn unsigned_abs(self) -> u16 {
self.0.unsigned_abs()
/// The minimum number of negative implicit track there must be if a grid item starts at this line.
pub(crate) fn implied_negative_implicit_tracks(self) -> u16 {
if self.0 < 0 {
self.0.unsigned_abs()
} else {
0
}
}

/// The minimum number of positive implicit track there must be if a grid item end at this line.
pub(crate) fn implied_positive_implicit_tracks(self, explicit_track_count: u16) -> u16 {
if self.0 > explicit_track_count as i16 {
self.0 as u16 - explicit_track_count
} else {
0
}
}
}

Expand Down

0 comments on commit cfec1b8

Please sign in to comment.