Draw the map's missing squares as gaps, and its rings in your own units

Two faults reported from in front of the window, both of them the map saying
something confidently and wrongly.

Tiles that did not arrive.  Resizing the window does not refetch the map: the
window deliberately fetches more world than it shows, so a resize still fits
inside what is in hand and gets stretched to the new size.  It refetches when
the view leaves that box, which is what a new station does -- and that fetch
asks a volunteer-funded server for a hundred tiles that have never been on
this disk, all at once, at the sharper zoom the bigger window chose.  Some of
them are refused.

What the window did with a refusal was draw it.  A tile that never arrived
leaves its square of the canvas black, and black is not a neutral colour
here: the brightness is inverted on the way in, because a printed map is ink
on paper and this picture is the other way round.  So the darkest possible
square came out as the brightest thing on the picture, a glowing rectangle
where the map should be.  Measured on a reproduction, one missing tile in
eighteen put thirteen thousand pixels at full brightness -- and dragged the
floor of the map's own contrast down to black with it, so thirteen thousand
four hundred and ninety pixels changed in all: the whole map was redrawn
dimmer to make room for a square that was not there.  Then it was kept, cached
under the view it was fetched for, until the view moved again.

So the missing squares are asked for again at once, and only those, the rest
being on the disk by then; what is still missing is drawn as bare ground and
left out of the reckoning when the darkest and brightest of the map are worked
out, which puts the same reproduction at two pixels changed rather than
thirteen thousand four hundred and ninety, a hairline where a cell is averaged
over part of a tile and part of nothing; and the map is kept as provisional
rather than as the last word, asked for again half a minute later, four
attempts in all, each retrying its own misses once.

Found while measuring that: the politeness pause between requests was being
paid on every tile, including the ones read straight back off the disk.  Two
hundred and twenty tiles at an eighth of a second is twenty-six seconds of
sleeping to redraw a view that was entirely cached, and it would have made
asking again for three missing squares cost the wait for the two hundred that
were not.  The constant's own comment already said it should only be paid on a
tile that was not already there.  Now it is.

The APRS map's units.  Setting imperial changed nothing at all about the
window: the unit it measures in was hardcoded to kilometres, and that one
value drives the ring labels and the scale along the bottom; and --radius was
always read as kilometres, so the rings were not merely mislabelled, they were
at the wrong distance from the flag.  A ring is what a distance gets judged
against by eye, and one labelled in a unit it was not drawn in is a wrong
answer given confidently.  The aircraft side has done this properly all along
-- a radius read in whatever unit the speeds are in, and no unit suffix on the
setting because the suffix belongs to the other setting -- so this now mirrors
it exactly.  At --radius 100 in imperial the outermost ring stands seventy-
five statute miles from the flag and says so, where it used to stand seventy-
five kilometres and say kilometres whatever you had asked for.

Twenty-one new tests against sixteen deliberately broken builds.  One
survived, and removing what it broke was the right answer rather than
strengthening a test: a check that the remembered request still matched the
map in hand could not be made to fail, a request for a different view being
taken up only after the slot it guards is already full.  The tests do not
trust the drawing to mark its own homework -- the one that matters walks north
from the flag by each ring's radius and measures the great-circle distance
with a haversine written in the test, then checks that against the printed
label.  Full suite 2685 passed.  Built as 2026-09-21_03.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016PsWPTweCT6pwxKngvVxcg
This commit is contained in:
The Dust Council 2026-09-21 02:36:43 -07:00
parent e05b66ec3d
commit e203b3e581
11 changed files with 780 additions and 73 deletions

View file

