From 08c6dcc4325c3ee9606a94d30028a429d0230c64 Mon Sep 17 00:00:00 2001 From: dlawler489 <104159223@student.swin.edu.au> Date: Thu, 17 Sep 2026 13:10:18 +1000 Subject: [PATCH] Name a colour after the everyday filament, not the first match MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- public/app.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/public/app.js b/public/app.js index bc977f7..d798cca 100644 --- a/public/app.js +++ b/public/app.js @@ -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 // threshold is deliberately tight: this is identification, not substitution. 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; for (const f of palette) { if (material && filamentType(f.material) !== filamentType(material)) continue; for (const c of f.colours || []) { 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; @@ -2151,7 +2156,7 @@ function renderDetailPrintable(model) { })()} ${s.filled ? `${escapeHtml(s.by)}` - : `none${s.nearest + : `none ${s.nearest ? `nearest: ${escapeHtml(s.nearest.name)}` : ''}`} `).join(''); el.innerHTML = `
${p.ok