@playcanvas/splat-transform
Version:
Library and CLI tool for 3D Gaussian splat format conversion and transformation
53 lines (52 loc) • 2.48 kB
TypeScript
/**
* Reusable scratch buffers for `radixSortIndicesByFloat`. One instance is
* shared across many sort calls to avoid allocating multi-MB typed arrays on
* every call. Buffers grow on demand and never shrink.
*
* Only two count-sized buffers are held; the third (encoded keys) is the
* caller's `keys` buffer reinterpreted as u32 and encoded in place. That cuts
* scratch from ~24 N bytes to ~16 N — at 143M edges it saves ~572 MB at peak.
*/
declare class RadixSortScratch {
/** Ping-pong destination for u32 keys. */
keysAlt: Uint32Array;
/** Ping-pong destination for indices. */
indicesAlt: Uint32Array;
/** Per-byte histogram, reused across passes. */
counts: Uint32Array;
constructor();
ensure(count: number): void;
}
/**
* 4-pass LSD radix sort of `indices[0..count)` ascending by the Float32 value
* at the parallel position in `keys`. Mutates `indices` in place.
*
* `keys[i]` is the sort key for `indices[i]` — the two arrays are parallel.
* Callers compute both before calling and the sort permutes them together so
* the parallel relationship is preserved on output.
*
* **`keys` is mutated**: its underlying buffer is reinterpreted as u32 and
* monotonic-encoded in place to save the count-sized scratch buffer that an
* out-of-place encode would need. Callers must treat the Float32 contents of
* `keys` as garbage after this call.
*
* NaN / Inf entries are sorted to one extreme based on their bit pattern.
* Callers that need to reject them should filter before calling. (At
* ~250K-150M elements this is ~20x faster than a JavaScript comparator
* sort.)
*
* @param indices - Integer payload, mutated in place.
* @param keys - Float32 sort keys, parallel to `indices`. Mutated — contents are u32-encoded after this call; treat as garbage.
* @param count - Number of valid entries (length of the parallel prefix).
* @param scratch - Reusable scratch buffers; grown on demand.
*/
declare const radixSortIndicesByFloat: (indices: Uint32Array, keys: Float32Array, count: number, scratch: RadixSortScratch) => void;
/**
* Test whether a Float32 bit pattern represents NaN or ±Inf.
* Useful for callers that want to filter non-finite keys out before sorting.
*
* @param bits - Float32 bit pattern.
* @returns true if the value is NaN or infinite.
*/
declare const isFloatBitsNonFinite: (bits: number) => boolean;
export { RadixSortScratch, radixSortIndicesByFloat, isFloatBitsNonFinite };