pub struct TimeRange { /* private fields */ }Expand description
A half-open time range [start, end) in a given Timebase.
Represents the extent of a detected event — for example, a fade-out →
fade-in span. When start == end, the range is degenerate (an instant);
see Self::instant.
Both endpoints share the same Timebase. To compare ranges across
different timebases, rescale one of them first (e.g., by calling
Timestamp::rescale_to on each endpoint).
Implementations§
Source§impl TimeRange
impl TimeRange
Sourcepub const fn new(start: i64, end: i64, timebase: Timebase) -> TimeRange
pub const fn new(start: i64, end: i64, timebase: Timebase) -> TimeRange
Creates a new TimeRange with the given start/end PTS and shared timebase.
§Panics
- Panics if
end < start(negative duration).
Sourcepub const fn try_new(
start: i64,
end: i64,
timebase: Timebase,
) -> Option<TimeRange>
pub const fn try_new( start: i64, end: i64, timebase: Timebase, ) -> Option<TimeRange>
Fallible variant of Self::new: returns None if end < start
instead of panicking. Accepts start == end (degenerate instant range).
Sourcepub const fn instant(ts: Timestamp) -> TimeRange
pub const fn instant(ts: Timestamp) -> TimeRange
Creates a degenerate (instant) range where start == end == ts.pts().
Sourcepub const fn with_start(self, val: i64) -> TimeRange
pub const fn with_start(self, val: i64) -> TimeRange
Sets the start PTS.
Sourcepub const fn with_timebase(self, timebase: Timebase) -> TimeRange
pub const fn with_timebase(self, timebase: Timebase) -> TimeRange
Sets the shared timebase.
Sourcepub const fn set_timebase(&mut self, timebase: Timebase) -> &mut TimeRange
pub const fn set_timebase(&mut self, timebase: Timebase) -> &mut TimeRange
Sets the shared timebase in place.
Sourcepub const fn is_instant(&self) -> bool
pub const fn is_instant(&self) -> bool
Returns true if start == end (a degenerate instant range).
Sourcepub const fn total_pts(&self) -> i64
pub const fn total_pts(&self) -> i64
Returns the span in PTS units (end - start) in this timebase.
Always non-negative given the start <= end constructor invariant.
Saturates at i64::MAX in the pathological case where end - start
would overflow i64 (e.g., start = i64::MIN, end = i64::MAX).
Sourcepub const fn duration(&self) -> Duration
pub const fn duration(&self) -> Duration
Returns the elapsed Duration from start to end, or None if
end is before start.
Sourcepub const fn rescale_to(self, target: Timebase) -> TimeRange
pub const fn rescale_to(self, target: Timebase) -> TimeRange
Returns a new TimeRange representing the same span in a different timebase.
Rescales both endpoints via Timebase::rescale_pts (rounds toward zero);
round-tripping through a coarser timebase can lose precision. Because
rescaling is monotonic, the start <= end invariant is preserved.
Sourcepub const fn interpolate(&self, t: f64) -> Timestamp
pub const fn interpolate(&self, t: f64) -> Timestamp
Linearly interpolates between start and end: t = 0.0 returns
start, t = 1.0 returns end, t = 0.5 the midpoint. t is
clamped to [0.0, 1.0]. Rounds toward zero.
Use this to map an old-style bias value b ∈ [-1, 1] onto the range:
range.interpolate((b + 1.0) * 0.5).
Trait Implementations§
Source§impl<'a> Arbitrary<'a> for TimeRange
impl<'a> Arbitrary<'a> for TimeRange
Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<TimeRange, Error>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<TimeRange, Error>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read more