feat: add unique waterbody fingerprints

This commit is contained in:
ik
2026-09-12 15:35:57 +07:00
parent 80d534d549
commit 2ce1e20af2
10 changed files with 65 additions and 14 deletions
+23
View File
@@ -0,0 +1,23 @@
export type WaterbodyVisual = {
shore: number;
waves: number;
markerX: number;
markerY: number;
code: string;
};
export function stableVisualHash(identity: string): number {
return [...identity.trim().toLocaleLowerCase("ru")]
.reduce((hash, char) => Math.imul(hash ^ (char.codePointAt(0) ?? 0), 16777619) >>> 0, 2166136261);
}
export function waterbodyVisual(identity: string): WaterbodyVisual {
const hash = stableVisualHash(identity || "waterbody");
return {
shore: hash % 8,
waves: 1 + ((hash >>> 4) % 3),
markerX: 32 + ((hash >>> 8) % 59),
markerY: 18 + ((hash >>> 15) % 23),
code: hash.toString(36).toUpperCase().padStart(2, "0").slice(-2),
};
}