Skip to content

windowstead #70: Extract layout math and add dock/regression tests - #73

Merged
itsmiso-ai merged 1 commit into
mainfrom
fix/issue-70-dock-layout-regression-tests
Apr 20, 2026
Merged

windowstead #70: Extract layout math and add dock/regression tests#73
itsmiso-ai merged 1 commit into
mainfrom
fix/issue-70-dock-layout-regression-tests

Conversation

@itsmiso-ai

Copy link
Copy Markdown
Contributor

Fixes #70.

Extract pure dock/layout math from main.gd into scripts/layout_math.gd so layout logic can be tested directly without requiring a full scene or DisplayServer access.

Changes

New file: scripts/layout_math.gd — pure static math functions:

  • tile_px_for_anchor() — square tile size per anchor + zoom
  • world_pixel_size() — world panel dimensions
  • grid_dims_for_anchor() — grid width/height per anchor
  • dock_padding_for_anchor() — padding per anchor
  • dock_size_for_anchor() — full window size
  • dock_position_for_anchor() — window position within screen
  • popup_position_for_anchor() — sidebar panel position
  • popup_within_bounds() — bounds checking helper
  • anchor_family_from_dock_anchor() — anchor string mapping
  • stockpile_pos_for_anchor() — stockpile position per anchor

New file: tests/test_layout_math.gd — 22 deterministic regression tests:

  • Anchor family selection (bottom → bottom, side → vertical)
  • Tile sizing at zoom 1.0, 0.5, 2.0 and floor at 1
  • Grid dimensions for both anchor families
  • World pixel size math (exact values verified)
  • Dock padding correctness
  • Dock size includes sidebar in bottom mode, excludes in vertical
  • Dock position: bottom-centered, left-bottom, right-bottom
  • Popup position: top-right (bottom/right), top-left (left)
  • Popup bounds: in-bounds at normal/max zoom, out-of-bounds when sidebar exceeds screen
  • Stockpile positions
  • Anchor swap round-trips

Modified: scripts/main.gd — delegates all layout math to LayoutMath (18 insertions, 43 deletions — net shrink).

Run tests

godot --headless --quit --main-pack windowstead.pck --script tests/test_layout_math.gd

Part of #70 — more regression tests can be added for specific known failures (issues #40, #52, #53, #54) as they're identified.

- Extract pure dock/layout math from main.gd into layout_math.gd
  for deterministic testing without DisplayServer or scene nodes
- Add 22 regression tests covering:
  - anchor family selection (bottom vs vertical)
  - tile sizing with zoom scaling
  - grid dimensions per anchor
  - world panel size calculations
  - dock padding and window size
  - dock position for left/bottom/right anchors
  - popup sidebar positioning and bounds checking
  - stockpile position per anchor
  - anchor swap round-trips
- Wire main.gd to use LayoutMath for all layout calculations

Part of #70: Add deterministic regression tests for dock and layout behavior
@smurf-bot

smurf-bot Bot commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Automated recommendation: APPROVE

Analysis engine: MiniMax-M2.7@https://api.minimax.io/v1