@ -363,6 +363,123 @@ def test_a_map_that_could_not_be_fetched_is_not_asked_for_again():
assert sky.wanted_ground() is None
def test_a_map_with_squares_missing_is_asked_for_again():
"""A resize picks a sharper zoom and asks for a hundred tiles that have
never been on this disk at once, and a busy server refuses some of
them. Most of a map gets drawn; it does not get kept."""
from bandsaunter.livemap import GROUND_RETRY_S
sky = a_sky()
sky.want_ground("a", (0, 0, 1, 1), (10, 10))
sky.set_ground(np.zeros((40, 40), dtype=np.uint8), "a", (0, 0, 1, 1),
settled=False)
assert sky.wanted_ground() is None, "not before the server has a rest"
assert not sky.ground_settled()
sky.reask_ground()
assert sky.wanted_ground() is None, "still too soon"
sky._ground_at -= GROUND_RETRY_S + 1
sky.reask_ground()
# Asked for again, and for the map it already asked for rather than for
# whatever the view has drifted to since.
assert sky.wanted_ground() == ("a", (0, 0, 1, 1), (10, 10))
def test_a_whole_map_is_never_asked_for_again():
sky = a_sky()
sky.want_ground("a", (0, 0, 1, 1), (10, 10))
sky.set_ground(np.zeros((40, 40), dtype=np.uint8), "a", (0, 0, 1, 1))
assert sky.ground_settled()
sky._ground_at -= 10_000.0
sky.reask_ground()
assert sky.wanted_ground() is None
def test_a_square_that_is_missing_for_good_is_not_asked_for_all_night():
"""A tile can be absent because there is no such tile. Asking for it
every half minute until morning is the same discourtesy more slowly."""
from bandsaunter.livemap import GROUND_RETRY_S, GROUND_TRIES
sky = a_sky()
sky.want_ground("a", (0, 0, 1, 1), (10, 10))
asks = 0
for _ in range(GROUND_TRIES + 5):
sky.set_ground(np.zeros((40, 40), dtype=np.uint8), "a", (0, 0, 1, 1),
settled=False)
sky._ground_at -= GROUND_RETRY_S + 1
sky.reask_ground()
if sky.wanted_ground() is not None:
asks += 1
sky._wanted = None
assert asks == GROUND_TRIES - 1, asks
def test_moving_the_view_starts_the_asking_over():
"""The count is against one view's tiles. A window that was resized
twice has not used up its patience on the second view."""
from bandsaunter.livemap import GROUND_RETRY_S, GROUND_TRIES
sky = a_sky()
for _ in range(GROUND_TRIES + 2):
sky.set_ground(np.zeros((40, 40), dtype=np.uint8), "a", (0, 0, 1, 1),
settled=False)
sky.want_ground("b", (0, 0, 2, 2), (20, 20))
sky.set_ground(np.zeros((40, 40), dtype=np.uint8), "b", (0, 0, 2, 2),
settled=False)
sky._wanted = None
sky._ground_at -= GROUND_RETRY_S + 1
sky.reask_ground()
assert sky.wanted_ground() is not None
@qt
def test_drawing_most_of_a_map_draws_it_and_asks_for_the_rest(app):
"""Both halves: the window does not go bare while it waits, and it does
not settle for the map it was given."""
from bandsaunter.livemap import GROUND_RETRY_S, SkyView
sky = a_sky(a_blip())
view = SkyView(sky)
view.resize(900, 650)
view._draw_ground(_NoPainter(), view.projection()) # asks
wanted = sky.wanted_ground()
assert wanted is not None
key, box, _size = wanted
sky.set_ground(np.full((760, 1050), 12, dtype=np.uint8), key, box,
settled=False)
drawn = []
class _Painter(_NoPainter):
def drawImage(self, *a):
drawn.append(a)
sky._ground_at -= GROUND_RETRY_S + 1
view._draw_ground(_Painter(), view.projection())
assert drawn, "most of a map is still worth drawing"
assert sky.wanted_ground() is not None, "and worth finishing"
@qt
def test_drawing_a_whole_map_asks_for_nothing(app):
from bandsaunter.livemap import SkyView
sky = a_sky(a_blip())
view = SkyView(sky)
view.resize(900, 650)
view._draw_ground(_NoPainter(), view.projection())
key, box, _size = sky.wanted_ground()
sky.set_ground(np.full((760, 1050), 12, dtype=np.uint8), key, box)
sky._wanted = None
class _Painter(_NoPainter):
def drawImage(self, *a):
pass
sky._ground_at -= 10_000.0
view._draw_ground(_Painter(), view.projection())
assert sky.wanted_ground() is None
# ---------------------------------------------------------------------------
# The map staying still
# ---------------------------------------------------------------------------