feat(client): T-1153 + T-1152 client half — continuous cursor-anchored zoom ladder, Region-rung orbital entry, click-through retired
The atlas 'regional' screen now opens the LADDER at the canonical orbital frame (Region granularity, whole body fitted and centered) and wheel zoom descends continuously — cursor-anchored, unclamped across rungs, with progressive refinement (held composite keeps drawing, finer rung swaps in place on arrival; no blank frame, no mode flip). Full-zoom-out resets to the canonical planetary frame per Jeroen's HARD condition (is_fully_zoomed_out = extent >= body circumference, not a zoom-value heuristic). The district_screen nav hop is deleted — D-013 restored: descent is a zoom gesture, not a nav push. AtlasViewer's heightmap-texture path is unreachable from nav (code intact; overlay surface deferred, see report/tickets). Rung selection: design doc §5's literal formula has NO legal District band at any real viewport (visual-tolerance band and n=64 coverage ceiling never overlap — pinned by executable boundary tests at 1600x900); select_rung() splits it into a coverage ceiling (decides Region) then the 2x visual tolerance (District vs Quarter), documented at the function. In practice the ladder steps Region -> Quarter directly. Wire: window_granularity_v2 encoded (omitted at District for byte-compat), granularity_v2 echoed value keyed + staleness-guarded end to end; Region clamp mirror replicates the server's bounded halving loop (no closed form). MIN/MAX_ZOOM widened to [0.0005, 64] — the old 0.5 floor would have clamped a real body's canonical fit zoom, violating the reset condition. Real pre-existing bug fixed in atlas_window_overlay.gd: the draw path used echoed n as both cell-grid dimension and district extent — only coincidentally correct at District granularity; Quarter/Region would have read wrong array offsets. cell_grid_side_for_window() now mirrors the server's WindowGranularity::cell_grid_side. Tests: +26 pure-function geometry tests, new 30-test zoom-ladder suite, extensions across the window cache/request/overlay/delivery suites. Full suite 3518 green; cold-parse clean.
This commit is contained in:
@@ -265,3 +265,336 @@ func test_pole_wall_rows_half_matches_canonicalize_rows_half() -> void:
|
||||
Vector2i(0, rows_half), radius_km
|
||||
)
|
||||
assert_int(canonical.y).is_equal(rows_half)
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# T-1153: select_rung() — the §5 rung-selection rule, split into TWO tests
|
||||
# per select_rung()'s own doc: a COVERAGE ceiling decides Region (can a
|
||||
# District window even span this much world), and the `2x` visual-tolerance
|
||||
# rule (design doc §5: "select the coarsest rung whose cell spacing <=
|
||||
# 2*(E/C)") decides District vs. Quarter for whatever's under that ceiling.
|
||||
# =============================================================================
|
||||
|
||||
|
||||
## A tight sample spacing (deep zoom-in — small E over a large C) must select
|
||||
## Quarter (512 m), the finest legal rung — 2*(E/C) is far below District's
|
||||
## 2,048 m spacing at this ratio.
|
||||
func test_select_rung_picks_quarter_at_a_tight_sample_spacing() -> void:
|
||||
# E=2000m over C=1000px -> sample spacing 2 m/px -> threshold 4 m. Even
|
||||
# Quarter (512 m) is coarser than the threshold, so select_rung() falls
|
||||
# through to the FINEST legal rung (its own documented fallback) rather
|
||||
# than returning something even finer that doesn't exist — Quarter.
|
||||
var rung: String = AtlasWindowGeometry.select_rung(2000.0, 1000.0)
|
||||
assert_str(rung).is_equal("Quarter")
|
||||
|
||||
|
||||
## A sample spacing that satisfies BOTH District's own `2x` band AND the
|
||||
## coverage ceiling selects District — the coarsest rung whose spacing still
|
||||
## satisfies the fine-end rule, without exceeding what a District window can
|
||||
## physically cover.
|
||||
func test_select_rung_picks_district_at_a_moderate_sample_spacing() -> void:
|
||||
# E=120,000m (under the 64*2048=131,072m coverage ceiling) over C=100px ->
|
||||
# threshold = 2*120000/100 = 2,400m — satisfies District's 2,048m spacing.
|
||||
var rung: String = AtlasWindowGeometry.select_rung(120_000.0, 100.0)
|
||||
assert_str(rung).is_equal("District")
|
||||
|
||||
|
||||
## An extent past the COVERAGE ceiling (more world than a District window can
|
||||
## physically span, regardless of how generous the visual tolerance would
|
||||
## otherwise be) must select Region — the coverage test, not the `2x` visual
|
||||
## one, is what decides this (select_rung()'s own doc: "the coverage ceiling
|
||||
## wins whenever the two disagree").
|
||||
func test_select_rung_picks_region_past_the_coverage_ceiling() -> void:
|
||||
# E = full Earth-like circumference (~40,075 km) — far past the
|
||||
# 64*2048=131,072m District coverage ceiling regardless of canvas_px.
|
||||
var rung: String = AtlasWindowGeometry.select_rung(40_075_264.0, 1920.0)
|
||||
assert_str(rung).is_equal("Region")
|
||||
|
||||
|
||||
## Exactly AT the coverage ceiling (E == 64*2048 = 131,072m) must still
|
||||
## select District if the `2x` band also agrees — the ceiling is `>`, not
|
||||
## `>=`, so the boundary value itself stays under District's own test.
|
||||
func test_select_rung_coverage_ceiling_boundary_stays_district() -> void:
|
||||
var rung: String = AtlasWindowGeometry.select_rung(131_072.0, 100.0)
|
||||
assert_str(rung).is_equal("District")
|
||||
|
||||
|
||||
## One metre past the coverage ceiling must flip to Region — confirms the
|
||||
## ceiling actually bites right at its own boundary, not one district-window
|
||||
## short of it.
|
||||
func test_select_rung_one_past_the_coverage_ceiling_is_region() -> void:
|
||||
var rung: String = AtlasWindowGeometry.select_rung(131_073.0, 100.0)
|
||||
assert_str(rung).is_equal("Region")
|
||||
|
||||
|
||||
## Exactly AT District's `2x` threshold (spacing_m == 2*(E/C)) must select
|
||||
## District, not the next-finer rung — the rule is `<=`, not `<`.
|
||||
func test_select_rung_district_threshold_boundary_is_inclusive() -> void:
|
||||
# District spacing = 2048 m. Choose E/C such that 2*(E/C) == 2048 exactly:
|
||||
# E=1024, C=1.0 -> E/C=1024 -> threshold=2048. E=1024 is also comfortably
|
||||
# under the coverage ceiling (131,072), so the `2x` test is what's
|
||||
# actually being exercised here.
|
||||
var rung: String = AtlasWindowGeometry.select_rung(1024.0, 1.0)
|
||||
assert_str(rung).is_equal("District")
|
||||
|
||||
|
||||
## Degenerate canvas_px (<=0, an unlaid-out viewport) must fall back to the
|
||||
## FINEST rung, never crash or pick the coarsest by dividing by zero — the
|
||||
## documented "under-resolve is the safe failure direction" disposition (and
|
||||
## must be checked BEFORE the coverage ceiling could otherwise route a
|
||||
## degenerate small extent toward Region by accident).
|
||||
func test_select_rung_degenerate_canvas_px_falls_back_to_finest() -> void:
|
||||
var rung: String = AtlasWindowGeometry.select_rung(1000.0, 0.0)
|
||||
assert_str(rung).is_equal("Quarter")
|
||||
|
||||
|
||||
## 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)
|
||||
|
||||
|
||||
## The exact scenario that surfaced the coverage-vs-visual-tolerance
|
||||
## distinction (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 — this is the direct regression guard for the bug this
|
||||
## implementation found and fixed (an earlier version of select_rung()
|
||||
## selected 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")
|
||||
|
||||
|
||||
## Pinned capture-resolution boundary numbers (1600x900, the coordinator's
|
||||
## requested eyeball-capture viewport) — a live executable regression guard
|
||||
## for select_rung()'s own doc's worked example. Region releases District's
|
||||
## coverage ceiling at _view_zoom ~= 1.5625; District's own `2x` band edge
|
||||
## sits at _view_zoom ~= 0.125 — i.e. BELOW (not above) the coverage-ceiling
|
||||
## crossing, confirming the two never overlap at this (or any real) canvas
|
||||
## size — see select_rung()'s "Tuning knobs" paragraph for what would need
|
||||
## to change (DISTRICT_WINDOW_MAX_N, a server-side wire-budget change) to
|
||||
## open a real District band.
|
||||
func test_select_rung_1600x900_region_district_boundary_zoom() -> void:
|
||||
var viewport := Vector2(1600.0, 900.0)
|
||||
var canvas_px: float = maxf(viewport.x, viewport.y)
|
||||
var boundary_zoom := 1.5625
|
||||
var just_inside: float = AtlasWindowGeometry.world_extent_m(
|
||||
CELL_PIXEL_SIZE, boundary_zoom * 1.001, viewport
|
||||
)
|
||||
var just_outside: float = AtlasWindowGeometry.world_extent_m(
|
||||
CELL_PIXEL_SIZE, boundary_zoom * 0.999, viewport
|
||||
)
|
||||
assert_str(AtlasWindowGeometry.select_rung(just_inside, canvas_px)).override_failure_message(
|
||||
"zoomed IN past ~1.5625 at 1600x900 must have released the Region coverage ceiling"
|
||||
).is_not_equal("Region")
|
||||
assert_str(AtlasWindowGeometry.select_rung(just_outside, canvas_px)).override_failure_message(
|
||||
"zoomed OUT past ~1.5625 at 1600x900 must still be under the Region coverage ceiling"
|
||||
).is_equal("Region")
|
||||
|
||||
|
||||
func test_select_rung_1600x900_district_quarter_boundary_zoom_confirms_no_overlap() -> void:
|
||||
var viewport := Vector2(1600.0, 900.0)
|
||||
var canvas_px: float = maxf(viewport.x, viewport.y)
|
||||
var boundary_zoom := 0.125
|
||||
var just_inside: float = AtlasWindowGeometry.world_extent_m(
|
||||
CELL_PIXEL_SIZE, boundary_zoom * 1.001, viewport
|
||||
)
|
||||
var just_outside: float = AtlasWindowGeometry.world_extent_m(
|
||||
CELL_PIXEL_SIZE, boundary_zoom * 0.999, viewport
|
||||
)
|
||||
# Both sides of the District/Quarter `2x`-band boundary read "Region" at
|
||||
# 1600x900, NOT "District" — confirming the coverage ceiling (which
|
||||
# releases at zoom~=1.5625, far above this boundary) has already forced
|
||||
# Region long before the `2x` band's own edge is reached. This is the
|
||||
# literal "no overlap" finding, pinned as an executable assertion.
|
||||
assert_str(AtlasWindowGeometry.select_rung(just_inside, canvas_px)).is_equal("Region")
|
||||
assert_str(AtlasWindowGeometry.select_rung(just_outside, canvas_px)).is_equal("Region")
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 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)
|
||||
|
||||
Reference in New Issue
Block a user