Skip to main content

TcMath

Struct TcMath 

Source
pub struct TcMath;
Expand description

Stateless utility for timecode mathematical operations.

§Example

use oximedia_timecode::tc_math::{TcMath, TcDuration};

let dur = TcDuration::from_hmsf(0, 1, 0, 0, 25); // 1 minute
let mid = TcMath::midpoint_between_durations(&TcDuration::from_frames(0, 25), &dur);
assert_eq!(mid.frames, 750); // 30 seconds at 25fps

Implementations§

Source§

impl TcMath

Source

pub fn duration_between(a: &Timecode, b: &Timecode) -> TcDuration

Compute the duration between two timecodes (absolute value).

Source

pub fn midpoint( a: &Timecode, b: &Timecode, rate: FrameRate, ) -> Result<Timecode, TimecodeError>

Compute the midpoint timecode between two timecodes.

Source

pub fn offset_by_percentage( tc: &Timecode, duration: &TcDuration, pct: f64, rate: FrameRate, ) -> Result<Timecode, TimecodeError>

Offset a timecode by a percentage of a duration.

Source

pub fn midpoint_between_durations(a: &TcDuration, b: &TcDuration) -> TcDuration

Compute the midpoint between two durations (not anchored to a TOD).

Source

pub fn position_percentage( tc: &Timecode, start: &Timecode, end: &Timecode, ) -> f64

Compute a percentage position of a timecode within a range.

Source

pub fn rate_conversion_factor(from: FrameRate, to: FrameRate) -> f64

Compute the frame rate conversion factor between two rates.

Source

pub fn convert_frame_count(frames: u64, from: FrameRate, to: FrameRate) -> u64

Convert a frame count from one frame rate to another.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.