[][src]Struct alass_core::TimeSpan

pub struct TimeSpan {
    pub start: TimePoint,
    pub end: TimePoint,
}

Represents a time span from "start" (included) to "end" (excluded).

The constructors will ensure "start <= end", this condition will hold at any given time.

Fields

start: TimePoint

The first time point of the time span (inclusive)

end: TimePoint

The last time point of the time span (excluded)

Methods

impl TimeSpan[src]

pub fn new(start: TimePoint, end: TimePoint) -> TimeSpan[src]

Create a new TimeSpan with start and end.

Examples

use alass_core::{TimeSpan, TimePoint};

let t0 = TimePoint::from(0);
let t10 = TimePoint::from(10);

let ts = TimeSpan::new(t0, t10);

Panics

This function asserts that start is less or equal end.

use alass_core::{TimeSpan, TimePoint};

let t0 = TimePoint::from(0);
let t10 = TimePoint::from(10);

// this will case a panic
let ts = TimeSpan::new(t10, t0);

pub fn new_safe(start: TimePoint, end: TimePoint) -> TimeSpan[src]

Create a new TimeSpan with start and end. This function will not panic on end < start, but swap the values before calling TimeSpan::new().

Examples

use alass_core::{TimeSpan, TimePoint};

let t0 = TimePoint::from(0);
let t10 = TimePoint::from(10);

let ts = TimeSpan::new_safe(t10, t0);
assert!(ts.start() == t0 && ts.end() == t10);

pub fn new_copy_with_end(self, new_end: TimePoint) -> TimeSpan[src]

Mutates a TimeSpans end.

Panics

Will panic if new_end is less than current start.

pub fn len(self) -> TimeDelta[src]

Returns the length of the TimeSpan.

len() is zero, if and only if start is end.

pub fn is_empty(self) -> bool[src]

Returns true if start == end.

pub fn start(self) -> TimePoint[src]

Returns the start point of the TimeSpan.

pub fn end(self) -> TimePoint[src]

Returns the end point of the TimeSpan.

pub fn half(self) -> TimePoint[src]

Returns one (of the possibly two) points in the center of the TimeSpan.

pub fn contains(self, other: TimeSpan) -> bool[src]

Returns true if self contains TimeSpan other.

Examples

use alass_core::{TimeSpan, TimePoint};

pub fn fast_distance_to(self, other: TimeSpan) -> TimeDelta[src]

Returns the smallest difference between two TimeSpans.

use alass_core::{TimeSpan, TimePoint, TimeDelta};

let p = TimePoint::from(0);
let d = TimeDelta::one();

let ts1 = TimeSpan::new(p, p + 10 * d);
let ts4 = TimeSpan::new(p + 20 * d, p + 100 * d);

assert!(TimeSpan::fast_distance_to(ts1, ts1) == 0 * d);
assert!(TimeSpan::fast_distance_to(ts1, ts4) == 10 * d);
assert!(TimeSpan::fast_distance_to(ts4, ts1) == 10 * d);
assert!(TimeSpan::fast_distance_to(ts4, ts4) == 0 * d);

pub fn get_overlapping_length(self, other: TimeSpan) -> TimeDelta[src]

Returns the smallest difference between two TimeSpans.

pub fn scaled(self, scaling_factor: f64) -> TimeSpan[src]

Scale start and end time point to zero by scaling_factor.

pub fn cmp_start(self, other: TimeSpan) -> Ordering[src]

Compares two TimeSpans by their start timepoint.

pub fn cmp_end(self, other: TimeSpan) -> Ordering[src]

Compares two TimeSpans by their end timepoint.

Trait Implementations

impl Clone for TimeSpan[src]

impl Copy for TimeSpan[src]

impl Eq for TimeSpan[src]

impl PartialEq<TimeSpan> for TimeSpan[src]

impl Debug for TimeSpan[src]

impl Add<TimeDelta> for TimeSpan[src]

type Output = TimeSpan

The resulting type after applying the + operator.

impl Hash for TimeSpan[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]