Clamp tile spanX to columns in TileGridEngine layout - #25
Merged
Conversation
place(tile:atRow:col:) wrote grid cells using the unclamped tile.size.spanX while the placement loop and canPlace use min(spanX, columns). A tile wider than the grid (e.g. a .large tile in a 2-column grid) wrote past the row end and trapped with an index out of range. snapshot() reported the same unclamped span, so the reported span exceeded the reserved cells. Clamp spanX to columns in both place() and snapshot() so the reserved cells, the written cells, and the reported span agree. No behavior change for the in-app column counts (4/8/12, max tile width 4). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the two multi-line // explanatory comments added in the clamp regression tests to the project's /** ... */ block convention. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
place_tileWiderThanGrid_clampsWithoutCrashing previously asserted only on snapshot().placements.first?.spanX, which snapshot() recomputes from tile.size — so it validated the snapshot() clamp but not the cells place() actually wrote (that was only covered implicitly by "did not trap"). Assert on engine.cells: every row stays within the column count, and a .large tile reserves a full 4x2 block with exactly one origin. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
spanXtocolumnsinsideTileGridEngine.place(tile:atRow:col:)andsnapshot(), matching the placement loop /canPlace, so the cells reserved, the cells written, and the reported span all agree.TileGridEngineClampTestscovering an over-wide tile (.largein a 2-column grid), the single-column case, and the in-app case (.largein a 4-column grid, span unchanged).Why
place()wrote grid cells using the unclampedtile.size.spanXwhile the placement loop andcanPlacealready usedmin(spanX, columns). A tile wider than the grid — e.g. a.largetile (spanX 4) in a 2-column grid — wrote past the row end and trapped with an index-out-of-range.snapshot()reported the same unclamped span, so the reported span exceeded the reserved cells.This is latent in the current app (columns are always 4/8/12 and max tile width is 4, so
spanX <= columnsalways holds) but reachable through the public package API with a narrow column count.Notes
columns >= 4,min(4, columns) == 4.spanYis intentionally left unclamped — the grid grows rows on demand viaensureRows, so there is no vertical out-of-bounds.engine.cellsdirectly (each row stays within the column count; a.largetile reserves a full 4x2 block with one origin), so they lock in theplace()cell-writing fix, not just thesnapshot()value.swift test --package-path Packages/TileGridEngine→ 32 tests pass; app builds clean (xcodebuild build -scheme Hemera).