From e32d71efdbae28e0ca2ff527ffd1c808cb7dcc93 Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Sun, 7 Jan 2024 18:05:14 -0300 Subject: [PATCH] improve 'grid-get-row' Too many redundant calls before. --- src/grid.typ | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/grid.typ b/src/grid.typ index ff1fb36..80289c4 100644 --- a/src/grid.typ +++ b/src/grid.typ @@ -59,7 +59,24 @@ // Fetches an entire row of cells (all positions with the given y). #let grid-get-row(grid, y) = { - range(grid.width).map(x => grid-at(grid, x, y)) + let len = grid.items.len() + // position of the first cell in that row. + let first-row-pos = grid-index-at(0, y, grid: grid) + if len <= first-row-pos { + // grid isn't large enough, so no row to return + (none,) * grid.width + } else { + // position right after the last cell in this row + let next-row-pos = first-row-pos + grid.width + let cell-row = grid.items.slice(first-row-pos, calc.min(len, next-row-pos)) + let cell-row-len = cell-row.len() + if cell-row-len < grid.width { + // the row isn't complete because the grid wasn't large enough. + let missing-cells = (none,) * (grid.width - cell-row-len) + cell-row += missing-cells + } + cell-row + } } // Fetches an entire column of cells (all positions with the given x).