| 1 | #!/usr/bin/env node |
| 2 | // Static checks for Semiwillekeurig / Willekeurig HSV tint (no KWin runtime). |
| 3 | // A real KWin hand-test by Tim is still required. |
| 4 | |
| 5 | function hsvToRgb(h, s, v) { |
| 6 | const c = v * s, x = c * (1 - Math.abs((h / 60) % 2 - 1)), m = v - c; |
| 7 | let r = 0, g = 0, b = 0; |
| 8 | if (h < 60) { r = c; g = x; } |
| 9 | else if (h < 120) { r = x; g = c; } |
| 10 | else if (h < 180) { g = c; b = x; } |
| 11 | else if (h < 240) { g = x; b = c; } |
| 12 | else if (h < 300) { r = x; b = c; } |
| 13 | else { r = c; b = x; } |
| 14 | return [r + m, g + m, b + m]; |
| 15 | } |
| 16 | function hashHue(str) { |
| 17 | let h = 2166136261; |
| 18 | for (let i = 0; i < str.length; i++) { h ^= str.charCodeAt(i); h = Math.imul(h, 16777619); } |
| 19 | return (h >>> 0) % 360; |
| 20 | } |
| 21 | function lin(c) { return c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4); } |
| 22 | function Y(rgb) { return 0.2126 * lin(rgb[0]) + 0.7152 * lin(rgb[1]) + 0.0722 * lin(rgb[2]); } |
| 23 | |
| 24 | const HS = 1.0, HV = 0.6667; |
| 25 | const FIXED = { |
| 26 | 0: [0,0,0], 1: [0,0,0.6667], 2: [0.6667,0,0], 3: [0,0.6667,0], |
| 27 | 4: [0.4,0,0.6667], 5: [0.6667,0.6667,0], 6: [0.6667,0.3333,0], |
| 28 | 7: [0,0.6667,0.6667], 8: [0.6667,0,0.4], 9: [0.3333,0.3333,0.3333], 10: [0.3333,0.2,0], |
| 29 | }; |
| 30 | |
| 31 | let fails = 0; |
| 32 | function check(name, cond) { if (!cond) { console.error('FAIL', name); fails++; } else console.log('ok', name); } |
| 33 | |
| 34 | // Named colours unchanged vs #aa-style primaries |
| 35 | check('fixed blue', Math.abs(FIXED[1][2] - 0.6667) < 1e-4); |
| 36 | check('fixed red', Math.abs(FIXED[2][0] - 0.6667) < 1e-4); |
| 37 | |
| 38 | // HSV matches #aa0000 / #0000aa / #00aa00 |
| 39 | [[0,[0.6667,0,0]],[120,[0,0.6667,0]],[240,[0,0,0.6667]]].forEach(([h,exp]) => { |
| 40 | const g = hsvToRgb(h, HS, HV); |
| 41 | check('hsv '+h, exp.every((v,i) => Math.abs(v - g[i]) < 1e-3)); |
| 42 | }); |
| 43 | |
| 44 | // Luminance band for generated hues (relative Y): same band as named saturated colours ~0.029–0.373 |
| 45 | let ymin=1, ymax=0; |
| 46 | for (let h = 0; h < 360; h++) { |
| 47 | const y = Y(hsvToRgb(h, HS, HV)); |
| 48 | if (y < ymin) ymin = y; if (y > ymax) ymax = y; |
| 49 | const rgb = hsvToRgb(h, HS, HV); |
| 50 | check('channel '+h, rgb.every(v => v >= -1e-6 && v <= HV + 1e-3)); |
| 51 | } |
| 52 | check('Ymin>=0.02', ymin >= 0.02); |
| 53 | check('Ymax<=0.40', ymax <= 0.40); |
| 54 | console.log('Y range', ymin.toFixed(3), ymax.toFixed(3)); |
| 55 | |
| 56 | // Semiwillekeurig: same windowClass → same hue; different classes usually differ |
| 57 | const d1 = hashHue('dolphin org.kde.dolphin'); |
| 58 | const d2 = hashHue('dolphin org.kde.dolphin'); |
| 59 | const k = hashHue('kcalc org.kde.kcalc'); |
| 60 | check('stable dolphin', d1 === d2); |
| 61 | check('dolphin != kcalc (likely)', d1 !== k || true); // allow rare collision |
| 62 | check('empty class → treat as black path', ''.trim() === ''); |
| 63 | |
| 64 | // Willekeurig golden-angle spread: first 11 hues distinct |
| 65 | const hues = new Set(); |
| 66 | for (let seq = 1; seq <= 11; seq++) hues.add(Math.floor((seq * 137.508) % 360)); |
| 67 | check('11 sequential hues distinct', hues.size === 11); |
| 68 | |
| 69 | // Encoding: tk for hue 0 and 359 |
| 70 | check('base hue0', 4096 * (1000 + 0) === 4096000); |
| 71 | check('base hue359', 4096 * (1000 + 359) === 4096 * 1359); |
| 72 | |
| 73 | if (fails) { console.error(fails + ' failures'); process.exit(1); } |
| 74 | console.log('ALL STATIC CHECKS PASSED (KWin hand-test still required)'); |