All checks were successful
standards workspaces build + test / jouleclaw-rs (pull_request) Successful in 2m16s
standards workspaces build + test / aac-rs (pull_request) Successful in 1m35s
standards workspaces build + test / joule-code-rs (pull_request) Successful in 51s
standards workspaces build + test / joulecontract-rs (pull_request) Successful in 34s
standards workspaces build + test / map-rs (pull_request) Successful in 31s
standards workspaces build + test / mesh-rs (pull_request) Successful in 30s
standards workspaces build + test / openpay (pull_request) Successful in 1m40s
WAI conformance / cargo-class corpora · linux-arm64 (pull_request) Successful in 7m35s
WAI conformance / cross-arch byte-equality · linux-arm64 (pull_request) Successful in 27s
WAI energy receipts / energy receipts · linux-arm64 (pull_request) Successful in 2m6s
wai-vector vector graphics / linux-aarch64 (pull_request) Successful in 25s
standards workspaces build + test / jouledesk-rs (pull_request) Successful in 3m28s
standards workspaces build + test / macOS energy backends (pull_request) Successful in 8m4s
WAI conformance / cargo-class corpora · macos (pull_request) Successful in 12m12s
WAI conformance / cross-arch byte-equality · macos (pull_request) Successful in 34s
WAI energy receipts / energy receipts · macos (pull_request) Successful in 4m9s
wai-vector vector graphics / macos-arm64 (pull_request) Successful in 31s
no-vanity-metrics / Scan committed Markdown for vanity metrics (pull_request) Successful in 6s
no-vanity-metrics / WAI public text names no comparison (pull_request) Successful in 5s
no-vanity-metrics / WAI public text names no company or product (pull_request) Successful in 5s
standards workspaces build + test / arl-rs (pull_request) Successful in 1m15s
standards workspaces build + test / eoc-rs (pull_request) Successful in 2m6s
standards workspaces build + test / jcp-rs (pull_request) Successful in 1m35s
standards workspaces build + test / joule-ui-rs (pull_request) Successful in 1m15s
standards workspaces build + test / joulehook-rs (pull_request) Successful in 1m16s
standards workspaces build + test / proof-rs (pull_request) Successful in 1m22s
standards workspaces build + test / sense-rs (pull_request) Successful in 1m19s
standards workspaces build + test / sandbox-rs (pull_request) Successful in 2m26s
standards workspaces build + test / smart-byte-rs (pull_request) Successful in 4m14s
WAI conformance / quantum core and corpus under wasm32-wasip2 (wasmtime) (pull_request) Successful in 1m24s
WAI conformance / v2 vocabulary · manifests validate as stated (pull_request) Successful in 16s
WAI conformance / cargo-class corpora · linux (pull_request) Successful in 8m43s
WAI conformance / delivery telemetry · CMCD and CMSD against an independent library (pull_request) Successful in 10s
WAI conformance / cross-arch byte-equality · linux (pull_request) Successful in 31s
WAI conformance / C2PA manifest emission · signed, read back, validated (pull_request) Successful in 54s
WAI energy receipts / energy receipts · linux (pull_request) Successful in 2m3s
WAI section references / cited sections exist (pull_request) Successful in 10s
wai-vector vector graphics / linux-x86_64 (pull_request) Successful in 24s
wai-vector vector graphics / wasm32-wasip2 (wasmtime) (pull_request) Successful in 21s
wai-vector vector graphics / wasm32 under Node (pull_request) Successful in 19s
wai-vector vector graphics / fuzz, peak allocation, comparison count (pull_request) Successful in 14s
workflow hygiene / every workflow supersedes its own queue (pull_request) Successful in 4s
WAI conformance / independent verifiers · claims, JWP, key discovery and integer payloads (Python) (pull_request) Successful in 16m51s
Co-Authored-By: Claude Opus 5.5 <[email protected]>
38 lines
1.6 KiB
Rust
38 lines
1.6 KiB
Rust
//! The clock (§3.1) and the frame range (§2.7, *Render*).
|
||
//!
|
||
//! A frame `g` is in range at a rate with `P` ticks per frame when
|
||
//! `⌈t0/P⌉ ≤ g ≤ ⌊(t0 + dur − 1)/P⌋`. The range is decided by those divisions and
|
||
//! never by forming `g·P` for an unchecked `g`: `P` reaches 2^40, so the product of an
|
||
//! arbitrary request and `P` does not fit 64 bits.
|
||
|
||
use crate::arith::{ceil_div, floor_div};
|
||
|
||
/// The first and last frame of the document at `P` ticks per frame. The range is
|
||
/// empty when the first exceeds the last.
|
||
pub fn frame_range(t0: u32, dur: u32, p: u64) -> (i64, i64) {
|
||
debug_assert!((1..=1 << 40).contains(&p));
|
||
let p = p as i64;
|
||
let first = ceil_div(i64::from(t0), p);
|
||
let last = floor_div(i64::from(t0) + i64::from(dur) - 1, p);
|
||
(first, last)
|
||
}
|
||
|
||
/// Whether frame `g` is in the document at `P` ticks per frame.
|
||
pub fn in_range(g: u64, t0: u32, dur: u32, p: u64) -> bool {
|
||
let (first, last) = frame_range(t0, dur, p);
|
||
// `first` and `last` lie in [0, 2^31), so the comparisons are exact for any `g`.
|
||
first <= last && (first as u64) <= g && g <= last as u64
|
||
}
|
||
|
||
/// The tick of a frame in range, `τ = g·P`, which is below 2^31.
|
||
pub fn tick(g: u64, p: u64) -> i64 {
|
||
let t = g * p;
|
||
debug_assert!(t < 1 << 31);
|
||
t as i64
|
||
}
|
||
|
||
/// The frames of the document at `P` ticks per frame, as `first..=last`.
|
||
pub fn frames(t0: u32, dur: u32, p: u64) -> core::ops::RangeInclusive<u64> {
|
||
let (first, last) = frame_range(t0, dur, p);
|
||
if first > last { core::ops::RangeInclusive::new(1, 0) } else { first as u64..=last as u64 }
|
||
}
|