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:
parent
e05b66ec3d
commit
e203b3e581
11 changed files with 780 additions and 73 deletions
|
|
@ -1075,6 +1075,32 @@ def test_the_window_gets_the_position_so_the_flag_is_drawn(tmp_path,
|
|||
assert "aircraft" not in built["waiting"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("units, unit, nm", [
|
||||
("metric", "kph", 100 / 1.852),
|
||||
("imperial", "mph", 100 / 1.150779),
|
||||
])
|
||||
def test_the_window_is_built_in_the_unit_being_shown(units, unit, nm,
|
||||
tmp_path, monkeypatch):
|
||||
"""Not just the helpers: the window that actually gets opened. The
|
||||
rings, their labels and the scale along the bottom all read off what is
|
||||
handed over here."""
|
||||
from bandsaunter import livemap
|
||||
|
||||
built = {}
|
||||
monkeypatch.setattr(livemap, "available", lambda: True)
|
||||
monkeypatch.setattr(livemap, "show",
|
||||
lambda sky, title: built.update(
|
||||
unit=sky.unit, radius_nm=sky.radius_nm))
|
||||
monkeypatch.setattr(ap, "open_device", lambda console, opts: Silence(1))
|
||||
console = Console(width=120, force_terminal=False)
|
||||
with console.capture():
|
||||
ap.watch(console, ap.AprsOptions(rate=RATE, log=False, report=False,
|
||||
basemap=False, units=units,
|
||||
radius=100.0), str(tmp_path))
|
||||
assert built["unit"] == unit
|
||||
assert built["radius_nm"] == pytest.approx(nm, rel=1e-6)
|
||||
|
||||
|
||||
def test_it_says_where_the_position_came_from_rather_than_assuming(
|
||||
tmp_path, monkeypatch):
|
||||
"""A position inherited from another section is a convenience right up
|
||||
|
|
@ -1109,6 +1135,74 @@ def test_knowing_nowhere_says_what_that_costs(tmp_path, monkeypatch):
|
|||
assert "no flag" in out and "--at" in out
|
||||
|
||||
|
||||
def _haversine_km(a, b):
|
||||
"""Great-circle distance, written here rather than imported, so that a
|
||||
test of how far the rings are drawn is not asking the drawing."""
|
||||
import math
|
||||
|
||||
lat1, lon1 = math.radians(a[0]), math.radians(a[1])
|
||||
lat2, lon2 = math.radians(b[0]), math.radians(b[1])
|
||||
h = (math.sin((lat2 - lat1) / 2) ** 2
|
||||
+ math.cos(lat1) * math.cos(lat2) * math.sin((lon2 - lon1) / 2) ** 2)
|
||||
return 2 * 6371.0088 * math.asin(math.sqrt(h))
|
||||
|
||||
|
||||
def _rings_as_drawn(options):
|
||||
"""Every ring the window would draw: how far it really is from the flag,
|
||||
in kilometres, and what is written beside it."""
|
||||
from bandsaunter.flightlog import move
|
||||
from bandsaunter.flightmap import ring_labels
|
||||
|
||||
home = (47.6062, -122.3322)
|
||||
out = []
|
||||
for nm, text in ring_labels(ap.radius_in_nm(options),
|
||||
ap.map_unit(options)):
|
||||
edge = move(home[0], home[1], 0.0, nm)
|
||||
out.append((_haversine_km(home, edge), text))
|
||||
return out
|
||||
|
||||
|
||||
@pytest.mark.parametrize("units, label, per_km", [
|
||||
("metric", "km", 1.0),
|
||||
("imperial", "mi", 1.609344),
|
||||
])
|
||||
def test_the_rings_are_drawn_at_the_distance_they_are_labelled(
|
||||
units, label, per_km):
|
||||
"""Both halves of it. Writing miles beside a ring drawn at kilometres
|
||||
is worse than writing nothing: it is a wrong answer given confidently,
|
||||
and the ring is the thing a distance gets judged against by eye."""
|
||||
options = ap.defaults()
|
||||
options.units, options.radius = units, 100.0
|
||||
drawn = _rings_as_drawn(options)
|
||||
assert [text for _km, text in drawn] == [f"25 {label}", f"50 {label}",
|
||||
f"75 {label}"]
|
||||
for km, text in drawn:
|
||||
said = float(text.split()[0])
|
||||
assert abs(km - said * per_km) < 0.5, (km, text)
|
||||
|
||||
|
||||
def test_the_window_reaches_as_far_as_it_was_told_in_the_unit_being_shown():
|
||||
"""A hundred set in imperial is a hundred miles, not a hundred
|
||||
kilometres with miles written on it."""
|
||||
metric, imperial = ap.defaults(), ap.defaults()
|
||||
metric.units, metric.radius = "metric", 100.0
|
||||
imperial.units, imperial.radius = "imperial", 100.0
|
||||
assert ap.radius_in_nm(metric) == pytest.approx(100 / 1.852, rel=1e-6)
|
||||
assert ap.radius_in_nm(imperial) == pytest.approx(100 / 1.150779,
|
||||
rel=1e-6)
|
||||
assert ap.radius_in_nm(imperial) > ap.radius_in_nm(metric)
|
||||
|
||||
|
||||
def test_the_unit_the_window_measures_in_follows_the_one_being_shown():
|
||||
"""The scale along the bottom and the rings read off the same setting
|
||||
as the tables, so the window cannot disagree with the report."""
|
||||
options = ap.defaults()
|
||||
options.units = "metric"
|
||||
assert ap.map_unit(options) == "kph"
|
||||
options.units = "imperial"
|
||||
assert ap.map_unit(options) == "mph"
|
||||
|
||||
|
||||
def test_the_box_gives_the_position_in_figures():
|
||||
"""A mark shows where a station is; a number is what gets written down."""
|
||||
rows = dict((label, value) for label, value, _f
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue