feat(coords): Chunk-Namen als Planquadrat A1 bis L12

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
knsoandClaude Haiku 4.5 committed 2026-09-13 09:26:59 +02:00
1 parent 44108f94f4
commit 2f63779363
5 files changed
+120 -2

No files matched your search

+22
View File
@@ -25,3 +25,25 @@ export function chunkForWorld(X, Y) {
export function chunkOrigin(i, j) {
return { X: SLICE.x0 + i * CHUNK_SIZE, Y: SLICE.y1 - j * CHUNK_SIZE };
}
const CHUNK_COLUMNS = "ABCDEFGHIJKL";
const CHUNK_NAME_PATTERN = /^([A-La-l])([1-9]\d?)$/;
/**
* Planquadrat-Name eines Chunks: Spalte A–L aus i (West → Ost), Zeile 1–12 aus j (Nord → Süd).
* A1 ist die Nordwest-Ecke, weil chunkOrigin i nach Osten und j von der Nordkante nach Süden zählt.
* Die Namen sind die Schnittstelle zur Feinkalibrierung: was im Chat "C10" heißt, ist chunk_2_9.
*/
export function chunkName(i, j) {
const inside = (k) => Number.isInteger(k) && k >= 0 && k < CHUNKS_PER_SIDE;
return inside(i) && inside(j) ? CHUNK_COLUMNS[i] + (j + 1) : null;
}
/** Umkehrung von chunkName. Akzeptiert Kleinschreibung, liefert null für alles außerhalb A1–L12. */
export function parseChunkName(name) {
const match = CHUNK_NAME_PATTERN.exec(String(name));
if (!match) return null;
const row = Number(match[2]);
if (row > CHUNKS_PER_SIDE) return null;
return { i: CHUNK_COLUMNS.indexOf(match[1].toUpperCase()), j: row - 1 };
}