Struct crystalorb::timestamp::FloatTimestamp[][src]

pub struct FloatTimestamp(_);
Expand description

Representation of time in the same units as Timestamp, but whereas Timestamp identifies which whole number of frames only, FloatTimestamp can represent any time in the continuous region between two adjacent frames.

Implementations

Convert the time from seconds into Timestamp units (1 per frame, i.e. 1 per timestep), and fit it into the Timestamp space.

Fit the time in Timestamp units into the Timestamp space by wrapping.

Find the corresponding time in seconds for this float timestamp. Since timestamps repeat over time, this function returns the time closest to zero. This makes it useful to find the number of seconds between two float timestamps.

Example
use crystalorb::timestamp::FloatTimestamp;
use float_cmp::approx_eq;
const TIMESTEP: f64 = 1.0 / 60.0;

// Given two float timestamps.
let t1 = FloatTimestamp::from_unwrapped(123.2);
let t2 = FloatTimestamp::from_unwrapped(123.7);

// We can get the seconds between these two float timestamps.
let seconds_difference = (t2 - t1).as_seconds(TIMESTEP);
assert!(approx_eq!(f64, seconds_difference, 0.5 / 60.0, ulps=1));

Round up to the next whole-number Timestamp (or its own value if it is already a whole number).

Example
use crystalorb::timestamp::{FloatTimestamp, Timestamp};

let t1 = FloatTimestamp::from_unwrapped(123.4);
let t2 = FloatTimestamp::from_unwrapped(123.0);

assert_eq!(t1.ceil(), Timestamp::default() + 124);
assert_eq!(t2.ceil(), Timestamp::default() + 123);

Round down to the previous whole-number Timestamp (or its own value if it is already a whole number).

Example
use crystalorb::timestamp::{FloatTimestamp, Timestamp};

let t1 = FloatTimestamp::from_unwrapped(123.4);
let t2 = FloatTimestamp::from_unwrapped(123.0);

assert_eq!(t1.floor(), Timestamp::default() + 123);
assert_eq!(t2.floor(), Timestamp::default() + 123);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

Performs the conversion.

Performs the conversion.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more