Skip to main content

SpringTrack

Struct SpringTrack 

Source
pub struct SpringTrack<T: Lerp> { /* private fields */ }
Expand description

弹簧属性轨道:保存当前呈现值、速度、目标值,用弹簧物理推进。

与 PropertyTrack(时长 + 曲线、到点即停)互补:弹簧在进度空间维护 position(0=起点、1=目标,可越过 1 再回弹)与 velocity(进度速度,1/s), 呈现值 = T::lerp(from, to, position)。这样任意 Lerp 类型(含旋转走 最短弧的 Transform2D)都能用同一套弹簧,不必给每种类型定义向量空间。

中断连续:retarget 先结算当前呈现值与速度,以当前值为新 from、 保留速度,再朝新目标推进 —— 中途改向不会瞬间归零或跳变。

确定性:进度用固定子步长 SPRING_STEP_S 半隐式欧拉积分,积分步数只由 now_ms 决定,与帧率/调用间隔无关;同一 now_ms 序列逐位可重放。

Implementations§

Source§

impl<T: Lerp> SpringTrack<T>

Source

pub fn new(initial: T, spring: Spring) -> Self

以 initial 为初始呈现值创建静止轨道。

Source

pub fn with_spring(self, spring: Spring) -> Self

Source

pub fn presented(&self) -> T

Source

pub fn set_presented(&mut self, value: T, now_ms: u64)

live_only 专用:清速度/进度,把呈现值就地钉到 value,逻辑 to 不变。

Source

pub fn settle_live(&mut self, value: T, now_ms: u64)

结束 live 接管,把终值同时写回呈现位与逻辑目标。

Source

pub fn target(&self) -> T

Source

pub fn is_animating(&self) -> bool

Source

pub fn is_settled(&self) -> bool

Source

pub fn velocity(&self) -> f32

当前进度速度(1/s);供观测“retarget 保留速度“。

Source

pub fn retarget(&mut self, target: T, now_ms: u64)

从当前呈现值起,在 now_ms 时刻重定向到 target,保留速度。

先按 now_ms 结算当前呈现值与速度,再以当前值为新 from —— 与 PropertyTrack::retarget 同为中断连续的来源,只是多带一份速度。

Source

pub fn tick(&mut self, now_ms: u64) -> T

推进到 now_ms,返回结算后的呈现值。在 State::tick 里每帧调用一次。

Trait Implementations§

Source§

impl<T: Clone + Lerp> Clone for SpringTrack<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Lerp> Debug for SpringTrack<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Lerp> Track<T> for SpringTrack<T>

Source§

fn presented(&self) -> T

Source§

fn target(&self) -> T

Source§

fn set_presented(&mut self, value: T, now_ms: u64)

live_only 呈现位直写;不产生响应式副作用、不改逻辑目标。
Source§

fn settle_live(&mut self, value: T, now_ms: u64)

结束 live 接管并把终值结算为新的逻辑目标。
Source§

fn tick(&mut self, now_ms: u64) -> T

Source§

fn retarget(&mut self, target: T, now_ms: u64)

Source§

fn is_animating(&self) -> bool

Source§

fn is_settled(&self) -> bool

Auto Trait Implementations§

§

impl<T> Forget for SpringTrack<T>

§

impl<T> Freeze for SpringTrack<T>
where T: Freeze,

§

impl<T> Move for SpringTrack<T>

§

impl<T> RefUnwindSafe for SpringTrack<T>
where T: RefUnwindSafe,

§

impl<T> Send for SpringTrack<T>
where T: Send,

§

impl<T> Sync for SpringTrack<T>
where T: Sync,

§

impl<T> Unpin for SpringTrack<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for SpringTrack<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for SpringTrack<T>
where T: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.