From 1e089df4b4920dc0e867d54ebf99954ee3714772 Mon Sep 17 00:00:00 2001 From: KNSO Date: Sat, 12 Sep 2026 14:04:39 +0200 Subject: [PATCH] =?UTF-8?q?test(extract):=20Mosaik-Test=20auf=20exakten=20?= =?UTF-8?q?Zuschnitt-Versatz=20versch=C3=A4rfen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Einfarbige Fake-Kacheln erkannten nur die Herkunftskachel eines Pixels, nicht den Versatz innerhalb der Kachel (72px Spielraum je Achse zwischen 3072px Kachelraster und 3000px Zuschnitt). fake_tile kodiert jetzt die globale Pixelposition, ein neuer Test nagelt mosaic_origin_px() == (24, 60) fest und prüft drei Pixel gegen den daraus berechneten globalen Index. Produktionscode unverändert (Ruling 8). Co-Authored-By: Claude Sonnet 5 --- tools/extract/tests/test_tiles.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tools/extract/tests/test_tiles.py b/tools/extract/tests/test_tiles.py index 13e9bb0..64f3616 100644 --- a/tools/extract/tests/test_tiles.py +++ b/tools/extract/tests/test_tiles.py @@ -1,14 +1,24 @@ import numpy as np +from leonida.coords import mosaic_origin_px from leonida.tiles import assemble def fake_tile(row: int, col: int) -> np.ndarray: - # Jede Kachel einfarbig, Farbe kodiert Zeile und Spalte. - return np.full((256, 256, 3), (row, col, 7), dtype=np.uint8) + """Kodiert die globale Pixelposition, damit ein falscher Versatz auffällt.""" + ys, xs = np.mgrid[0:256, 0:256] + gy = (row * 256 + ys) % 251 + gx = (col * 256 + xs) % 251 + return np.dstack([gy, gx, np.full((256, 256), 7)]).astype(np.uint8) def test_assemble_crops_to_slice(): mosaic = assemble(fake_tile) assert mosaic.shape == (3000, 3000, 3) - # Nordwest-Ecke stammt aus Kachel (54, 60) - assert tuple(mosaic[0, 0]) == (54, 60, 7) - # Südost-Ecke stammt aus Kachel (65, 71) - assert tuple(mosaic[-1, -1]) == (65, 71, 7) + +def test_assemble_uses_the_exact_crop_offset(): + # Einfarbige Kacheln würden jeden Versatz von 0 bis 72 px durchgehen lassen. + ox, oy = mosaic_origin_px() + assert (ox, oy) == (24, 60) + mosaic = assemble(fake_tile) + r0, c0 = 54, 60 + for py, px in [(0, 0), (2999, 2999), (1234, 567)]: + gy, gx = r0 * 256 + oy + py, c0 * 256 + ox + px + assert tuple(mosaic[py, px]) == (gy % 251, gx % 251, 7)