Advance M8-M11 parity workflows
This commit is contained in:
37
web/protocol/nanovdb-progressive-redraw.ts
Normal file
37
web/protocol/nanovdb-progressive-redraw.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
export const NANOVDB_PROGRESSIVE_REDRAW_MAX_FRAMES = 32;
|
||||
export const NANOVDB_PROGRESSIVE_REDRAW_LIMIT_CODE = "NANOVDB_PROGRESSIVE_REDRAW_LIMIT" as const;
|
||||
|
||||
export interface NanoVDBProgressiveRedrawBudgetResult {
|
||||
allowed: boolean;
|
||||
redrawCount: number;
|
||||
capped: boolean;
|
||||
errorCode: typeof NANOVDB_PROGRESSIVE_REDRAW_LIMIT_CODE | null;
|
||||
}
|
||||
|
||||
export function validateNanoVDBProgressiveRedrawLimit(value: number): number {
|
||||
if (!Number.isSafeInteger(value) || value < 1 || value > 1024) {
|
||||
throw new Error("NANOVDB_INVALID_ARGUMENT: progressive redraw limit must be an integer from 1 to 1024");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function consumeNanoVDBProgressiveRedrawBudget(
|
||||
redrawCount: number,
|
||||
maxRedraws: number,
|
||||
): NanoVDBProgressiveRedrawBudgetResult {
|
||||
if (!Number.isSafeInteger(redrawCount) || redrawCount < 0) {
|
||||
throw new Error("NANOVDB_INVALID_ARGUMENT: progressive redraw count must be a non-negative integer");
|
||||
}
|
||||
const limit = validateNanoVDBProgressiveRedrawLimit(maxRedraws);
|
||||
if (redrawCount >= limit) {
|
||||
return { allowed: false, redrawCount, capped: true, errorCode: NANOVDB_PROGRESSIVE_REDRAW_LIMIT_CODE };
|
||||
}
|
||||
const nextCount = redrawCount + 1;
|
||||
const capped = nextCount >= limit;
|
||||
return {
|
||||
allowed: true,
|
||||
redrawCount: nextCount,
|
||||
capped,
|
||||
errorCode: capped ? NANOVDB_PROGRESSIVE_REDRAW_LIMIT_CODE : null,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user