MCPcopy Index your code
hub / github.com/ChartGPU/ChartGPU / createMillionPointsData

Function createMillionPointsData

examples/million-points/main.ts:67–113  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65 * Deterministic output ensures reproducible benchmark results across runs.
66 */
67const createMillionPointsData = (): Readonly<{
68 data: ReadonlyArray<DataPoint>;
69 yMin: number;
70 yMax: number;
71}> => {
72 const out: DataPoint[] = new Array(TOTAL_POINTS);
73
74 // Synthetic: sine wave + low-frequency component + uniform noise.
75 const freq = 0.012;
76 const lowFreq = 0.0017;
77 const noiseAmp = 0.35;
78
79 // xorshift32 PRNG (deterministic, no allocations).
80 let state = 0x12345678 | 0;
81 const rand01 = (): number => {
82 state ^= state << 13;
83 state ^= state >>> 17;
84 state ^= state << 5;
85 // Convert to [0, 1).
86 return (state >>> 0) / 4294967296;
87 };
88
89 let yMin = Number.POSITIVE_INFINITY;
90 let yMax = Number.NEGATIVE_INFINITY;
91
92 for (let i = 0; i < TOTAL_POINTS; i++) {
93 const x = i;
94 const y =
95 Math.sin(i * freq) * 0.95 +
96 Math.sin(i * lowFreq + 1.1) * 0.6 +
97 (rand01() - 0.5) * noiseAmp;
98
99 if (y < yMin) yMin = y;
100 if (y > yMax) yMax = y;
101
102 out[i] = [x, y] as const;
103 }
104
105 if (!Number.isFinite(yMin) || !Number.isFinite(yMax)) {
106 yMin = -2;
107 yMax = 2;
108 }
109
110 // Add a small pad to avoid touching edges.
111 const pad = 0.05 * (yMax - yMin || 1);
112 return { data: out, yMin: yMin - pad, yMax: yMax + pad };
113};
114
115/**
116 * Zoom-aware sampling target: zooming in increases target points for detail preservation.

Callers 1

mainFunction · 0.85

Calls 1

rand01Function · 0.85

Tested by

no test coverage detected