( data: ReadonlyArray<DataPoint> | Float32Array, targetPoints: number )
| 175 | export function lttbSample(data: DataPoint[], targetPoints: number): DataPoint[]; |
| 176 | export function lttbSample(data: ReadonlyArray<DataPoint>, targetPoints: number): ReadonlyArray<DataPoint>; |
| 177 | export function lttbSample( |
| 178 | data: ReadonlyArray<DataPoint> | Float32Array, |
| 179 | targetPoints: number |
| 180 | ): ReadonlyArray<DataPoint> | Float32Array { |
| 181 | const threshold = Math.floor(targetPoints); |
| 182 | |
| 183 | if (data instanceof Float32Array) { |
| 184 | const n = data.length >>> 1; |
| 185 | if (threshold <= 0 || n === 0) return new Float32Array(0); |
| 186 | |
| 187 | // If we're already under the target, avoid copying. |
| 188 | if (n <= threshold) return data; |
| 189 | |
| 190 | const indices = lttbIndicesForInterleavedXY(data, threshold); |
| 191 | const out = new Float32Array(indices.length * 2); |
| 192 | for (let i = 0; i < indices.length; i++) { |
| 193 | const idx = indices[i]!; |
| 194 | out[i * 2 + 0] = data[idx * 2 + 0]; |
| 195 | out[i * 2 + 1] = data[idx * 2 + 1]; |
| 196 | } |
| 197 | return out; |
| 198 | } |
| 199 | |
| 200 | const n = data.length; |
| 201 | if (threshold <= 0 || n === 0) return []; |
| 202 | |
| 203 | // Story requirement: when data is shorter than the target, return original. |
| 204 | if (n <= threshold) return data; |
| 205 | |
| 206 | const indices = lttbIndicesForDataPoints(data, threshold); |
| 207 | const out = new Array<DataPoint>(indices.length); |
| 208 | for (let i = 0; i < indices.length; i++) { |
| 209 | out[i] = data[indices[i]!]!; |
| 210 | } |
| 211 | return out; |
| 212 | } |
| 213 |
no test coverage detected