Compare commits

..

No commits in common. "c81dc68c0b99b6026ab36da00b6894a71ae97298" and "d6ad49d9cb5e95753162fdd7a23bcf0434c73275" have entirely different histories.

View file

@ -296,17 +296,12 @@ 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) continue; if (d !== null && d <= 12 && (!best || d < best.d)) best = { d, name: f.name, type: f.type };
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;
@ -2156,7 +2151,7 @@ function renderDetailPrintable(model) {
})()}</span> })()}</span>
${s.filled ${s.filled
? `<span class="print-badge ok">${escapeHtml(s.by)}</span>` ? `<span class="print-badge ok">${escapeHtml(s.by)}</span>`
: `<span class="print-badge no">none</span> ${s.nearest : `<span class="print-badge no">none</span>${s.nearest
? `<span class="form-hint">nearest: ${escapeHtml(s.nearest.name)}</span>` : ''}`} ? `<span class="form-hint">nearest: ${escapeHtml(s.nearest.name)}</span>` : ''}`}
</div>`).join(''); </div>`).join('');
el.innerHTML = `<div>${p.ok el.innerHTML = `<div>${p.ok