Lineweight to stored index
ExactThe index written for a lineweight, or the codes for by layer, by block and default.
index of the list value with the smallest |value − lineweight|
A lineweight between two list values is stored as the nearer one: 0.45 mm becomes 0.40 mm, because the comparison is strict and the first of two equally near values wins. A lineweight above 2.11 mm becomes 2.11 mm.
export function lineweightIndex(lw) {
if (lw === -1) return 29;
if (lw === -2) return 30;
if (lw === -3 || lw == null) return 31;
let best = 0;
for (let i = 0; i < LINEWEIGHTS.length; i++) if (Math.abs(LINEWEIGHTS[i] - lw) < Math.abs(LINEWEIGHTS[best] - lw)) best = i;
return best;
}