Compare commits
2 commits
d6ad49d9cb
...
c81dc68c0b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c81dc68c0b | ||
|
|
08c6dcc432 |
1 changed files with 7 additions and 2 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue