## T-1142 (Jeroen's second/third hands-on findings): pure-function tests for ## AtlasWindowViewer's fit-and-center math (fit_window_view) and pole-wall ## pan clamp (clamp_pan_offset_to_pole_wall) — both extracted specifically so ## the "viewport + n -> zoom/offset" transform is unit-testable without a ## live Control tree. class_name TestAtlasWindowGeometry extends GdUnitTestSuite const AtlasWindowGeometry := preload("res://ui/implant/apps/atlas/atlas_window_geometry.gd") const AtlasDescendGeometry := preload("res://ui/implant/apps/atlas/atlas_descend_geometry.gd") const MIN_ZOOM: float = 0.5 const MAX_ZOOM: float = 8.0 const CELL_PIXEL_SIZE: float = 16.0 # ============================================================================= # fit_window_view — the "postage stamp" fix (item 2) # ============================================================================= ## n=32, cell_px=16 -> native composite is 512x512. T-1145 item 1: COVER ## fit derives zoom from the LARGER viewport dimension (1920, not 1080) with ## NO margin factor — zoom = 1920 / 512 = 3.75 — well inside [MIN_ZOOM, ## MAX_ZOOM], so the clamp is a no-op here. func test_fit_window_view_computes_expected_zoom_for_a_wide_viewport() -> void: var fit: Dictionary = AtlasWindowGeometry.fit_window_view( Vector2(1920.0, 1080.0), 32, CELL_PIXEL_SIZE, MIN_ZOOM, MAX_ZOOM ) var expected_zoom: float = 1920.0 / 512.0 assert_float(fit["zoom"]).is_equal_approx(expected_zoom, 0.001) ## The composite must be CENTERED — offset.x/.y each leave an equal margin on ## both sides of the (n*cell_px*zoom)-sized composite (a NEGATIVE "margin" is ## fine and expected under cover — it just means the composite overhangs ## that axis, checked separately by test_fit_window_view_covers_with_no_gap). func test_fit_window_view_centers_the_composite() -> void: var viewport := Vector2(1920.0, 1080.0) var fit: Dictionary = AtlasWindowGeometry.fit_window_view( viewport, 32, CELL_PIXEL_SIZE, MIN_ZOOM, MAX_ZOOM ) var composite_scaled: float = 32.0 * CELL_PIXEL_SIZE * float(fit["zoom"]) var offset: Vector2 = fit["offset"] # The composite's right/bottom edge is offset + composite_scaled — the # margin on the far side must equal the margin on the near side (offset). var right_margin: float = viewport.x - (offset.x + composite_scaled) var bottom_margin: float = viewport.y - (offset.y + composite_scaled) assert_float(right_margin).is_equal_approx(offset.x, 0.01) assert_float(bottom_margin).is_equal_approx(offset.y, 0.01) ## T-1145 item 1 (Jeroen's round-2 finding, KALLAST window): a wide viewport ## must show NO side margins — the composite's LONG axis (the one the cover ## zoom is derived from) must land EXACTLY at the viewport edges (offset ~= ## 0 on that axis), and the SHORT axis must OVERHANG past both edges ## (negative margin — the composite is bigger than the viewport there, ## exactly what "cover" means). This is the literal assertion the coordinator ## asked for: no side margins at 16:9. func test_fit_window_view_covers_with_no_gap_on_the_long_axis() -> void: var viewport := Vector2(1920.0, 1080.0) var fit: Dictionary = AtlasWindowGeometry.fit_window_view( viewport, 32, CELL_PIXEL_SIZE, MIN_ZOOM, MAX_ZOOM ) var composite_scaled: float = 32.0 * CELL_PIXEL_SIZE * float(fit["zoom"]) var offset: Vector2 = fit["offset"] # Long axis (X, 1920 > 1080): the composite must span EXACTLY the # viewport width — zero margin on both sides. assert_float(offset.x).override_failure_message( "the long (cover) axis must have NO side margin — offset.x should be ~0" ).is_equal_approx(0.0, 0.5) var right_margin: float = viewport.x - (offset.x + composite_scaled) assert_float(right_margin).override_failure_message( "the long (cover) axis's far edge must have NO margin either" ).is_equal_approx(0.0, 0.5) # Short axis (Y, 1080 < 1920): the composite must OVERHANG (negative # margin) past BOTH edges — this is the data that extends into pan-space. assert_float(offset.y).override_failure_message( "the short axis must OVERHANG past the top edge (negative offset)" ).is_less(0.0) ## A TALL viewport (portrait) must cover the same way, just with the axes ## swapped — long axis (Y) gets zero margin, short axis (X) overhangs. func test_fit_window_view_covers_a_tall_viewport_too() -> void: var viewport := Vector2(1080.0, 1920.0) var fit: Dictionary = AtlasWindowGeometry.fit_window_view( viewport, 32, CELL_PIXEL_SIZE, MIN_ZOOM, MAX_ZOOM ) var offset: Vector2 = fit["offset"] assert_float(offset.y).override_failure_message( "the long (cover) axis (Y, portrait) must have NO side margin" ).is_equal_approx(0.0, 0.5) assert_float(offset.x).override_failure_message( "the short axis (X, portrait) must overhang past the left edge" ).is_less(0.0) ## A perfectly square viewport needs NO overhang on either axis — cover and ## contain agree exactly at a 1:1 aspect ratio (the degenerate case where ## "long" and "short" axis are the same). func test_fit_window_view_square_viewport_has_no_overhang_either_axis() -> void: var fit: Dictionary = AtlasWindowGeometry.fit_window_view( Vector2(1024.0, 1024.0), 32, CELL_PIXEL_SIZE, MIN_ZOOM, MAX_ZOOM ) assert_vector(fit["offset"]).is_equal_approx(Vector2.ZERO, Vector2(0.5, 0.5)) ## Jeroen's exact bug: an n=32 composite (512px native) in a real ~1920px ## viewport must NOT render at zoom=1.0 (the old, unfitted "postage stamp" ## behavior) — the fit must scale it up to fill (now: COVER) the viewport. func test_fit_window_view_scales_up_a_small_composite_to_fill_the_viewport() -> void: var fit: Dictionary = AtlasWindowGeometry.fit_window_view( Vector2(1920.0, 1080.0), 32, CELL_PIXEL_SIZE, MIN_ZOOM, MAX_ZOOM ) assert_float(fit["zoom"]).override_failure_message( "a 512px composite in a 1920x1080 viewport must be scaled UP, not left at 1.0" ).is_greater(1.0) ## A huge n (e.g. n=64 at a tiny viewport) must clamp to MIN_ZOOM, never ## shrink the composite into illegibility below the floor. func test_fit_window_view_clamps_to_min_zoom_for_a_tiny_viewport() -> void: var fit: Dictionary = AtlasWindowGeometry.fit_window_view( Vector2(200.0, 150.0), 64, CELL_PIXEL_SIZE, MIN_ZOOM, MAX_ZOOM ) assert_float(fit["zoom"]).is_equal_approx(MIN_ZOOM, 0.001) ## A small n (e.g. n=2) at a huge viewport must clamp to MAX_ZOOM, never ## scale past the ceiling. func test_fit_window_view_clamps_to_max_zoom_for_a_tiny_composite() -> void: var fit: Dictionary = AtlasWindowGeometry.fit_window_view( Vector2(3840.0, 2160.0), 2, CELL_PIXEL_SIZE, MIN_ZOOM, MAX_ZOOM ) assert_float(fit["zoom"]).is_equal_approx(MAX_ZOOM, 0.001) ## Degenerate inputs (zero viewport, zero n) must not divide by zero — a safe ## fallback (zoom=1.0, offset=ZERO), never a crash or NaN. func test_fit_window_view_degenerate_inputs_are_safe() -> void: var fit_zero_viewport: Dictionary = AtlasWindowGeometry.fit_window_view( Vector2.ZERO, 32, CELL_PIXEL_SIZE, MIN_ZOOM, MAX_ZOOM ) assert_float(fit_zero_viewport["zoom"]).is_equal_approx(1.0, 0.001) var fit_zero_n: Dictionary = AtlasWindowGeometry.fit_window_view( Vector2(1920.0, 1080.0), 0, CELL_PIXEL_SIZE, MIN_ZOOM, MAX_ZOOM ) assert_float(fit_zero_n["zoom"]).is_equal_approx(1.0, 0.001) # ============================================================================= # clamp_pan_offset_to_pole_wall — item 5 (pole hard wall, row axis only) # ============================================================================= ## Deep inside the valid range (window nowhere near a pole), the clamp must ## be a no-op — offset passes through unchanged. func test_pole_wall_clamp_is_a_noop_far_from_the_poles() -> void: var offset := Vector2(10.0, 20.0) var clamped: Vector2 = AtlasWindowGeometry.clamp_pan_offset_to_pole_wall( offset, Vector2(1920.0, 1080.0), Vector2i(0, 0), 32, 4785, CELL_PIXEL_SIZE, 1.0 ) assert_that(clamped).is_equal(offset) ## X is NEVER clamped by the pole wall (item 6: east-west is seamless) — even ## an absurdly large X offset passes through untouched. func test_pole_wall_clamp_never_touches_x() -> void: var offset := Vector2(999999.0, 0.0) var clamped: Vector2 = AtlasWindowGeometry.clamp_pan_offset_to_pole_wall( offset, Vector2(1920.0, 1080.0), Vector2i(0, 0), 32, 4785, CELL_PIXEL_SIZE, 1.0 ) assert_float(clamped.x).is_equal_approx(999999.0, 0.001) ## The core pole-wall behavior: dragging FAR past the north pole (offset.y ## driven to an extreme) must clamp — the resulting offset must be LESS than ## the extreme requested, and a SECOND, even-more-extreme drag must produce ## the SAME clamped value (further dragging is inert once pinned at the wall). func test_pole_wall_clamp_pins_offset_when_dragged_past_the_pole() -> void: var rows_half := 100 var held_center := Vector2i(0, 90) # near the south pole already (row 90 of 100) var extreme_offset := Vector2(0.0, 5000.0) # a huge downward drag var clamped: Vector2 = AtlasWindowGeometry.clamp_pan_offset_to_pole_wall( extreme_offset, Vector2(800.0, 800.0), held_center, 32, rows_half, CELL_PIXEL_SIZE, 1.0 ) assert_float(clamped.y).override_failure_message( "an extreme drag toward the pole must be clamped, not pass through" ).is_less(extreme_offset.y) var even_more_extreme := Vector2(0.0, 50000.0) var clamped_again: Vector2 = AtlasWindowGeometry.clamp_pan_offset_to_pole_wall( even_more_extreme, Vector2(800.0, 800.0), held_center, 32, rows_half, CELL_PIXEL_SIZE, 1.0 ) assert_float(clamped_again.y).override_failure_message( "further dragging past an already-pinned wall must be inert (same clamped value)" ).is_equal_approx(clamped.y, 0.01) ## Symmetric check on the north side: a huge UPWARD drag near the north pole ## also clamps. func test_pole_wall_clamp_pins_offset_on_the_north_side_too() -> void: var rows_half := 100 var held_center := Vector2i(0, -90) # near the north pole var extreme_offset := Vector2(0.0, -5000.0) # a huge upward drag var clamped: Vector2 = AtlasWindowGeometry.clamp_pan_offset_to_pole_wall( extreme_offset, Vector2(800.0, 800.0), held_center, 32, rows_half, CELL_PIXEL_SIZE, 1.0 ) assert_float(clamped.y).override_failure_message( "an extreme drag toward the north pole must be clamped" ).is_greater(extreme_offset.y) ## rows_half <= 0 (a no-radius body, or a degenerate district_extent()) means ## "no wall concept" — the clamp is a no-op, matching ## canonicalize_district_center()'s own no-radius identity disposition. func test_pole_wall_clamp_is_noop_when_rows_half_is_zero() -> void: var offset := Vector2(0.0, 999999.0) var clamped: Vector2 = AtlasWindowGeometry.clamp_pan_offset_to_pole_wall( offset, Vector2(800.0, 800.0), Vector2i(0, 0), 32, 0, CELL_PIXEL_SIZE, 1.0 ) assert_that(clamped).is_equal(offset) ## Tiny-body edge case (documented open item in atlas_window_viewer.gd's own ## _clamp_offset_to_pole_wall doc): a window TALLER than the whole planet's ## row span (n=64 window, rows_half=10 -> pole-to-pole is only 20 districts) ## must not crash or produce an inverted/degenerate clamp range — the offset ## still comes back as a finite Vector2, and repeated extreme drags still ## converge to a stable pinned value (not NaN, not unbounded). func test_pole_wall_clamp_handles_a_window_taller_than_the_planet() -> void: var rows_half := 10 var held_n := 64 var held_center := Vector2i(0, 0) var clamped: Vector2 = AtlasWindowGeometry.clamp_pan_offset_to_pole_wall( Vector2(0.0, 999999.0), Vector2(800.0, 800.0), held_center, held_n, rows_half, CELL_PIXEL_SIZE, 1.0 ) assert_bool(is_finite(clamped.y)).override_failure_message( "a window taller than the planet's row span must still produce a finite clamp" ).is_true() var clamped_again: Vector2 = AtlasWindowGeometry.clamp_pan_offset_to_pole_wall( Vector2(0.0, 9999999.0), Vector2(800.0, 800.0), held_center, held_n, rows_half, CELL_PIXEL_SIZE, 1.0 ) assert_float(clamped_again.y).is_equal_approx(clamped.y, 0.01) # ============================================================================= # Cross-check: clamp bounds derived from district_extent() (the SAME source # canonicalize_district_center() uses) — confirms the two T-1142 fixes (item # 5 pole wall, item 6a wrap/clamp) agree on what "the pole" even is. # ============================================================================= func test_pole_wall_rows_half_matches_canonicalize_rows_half() -> void: var radius_km := 6238.4 # GJ380c var extent: Dictionary = AtlasDescendGeometry.district_extent(radius_km) var rows_half: int = int(extent["rows_half"]) # A center exactly at (0, rows_half) must canonicalize to itself (already # at the pole boundary, not past it) — pins that the SAME rows_half both # fixes consume describes an inclusive boundary, not an exclusive one. var canonical: Vector2i = AtlasDescendGeometry.canonicalize_district_center( Vector2i(0, rows_half), radius_km ) assert_int(canonical.y).is_equal(rows_half) # ============================================================================= # T-1153: select_rung() — REDESIGNED (live round 3 finding) per-rung # single-window COVERAGE CEILING model, superseding the original # `2x`-visual-tolerance-only reading of design doc §5. Select the FINEST # rung whose own single-window coverage ceiling (MAX_COVERAGE_M) still # covers the current world extent: Quarter <= 32,768 m; District <= # 131,072 m; Region otherwise (including tiled coverage beyond its own # single-window ceiling, a viewer-level concern — see select_rung()'s own # doc for the full derivation and why this REPLACES the earlier two-gate # design entirely, not just patches it). # ============================================================================= ## Deep zoom-in (a tiny extent) selects Quarter — comfortably under its own ## 32,768 m ceiling. func test_select_rung_picks_quarter_well_under_its_ceiling() -> void: var rung: String = AtlasWindowGeometry.select_rung(2000.0, 1000.0) assert_str(rung).is_equal("Quarter") ## An extent past Quarter's own ceiling but under District's selects ## District — the finest rung that can still cover it in one window. func test_select_rung_picks_district_between_the_two_ceilings() -> void: # 60,000 m is past Quarter's 32,768 m ceiling but well under District's # 131,072 m one. var rung: String = AtlasWindowGeometry.select_rung(60_000.0, 100.0) assert_str(rung).is_equal("District") ## An extent past BOTH Quarter's and District's ceilings selects Region — ## neither finer rung's single window can cover this much world. func test_select_rung_picks_region_past_both_finer_ceilings() -> void: var rung: String = AtlasWindowGeometry.select_rung(40_075_264.0, 1920.0) assert_str(rung).is_equal("Region") ## Exactly AT Quarter's own ceiling (32,768 m) must still select Quarter — ## the rule is `<=`, not `<`. func test_select_rung_quarter_ceiling_boundary_is_inclusive() -> void: var rung: String = AtlasWindowGeometry.select_rung(32_768.0, 100.0) assert_str(rung).is_equal("Quarter") ## One metre past Quarter's ceiling must flip to District — confirms the ## ceiling bites right at its own boundary, not one cell short of it. func test_select_rung_one_past_quarter_ceiling_is_district() -> void: var rung: String = AtlasWindowGeometry.select_rung(32_769.0, 100.0) assert_str(rung).is_equal("District") ## Exactly AT District's own ceiling (131,072 m) must still select District. func test_select_rung_district_ceiling_boundary_is_inclusive() -> void: var rung: String = AtlasWindowGeometry.select_rung(131_072.0, 100.0) assert_str(rung).is_equal("District") ## One metre past District's ceiling must flip to Region. func test_select_rung_one_past_district_ceiling_is_region() -> void: var rung: String = AtlasWindowGeometry.select_rung(131_073.0, 100.0) assert_str(rung).is_equal("Region") ## canvas_px is unused by the coverage rule (kept for signature stability, ## see select_rung()'s own doc) — degenerate/zero values must not change the ## selected rung at all, unlike the old `2x`-tolerance design's special-cased ## fallback. func test_select_rung_canvas_px_does_not_affect_selection() -> void: var with_real_canvas: String = AtlasWindowGeometry.select_rung(2000.0, 1000.0) var with_zero_canvas: String = AtlasWindowGeometry.select_rung(2000.0, 0.0) assert_str(with_zero_canvas).is_equal(with_real_canvas) ## spacing_for_rung() is select_rung()'s inverse lookup — pin the three known ## values against the D-243 constants directly (not against RUNG_TABLE ## indices, which would just restate the implementation). func test_spacing_for_rung_matches_d243_constants() -> void: assert_float(AtlasWindowGeometry.spacing_for_rung("Quarter")).is_equal_approx(512.0, 0.001) assert_float(AtlasWindowGeometry.spacing_for_rung("District")).is_equal_approx(2048.0, 0.001) assert_float(AtlasWindowGeometry.spacing_for_rung("Region")).is_equal_approx(204_800.0, 0.001) ## An unknown tag falls back to District — matching the server's own ## "unknown -> District" posture at every wire-decode boundary. func test_spacing_for_rung_unknown_tag_falls_back_to_district() -> void: assert_float(AtlasWindowGeometry.spacing_for_rung("Nonsense")).is_equal_approx(2048.0, 0.001) ## MAX_COVERAGE_M's three values, pinned directly against the formulas ## select_rung()'s own doc derives them from — a regression guard ## independent of select_rung()'s own boundary tests above, so a future ## accidental edit to the constants table itself (not just the selection ## logic) is caught here too. func test_max_coverage_m_matches_derived_formulas() -> void: assert_float(AtlasWindowGeometry.MAX_COVERAGE_M["Quarter"]).is_equal_approx(32_768.0, 0.001) assert_float(AtlasWindowGeometry.MAX_COVERAGE_M["District"]).is_equal_approx(131_072.0, 0.001) assert_float(AtlasWindowGeometry.MAX_COVERAGE_M["Region"]).is_equal_approx(13_107_200.0, 0.001) ## The exact scenario that surfaced the original design flaw ## (live-testing enter_orbital()'s own fit zoom): a whole Earth-like body's ## circumference (~40,075 km, matching AtlasDescendGeometry.district_extent()'s ## own cols*DISTRICT_M for radius=6371km) fitted to a 1920px-wide viewport at ## CELL_PIXEL_SIZE=16 must select Region — the direct regression guard for ## the bug an early version of select_rung() had (picking District here, ## which would have meant the canonical orbital frame requests a ## District-tier derive spanning an entire planet — the exact R1-catastrophe ## cost scenario the design doc §4 rejects). func test_select_rung_at_orbital_fit_zoom_selects_region() -> void: var radius_km := 6371.0 var extent: Dictionary = AtlasDescendGeometry.district_extent(radius_km) var n: int = int(extent["cols"]) var composite_native: float = float(n) * CELL_PIXEL_SIZE var viewport := Vector2(1920.0, 1080.0) var fit_zoom: float = maxf(viewport.x, viewport.y) / composite_native var world_extent: float = AtlasWindowGeometry.world_extent_m(CELL_PIXEL_SIZE, fit_zoom, viewport) var rung: String = AtlasWindowGeometry.select_rung( world_extent, maxf(viewport.x, viewport.y) ) assert_str(rung).override_failure_message( "the canonical orbital fit-zoom (whole-planet view) must select Region," + " never a District-tier derive spanning an entire planet" ).is_equal("Region") ## **Live round 3 regression, the direct fix target:** at 1600x900 (the ## coordinator's capture viewport), zooming IN from the orbital fit all the ## way to Quarter's own ceiling must pass through District along the way — ## a wheel-zoom gesture crossing world_extent_m from Region's territory down ## to Quarter's must select District for SOME real span of extent in ## between, not skip straight from Region to Quarter (the exact "money shot" ## the coordinator wants capture-worthy: a visible SHARPEN in place, not a ## jump). func test_select_rung_district_is_reachable_between_region_and_quarter() -> void: # An extent comfortably between District's and Quarter's ceilings (e.g. # the midpoint) must select District — proving the band is non-empty, # unlike the old two-gate design where it was empty by construction at # every real viewport (see git history / the coordinator's live-round # finding for the retired analysis). var midpoint: float = ( (AtlasWindowGeometry.MAX_COVERAGE_M["Quarter"] as float) + (AtlasWindowGeometry.MAX_COVERAGE_M["District"] as float) ) * 0.5 var rung: String = AtlasWindowGeometry.select_rung(midpoint, 1600.0) assert_str(rung).override_failure_message( "District must be reachable between Quarter's and District's own" + " coverage ceilings — the redesigned rule must not skip it" ).is_equal("District") # ============================================================================= # T-1153: world_extent_m() — the `E` half of the §5 rule, computed from the # viewer's own zoom/viewport state. # ============================================================================= ## At zoom=1.0, CELL_PIXEL_SIZE=16: one DISTRICT (2,048 m, the fixed display ## unit — see world_extent_m()'s own doc for why this is rung-INDEPENDENT) ## occupies 16 screen px, so a 1920px-wide viewport shows ## 1920/16 * 2048 = 245,760 m. func test_world_extent_m_at_zoom_one() -> void: var extent: float = AtlasWindowGeometry.world_extent_m( CELL_PIXEL_SIZE, 1.0, Vector2(1920.0, 1080.0) ) assert_float(extent).is_equal_approx(1920.0 / CELL_PIXEL_SIZE * 2048.0, 1.0) ## Doubling the zoom must HALVE the displayed world extent — zooming in ## shows less world, not more. func test_world_extent_m_halves_when_zoom_doubles() -> void: var extent_1x: float = AtlasWindowGeometry.world_extent_m( CELL_PIXEL_SIZE, 1.0, Vector2(1920.0, 1080.0) ) var extent_2x: float = AtlasWindowGeometry.world_extent_m( CELL_PIXEL_SIZE, 2.0, Vector2(1920.0, 1080.0) ) assert_float(extent_2x).is_equal_approx(extent_1x * 0.5, 1.0) ## The composite's on-screen footprint is rung-invariant (world_extent_m()'s ## own doc) — a change in held rung with NO change in zoom/viewport must ## leave the displayed world extent UNCHANGED. This is the direct regression ## test for the bug this function's signature once had (a granularity_v2 ## parameter that silently changed the formula per rung, when only zoom ## should) — the function no longer TAKES a rung parameter at all, so this ## pins that omission is intentional, not an oversight. func test_world_extent_m_has_no_rung_parameter() -> void: var extent_a: float = AtlasWindowGeometry.world_extent_m( CELL_PIXEL_SIZE, 1.0, Vector2(1920.0, 1080.0) ) var extent_b: float = AtlasWindowGeometry.world_extent_m( CELL_PIXEL_SIZE, 1.0, Vector2(1920.0, 1080.0) ) assert_float(extent_a).is_equal_approx(extent_b, 0.001) ## Degenerate zoom (<=0) must not divide by zero — a safe zero extent. func test_world_extent_m_degenerate_zoom_is_safe() -> void: var extent: float = AtlasWindowGeometry.world_extent_m( CELL_PIXEL_SIZE, 0.0, Vector2(1920.0, 1080.0) ) assert_float(extent).is_equal_approx(0.0, 0.001) # ============================================================================= # T-1153: is_fully_zoomed_out() — Jeroen's HARD condition's trigger predicate. # ============================================================================= func test_is_fully_zoomed_out_true_when_extent_covers_full_circumference() -> void: var radius_km := 6371.0 var circumference_m: float = TAU * radius_km * 1000.0 assert_bool(AtlasWindowGeometry.is_fully_zoomed_out(circumference_m, radius_km)).is_true() assert_bool( AtlasWindowGeometry.is_fully_zoomed_out(circumference_m * 1.5, radius_km) ).is_true() func test_is_fully_zoomed_out_false_when_extent_is_less_than_circumference() -> void: var radius_km := 6371.0 var circumference_m: float = TAU * radius_km * 1000.0 assert_bool( AtlasWindowGeometry.is_fully_zoomed_out(circumference_m * 0.5, radius_km) ).is_false() ## A no-radius body (tiny test body) has no circumference concept — never ## auto-resets, matching enter_orbital()'s own no-radius fallback disposition. func test_is_fully_zoomed_out_false_for_no_radius_body() -> void: assert_bool(AtlasWindowGeometry.is_fully_zoomed_out(1e12, 0.0)).is_false() # ============================================================================= # T-1153: screen_center_to_district() — the shared screen<->district formula # behind both the pan-edge refetch and the rung-reselect refetch. # ============================================================================= ## At the exact center of a symmetric fit (offset centers the composite, ## zoom=1.0), the screen center must map back to the held center exactly. func test_screen_center_to_district_at_rest_returns_held_center() -> void: var held_n := 32 var held_center := Vector2i(10, 20) var composite_native: float = float(held_n) * CELL_PIXEL_SIZE var viewport := Vector2(composite_native, composite_native) var offset := Vector2.ZERO # composite exactly fills the viewport, top-left at origin var result: Vector2i = AtlasWindowGeometry.screen_center_to_district( viewport, offset, 1.0, CELL_PIXEL_SIZE, held_center, held_n ) assert_that(result).is_equal(held_center) ## Panning the offset must shift the recovered district position in the ## OPPOSITE direction of the offset shift (dragging the composite right ## reveals districts to the WEST at screen-center). func test_screen_center_to_district_shifts_with_pan_offset() -> void: var held_n := 32 var held_center := Vector2i(0, 0) var composite_native: float = float(held_n) * CELL_PIXEL_SIZE var viewport := Vector2(composite_native, composite_native) var at_rest: Vector2i = AtlasWindowGeometry.screen_center_to_district( viewport, Vector2.ZERO, 1.0, CELL_PIXEL_SIZE, held_center, held_n ) var panned: Vector2i = AtlasWindowGeometry.screen_center_to_district( viewport, Vector2(CELL_PIXEL_SIZE * 4.0, 0.0), 1.0, CELL_PIXEL_SIZE, held_center, held_n ) assert_int(panned.x).override_failure_message( "dragging the composite EAST (positive offset) must reveal districts to the WEST" ).is_less(at_rest.x) # ============================================================================= # T-1153 (moved from atlas_window_viewer.gd for testability): WASD held-pan # direction is exercised live only (reads the global Input singleton) — # edge-scroll suppression/direction are pure and covered here directly. # ============================================================================= func test_is_cursor_edge_scrolling_true_near_an_edge() -> void: var result: bool = AtlasWindowGeometry.is_cursor_edge_scrolling( true, false, Vector2(800.0, 600.0), Vector2(10.0, 300.0), 24.0 ) assert_bool(result).is_true() func test_is_cursor_edge_scrolling_false_away_from_any_edge() -> void: var result: bool = AtlasWindowGeometry.is_cursor_edge_scrolling( true, false, Vector2(800.0, 600.0), Vector2(400.0, 300.0), 24.0 ) assert_bool(result).is_false() func test_is_cursor_edge_scrolling_suppressed_when_over_ui() -> void: var result: bool = AtlasWindowGeometry.is_cursor_edge_scrolling( true, true, Vector2(800.0, 600.0), Vector2(10.0, 300.0), 24.0 ) assert_bool(result).is_false() func test_is_cursor_edge_scrolling_suppressed_without_app_focus() -> void: var result: bool = AtlasWindowGeometry.is_cursor_edge_scrolling( false, false, Vector2(800.0, 600.0), Vector2(10.0, 300.0), 24.0 ) assert_bool(result).is_false() func test_edge_scroll_direction_points_west_near_left_edge() -> void: var direction: Vector2 = AtlasWindowGeometry.edge_scroll_direction( Vector2(800.0, 600.0), Vector2(5.0, 300.0), 24.0 ) assert_float(direction.x).is_less(0.0) assert_float(direction.y).is_equal_approx(0.0, 0.001) # ============================================================================= # T-1153, live round 3 (Jeroen's ruling, design doc §4): compute_tile_grid() # — the orbital rest state's multi-window mosaic. # ============================================================================= ## The exact live-round scenario: GJ380c/Lendel (radius 6238.4 km) needs a ## 3x2 = 6-tile grid — the coordinator's own estimate, confirmed here as an ## executable regression. func test_compute_tile_grid_lendel_produces_six_tiles() -> void: var tiles: Array = AtlasWindowGeometry.compute_tile_grid(6238.4) assert_int(tiles.size()).override_failure_message( "GJ380c/Lendel must tile into 3x2=6 windows, matching the coordinator's own" + " live-round finding (13,107.2 km single-window coverage vs. 39,198 km" + " circumference)" ).is_equal(6) ## A tiny body whose whole circumference fits in ONE Region window's ## coverage ceiling must produce exactly ONE tile — tiling degenerates ## gracefully to the pre-existing single-window behavior when it isn't ## actually needed. func test_compute_tile_grid_tiny_body_produces_one_tile() -> void: # radius small enough that circumference << MAX_COVERAGE_M["Region"] # (13,107,200 m) — a few hundred km radius comfortably qualifies. var tiles: Array = AtlasWindowGeometry.compute_tile_grid(50.0) assert_int(tiles.size()).is_equal(1) assert_that(tiles[0]).is_equal(Vector2i.ZERO) ## A no-radius body (tiny test body) must produce exactly one tile at the ## canonical origin — matching enter_orbital()'s own no-radius fallback ## disposition (no circumference/tiling concept without a radius). func test_compute_tile_grid_no_radius_produces_single_origin_tile() -> void: var tiles: Array = AtlasWindowGeometry.compute_tile_grid(0.0) assert_int(tiles.size()).is_equal(1) assert_that(tiles[0]).is_equal(Vector2i.ZERO) ## Every tile center must be a LEGAL canonicalized DistrictPos — column ## wrapped into [0, cols), row clamped into [-rows_half, rows_half] — the ## same range canonicalize_district_center() enforces everywhere else in ## this cluster (pan refetch, entry, rung-reselect). A raw, uncanonicalized ## tile center would fail the server's own normalize_window_center() (or ## silently alias to a different tile than intended). func test_compute_tile_grid_tiles_are_all_canonicalized() -> void: var radius_km := 6238.4 var extent: Dictionary = AtlasDescendGeometry.district_extent(radius_km) var cols: int = int(extent["cols"]) var rows_half: int = int(extent["rows_half"]) var tiles: Array = AtlasWindowGeometry.compute_tile_grid(radius_km) for tile: Vector2i in tiles: assert_int(tile.x).override_failure_message( "tile column %d must be wrapped into [0, %d)" % [tile.x, cols] ).is_greater_equal(0) assert_int(tile.x).is_less(cols) assert_int(tile.y).override_failure_message( "tile row %d must be clamped into [-%d, %d]" % [tile.y, rows_half, rows_half] ).is_greater_equal(-rows_half) assert_int(tile.y).is_less_equal(rows_half) ## No two tiles may share the same canonicalized center — compute_tile_grid() ## must dedupe (a pole-row clamp or column-wrap collision producing the exact ## same DistrictPos twice would otherwise request/draw the same tile twice, ## wasting a request and drawing one tile over another). func test_compute_tile_grid_has_no_duplicate_centers() -> void: var tiles: Array = AtlasWindowGeometry.compute_tile_grid(6238.4) var seen: Dictionary = {} for tile: Vector2i in tiles: assert_bool(seen.has(tile)).override_failure_message( "tile center %s appears more than once in the grid" % str(tile) ).is_false() seen[tile] = true ## The tile grid's own center of mass must land on the canonical origin ## (0,0) — the tile-set's symmetric layout (each axis' centers computed as ## `(index - (count-1)/2) * TILE_N`) is centered on the SAME canonical origin ## enter_orbital() uses, so the tile-set's overall framing agrees with ## single-window enter_orbital()'s own "center on (0,0)" contract. func test_compute_tile_grid_is_centered_on_the_canonical_origin() -> void: var tiles: Array = AtlasWindowGeometry.compute_tile_grid(6238.4) var sum_col := 0 var sum_row := 0 for tile: Vector2i in tiles: sum_col += tile.x sum_row += tile.y # Column centers wrap (periodic), so a raw average isn't meaningful there # the way it is for rows — assert row symmetry directly instead (rows # never wrap, so their average must be very close to 0 for a # symmetric grid). var avg_row: float = float(sum_row) / float(tiles.size()) assert_float(avg_row).override_failure_message( "the tile grid's row centers must average to ~0 (symmetric around the" + " canonical origin's equator row)" ).is_equal_approx(0.0, float(AtlasWindowGeometry.TILE_N))