classicCanvasHeat.test.ts
3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* 经典单笔热力层契约(第三十五轮:全市视野长尾重标定):
* 1) 半径 36px 绝对像素 = 业务格距 72px 的半格,光斑直径正好铺满一格不留冷缝;
* 2) 每桶 globalAlpha = (count/max)^0.6,封顶 1 —— 开方抬中段、头部仍到红端;
* 3) 笔刷中心 30% 半径饱和平台 + 外面线性衰减 —— 红心大过白盘才看得见;
* 4) 灰度 alpha → palette 直取,输出 alpha clamp 到 minOpacity~opacity。
*/
import { describe, expect, it } from 'vitest';
import {
CLASSIC_FLAT,
CLASSIC_GAMMA,
CLASSIC_RADIUS_PX,
classicBrushAlphaAt,
classicWeightToAlpha,
smoothMax,
} from './ClassicCanvasHeatLayer';
describe('经典单笔权重:(count/max)^0.6,抬中段、头部封顶', () => {
it('单调、端点封顶、不越界', () => {
expect(classicWeightToAlpha(0, 100)).toBe(0);
expect(classicWeightToAlpha(25, 100)).toBeCloseTo(Math.pow(0.25, CLASSIC_GAMMA), 6);
expect(classicWeightToAlpha(100, 100)).toBe(1);
expect(classicWeightToAlpha(400, 100)).toBe(1);
expect(classicWeightToAlpha(10, 0)).toBe(1);
});
it('全市长尾里中段抬到绿黄、头部红端、尾部仍压住', () => {
// P82≈500:count=58 线性 0.116 → 0.27;323→0.77;头部封顶;单点 0.002→0.024
expect(classicWeightToAlpha(58, 500)).toBeGreaterThan(0.25);
expect(classicWeightToAlpha(323, 500)).toBeGreaterThan(0.7);
expect(classicWeightToAlpha(323, 500)).toBeLessThan(0.85);
expect(classicWeightToAlpha(880, 500)).toBe(1);
expect(classicWeightToAlpha(1, 500)).toBeLessThan(0.05);
});
it('恒等权重下中段确实被抬起来(热力面不再消失)', () => {
expect(CLASSIC_GAMMA).toBeCloseTo(0.6, 6);
expect(classicWeightToAlpha(50, 250)).toBeGreaterThan(0.35);
expect(classicWeightToAlpha(50, 250)).toBeLessThan(0.45);
});
});
describe('单笔软刷:饱和平台 + 外面同心环', () => {
it('平台内饱和、边缘归零、平台外线性衰减', () => {
expect(classicBrushAlphaAt(0)).toBe(1);
expect(classicBrushAlphaAt(CLASSIC_FLAT * 0.5)).toBe(1);
expect(classicBrushAlphaAt(CLASSIC_FLAT)).toBe(1);
expect(classicBrushAlphaAt(0.5)).toBeCloseTo((1 - 0.5) / (1 - CLASSIC_FLAT), 6);
expect(classicBrushAlphaAt(1)).toBeCloseTo(0, 6);
expect(classicBrushAlphaAt(2)).toBe(0);
});
it('红心半径 = 36px × 30% = 10.8px,大过 11px 白盘的半径量级', () => {
expect(CLASSIC_FLAT).toBeCloseTo(0.3, 6);
expect(CLASSIC_RADIUS_PX * CLASSIC_FLAT).toBeGreaterThan(10);
});
});
describe('经典口径常量', () => {
it('半径 = 业务格距 72px 的一半,光斑铺满一格不留冷缝', () => {
expect(CLASSIC_RADIUS_PX).toBe(36);
});
});
describe('数字层分母仍逐帧逼近', () => {
it('单调收敛、端点吸附', () => {
expect(smoothMax(1, 100)).toEqual({ value: 36, settled: false });
expect(smoothMax(99, 100).settled).toBe(true);
expect(smoothMax(100, 100)).toEqual({ value: 100, settled: true });
});
});