pub struct Spring2D { /* private fields */ }
Expand description

一个二维弹簧,由两个一维弹簧组成

Implementations§

source§

impl Spring2D

source

pub fn new(start_pos: (f64, f64)) -> Self

根据初始位置创建一个新的弹簧

source

pub fn position(&mut self) -> (f64, f64)

获得当前弹簧所在位置

会因为调用的时间不同而变化

source

pub fn position_rounded(&mut self) -> (f64, f64)

获得当前弹簧所在位置,但是会四舍五入成整数

source

pub fn velocity(&mut self) -> (f64, f64)

获取当前弹簧的移动速度

会因为调用的时间不同而变化

source

pub fn damper(&self) -> f64

获取当前弹簧的阻尼

source

pub fn speed(&self) -> f64

获取弹簧的运行速度

source

pub fn target(&self) -> (f64, f64)

获取弹簧的目标位置

source

pub fn set_position(&mut self, value: (f64, f64))

设置当前位置,注意这不是目标位置,如果当前位置不是目标位置则会发生移动

source

pub fn set_velocity(&mut self, value: (f64, f64))

设置当前速度,此时弹簧会立刻改变速度

source

pub fn set_damper(&mut self, value: f64)

设置弹簧的阻尼

如果取值在 [0.0 - 1.0) 之间则会有回弹效果

如果大于等于 1.0 则会缓慢移动到目标位置而没有回弹效果

source

pub fn set_speed(&mut self, value: f64)

设置弹簧的运行速度,数值越大弹簧的速度就越快

source

pub fn set_target(&mut self, value: (f64, f64))

设置弹簧的目标位置,此时弹簧会立刻开始变换

source

pub fn arrived(&mut self) -> bool

判断弹簧是否已到达目标位置

既速度为零的情况下已到达目标位置

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.