Compare commits

..

2 commits

Author SHA1 Message Date
dlawler489
c81dc68c0b Merge colour-naming fixes
All checks were successful
build-and-push / docker (push) Successful in 14s
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-17 13:12:25 +10:00
dlawler489
08c6dcc432 Name a colour after the everyday filament, not the first match
Seventeen PLA filaments are #000000 and eleven are #FFFFFF, so slot 1 of a
bookmark came out as "Aero Black" — true, but not what anyone calls it. Naming
now prefers Basic, then Matte, before specialist types.

Also puts a space between the "none" badge and the nearest-spool hint, which
were running together as "nonenearest: Jade White".

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-17 13:10:18 +10:00

View file

@ -296,12 +296,17 @@ const COLOUR_TOLERANCE = 50; // keeps #000000 and #161616 (~66 apart) distinct
// The maker's name for a colour, when the palette has one that close. The // The maker's name for a colour, when the palette has one that close. The
// threshold is deliberately tight: this is identification, not substitution. // threshold is deliberately tight: this is identification, not substitution.
function paletteName(hex, material) { function paletteName(hex, material) {
// Seventeen PLA filaments are #000000. Whichever matched first would win, so
// prefer the everyday product — Basic, then Matte — over specialist ones.
const rank = (type) => (type === 'Basic' ? 0 : type === 'Matte' ? 1 : 2);
let best = null; let best = null;
for (const f of palette) { for (const f of palette) {
if (material && filamentType(f.material) !== filamentType(material)) continue; if (material && filamentType(f.material) !== filamentType(material)) continue;
for (const c of f.colours || []) { for (const c of f.colours || []) {
const d = colourDistance(hex, c); const d = colourDistance(hex, c);
if (d !== null && d <= 12 && (!best || d < best.d)) best = { d, name: f.name, type: f.type }; if (d === null || d > 12) continue;
const better = !best || rank(f.type) < rank(best.type) || (rank(f.type) === rank(best.type) && d < best.d);
if (better) best = { d, name: f.name, type: f.type };
} }
} }
return best ? `${best.type} ${best.name}` : null; return best ? `${best.type} ${best.name}` : null;