PR Review: Extract layout math and add dock/regression tests (PR #73)

Recommendation: Approve

This PR cleanly extracts pure layout geometry math from main.gd into a testable static module (layout_math.gd) and adds 22 deterministic regression tests. The net change is a code reduction in main.gd (-43 deletions, +18 insertions = -25 net lines) with no behavioral changes.


Change-by-Change Findings

1. scripts/layout_math.gd (new, 124 lines)

  • Purpose: Pure static math functions with no Godot node dependencies, enabling headless test execution
  • Constants correctly extracted: Grid dimensions (7×16 side, 30×5 bottom), tile sizing (40px/48px base), gaps (6px), bump factor (1.15), padding vectors, sidebar width (220)
  • Functions verified correct:
    • tile_px_for_anchor(): Returns square int via maxi(1, int(round(...))) — floor at 1 enforced
    • world_pixel_size(): Standard grid×tile + (gap×(count-1)) formula
    • grid_dims_for_anchor(): Returns Dictionary with grid_w/grid_h
    • dock_size_for_anchor(): Bottom mode includes sidebar+16; vertical excludes sidebar — matches original logic
    • dock_position_for_anchor(): left/bottom/right anchoring with 12px offset from edges
    • popup_position_for_anchor(): bottom→top-right, right→clamped top-right, left→top-left
    • popup_within_bounds(): 4-way bounds check (left/top ≤ corner ≤ right/bottom)
    • tile_is_square(): Returns true by construction — trivially correct
  • Regression targets documented: Issues Fix vertical dock width to match tile column geometry #40, Make dock span the full anchored edge #52, Fix tiles rendering taller than they are wide #53, Fix menu popup being clipped or inaccessible inside the dock #54

2. scripts/main.gd (modified, +18/-43)

  • Pattern: All layout math delegates to LayoutMath static functions
  • Preload added: const LayoutMath := preload("res://scripts/layout_math.gd")
  • Key delegation changes:
    • tile_px_for_anchor(): Now passes zoom from settings to LayoutMath
    • apply_anchor_geometry(): Uses anchor_family_from_dock_anchor() + grid_dims_for_anchor() + stockpile_pos_for_anchor()
    • dock_padding_for_anchor(): Now uses anchor_family variable instead of raw dock_anchor parameter
    • dock_size_for_anchor(): Uses anchor_family, passes grid_w, grid_h, tile_size.x
    • dock_position_for_anchor(): Unpacks usable_rect into 4 parameters for LayoutMath call
  • No behavioral changes detected — logic is identical, only refactored to delegation

3. tests/test_layout_math.gd (new, 273 lines)

  • Test framework: Custom pass/fail counter with assert() calls inside void functions
  • 22 tests covering:
    • Anchor family mapping (bottom→bottom, side→vertical)
    • Tile sizing at zoom 1.0/0.5/2.0 with exact expected values (46, 23, 92)
    • Tile floor at 1 for very small zoom (0.01)
    • Grid dimensions (bottom: 30×5, vertical: 7×16)
    • World pixel size math with exact values (1554×254 bottom, 421×970 vertical)
    • Dock padding constants
    • Dock size includes sidebar in bottom mode, excludes in vertical
    • Dock positions: centered bottom, bottom-left left, bottom-right right
    • Popup positions: top-right (bottom/right), top-left (left)
    • Popup bounds checking (in-bounds normal, in-bounds max zoom, out-of-bounds overflow)
    • Stockpile positions: (11,2) bottom, (2,7) vertical
    • Integration: anchor swap changes grid dims and tile sizes
  • Math verification: All arithmetic verified against stated formulas
    • 40.0 * 1.15 = 46.0
    • 48.0 * 1.15 = 55.2 → round to 55
    • 30 * 46 + 29 * 6 = 1554
    • 5 * 46 + 4 * 6 = 254

Standards Compliance

No AGENTS.md or repository standards file was present in the corpus to check against. However, the PR aligns with documented conventions:

  • Extraction for testability: Following the repo's established pattern of isolating logic for testing
  • No DisplayServer dependency: Tests run headless without scene requirements
  • Deterministic tests: All values are exact or use explicit comparison operators
  • Clear documentation: Docstrings explain purpose, regression targets, and usage
  • Net code reduction: main.gd shrinks by 25 net lines while adding comprehensive tests

Unknowns / Needs Verification

None. The PR has complete evidence:

  • All 3 files reviewed in full
  • All arithmetic verified against source formulas
  • All function signatures match between LayoutMath and main.gd delegations
  • Constants are consistent between extracted module and original location
  • Test command provided in PR body is appropriate for headless execution

@itsmiso-ai
itsmiso-ai merged commit fdf21a6 into main Apr 20, 2026
2 checks passed
@itsmiso-ai
itsmiso-ai deleted the fix/issue-70-dock-layout-regression-tests branch April 20, 2026 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add deterministic regression tests for dock and layout behavior

1 participant