From 480817a5c6e9672861e10f049f35c1ee1ae5e3cb Mon Sep 17 00:00:00 2001 From: Yarchik Date: Wed, 8 Jul 2026 14:34:04 +0100 Subject: [PATCH] fix(deficiency): interpolate between severity matrices The interpolation weight was computed with Math.round on the sub-step remainder, which is always zero, so the blend between neighboring matrices never ran and the severity snapped to the nearest tabulated step. Map severity onto the matrix index and use the fractional part as the blend weight. --- src/deficiency.js | 6 +++--- test/deficiency.test.js | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/deficiency.js b/src/deficiency.js index be66bd09..ec02051e 100644 --- a/src/deficiency.js +++ b/src/deficiency.js @@ -155,9 +155,9 @@ const TRIT = [ ]; const deficiency = (lut, t) => { - let tt = Math.max(0, Math.min(1, t)); - let i = Math.round(tt / 0.1); - let w = Math.round(tt % 0.1); + let tt = Math.max(0, Math.min(1, t)) * (lut.length - 1); + let i = Math.floor(tt); + let w = tt - i; let arr = lut[i]; if (w > 0 && i < lut.length - 1) { let arr_2 = lut[i + 1]; diff --git a/test/deficiency.test.js b/test/deficiency.test.js index c05d12af..cb176a53 100644 --- a/test/deficiency.test.js +++ b/test/deficiency.test.js @@ -14,9 +14,13 @@ test('0 severity', t => { }); test('0.55 severity', t => { - assert.equal(formatHex(filterDeficiencyProt(0.55)('blue')), '#0012ff'); + assert.equal(formatHex(filterDeficiencyProt(0.55)('blue')), '#0011ff'); assert.equal(formatHex(filterDeficiencyDeuter(0.55)('blue')), '#000afa'); - assert.equal(formatHex(filterDeficiencyTrit(0.55)('blue')), '#000fae'); + assert.equal(formatHex(filterDeficiencyTrit(0.55)('blue')), '#000eb6'); +}); + +test('severity interpolates between matrices', t => { + assert.equal(formatHex(filterDeficiencyProt(0.05)('#ff8800')), '#f98900'); }); test('1 severity', t => {