Download viewer/point-sampling.js from yyfz233/Pi4: direct link, hf CLI and curl.
- Browser
- Download file 1.57 kB
-
https://huggingface.co/spaces/yyfz233/Pi4/resolve/main/viewer/point-sampling.js
- Command line
-
hf download hf://spaces/yyfz233/Pi4/viewer/point-sampling.js
-
curl -L -o point-sampling.js https://huggingface.co/spaces/yyfz233/Pi4/resolve/main/viewer/point-sampling.js
1.57 kB
| export const DEFAULT_POINT_BUDGET = 500_000; | |
| export function linspaceIndices(total, limit) { | |
| if (!Number.isSafeInteger(total) || total < 0 || total > 0xffffffff || !Number.isSafeInteger(limit) || limit < 0) throw new Error('Invalid point sampling budget'); | |
| const count = Math.min(total, limit); | |
| const indices = new Uint32Array(count); | |
| for (let index = 0; index < count; index++) indices[index] = count > 1 ? Math.floor(index * (total - 1) / (count - 1)) : 0; | |
| return indices; | |
| } | |
| export class RandomPointSampler { | |
| constructor(capacity, seed = 20261114) { | |
| if (!Number.isSafeInteger(capacity) || capacity < 0 || capacity > 0xffffffff || !Number.isSafeInteger(seed)) throw new Error('Invalid point sampling capacity or seed'); | |
| this.order = new Uint32Array(capacity); | |
| this.count = 0; | |
| this.state = seed >>> 0; | |
| } | |
| sample(total, limit) { | |
| if (!Number.isSafeInteger(total) || total < this.count || total > this.order.length || !Number.isSafeInteger(limit) || limit < 0) throw new Error('Invalid point sampling budget'); | |
| for (let index = this.count; index < total; index++) { | |
| this.state = (this.state + 0x6d2b79f5) >>> 0; | |
| let value = Math.imul(this.state ^ this.state >>> 15, this.state | 1); | |
| value ^= value + Math.imul(value ^ value >>> 7, value | 61); | |
| const selected = Math.floor(((value ^ value >>> 14) >>> 0) / 2 ** 32 * (index + 1)); | |
| this.order[index] = this.order[selected]; | |
| this.order[selected] = index; | |
| } | |
| this.count = total; | |
| return this.order.subarray(0, Math.min(total, limit)); | |
| } | |
| } | |