pub struct TimeSpan {
pub start: TimePoint,
pub end: TimePoint,
}Expand description
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: TimePointThe first time point of the time span (inclusive)
end: TimePointThe last time point of the time span (excluded)
Implementations§
Source§impl TimeSpan
impl TimeSpan
Sourcepub fn new(start: TimePoint, end: TimePoint) -> TimeSpan
pub fn new(start: TimePoint, end: TimePoint) -> TimeSpan
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);Sourcepub fn new_safe(start: TimePoint, end: TimePoint) -> TimeSpan
pub fn new_safe(start: TimePoint, end: TimePoint) -> TimeSpan
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);Sourcepub fn new_copy_with_end(self, new_end: TimePoint) -> TimeSpan
pub fn new_copy_with_end(self, new_end: TimePoint) -> TimeSpan
Sourcepub fn len(self) -> TimeDelta
pub fn len(self) -> TimeDelta
Returns the length of the TimeSpan.
len() is zero, if and only if start is end.
Sourcepub fn half(self) -> TimePoint
pub fn half(self) -> TimePoint
Returns one (of the possibly two) points in the center of the TimeSpan.
Sourcepub fn fast_distance_to(self, other: TimeSpan) -> TimeDelta
pub fn fast_distance_to(self, other: TimeSpan) -> TimeDelta
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);Sourcepub fn get_overlapping_length(self, other: TimeSpan) -> TimeDelta
pub fn get_overlapping_length(self, other: TimeSpan) -> TimeDelta
Returns the smallest difference between two TimeSpans.
Sourcepub fn scaled(self, scaling_factor: f64) -> TimeSpan
pub fn scaled(self, scaling_factor: f64) -> TimeSpan
Scale start and end time point to zero by scaling_factor.