Trait veloren_voxygen::scene::math::Lerp
source · pub trait Lerp<Factor = f32>: Sized {
type Output;
// Required method
fn lerp_unclamped(from: Self, to: Self, factor: Factor) -> Self::Output;
// Provided methods
fn lerp_unclamped_inclusive_range(
range: RangeInclusive<Self>,
factor: Factor,
) -> Self::Output { ... }
fn lerp_unclamped_precise(
from: Self,
to: Self,
factor: Factor,
) -> Self::Output { ... }
fn lerp_unclamped_precise_inclusive_range(
range: RangeInclusive<Self>,
factor: Factor,
) -> Self::Output { ... }
fn lerp(from: Self, to: Self, factor: Factor) -> Self::Output
where Factor: Clamp + Zero + One { ... }
fn lerp_inclusive_range(
range: RangeInclusive<Self>,
factor: Factor,
) -> Self::Output
where Factor: Clamp + Zero + One { ... }
fn lerp_precise(from: Self, to: Self, factor: Factor) -> Self::Output
where Factor: Clamp + Zero + One { ... }
fn lerp_precise_inclusive_range(
range: RangeInclusive<Self>,
factor: Factor,
) -> Self::Output
where Factor: Clamp + Zero + One { ... }
}
Expand description
A value that can be linearly interpolated.
Note that, like standard operators, this can be implement for T
and &T
.
You would make the difference like so:
use vek::ops::Lerp;
let a = Lerp::lerp(0, 10, 0.5_f32);
let b = Lerp::lerp(&0, &10, 0.5_f32);
let c = i32::lerp(0, 10, 0.5_f32);
let d = <&i32>::lerp(&0, &10, 0.5_f32);
assert_eq!(a, b);
assert_eq!(a, c);
assert_eq!(a, d);
This is made possible thanks to the explicit Output
type.
Therefore, it’s also convenient for GameState
structures, which you might
prefer to interpolate by reference instead of consuming them.
The interpolation of two &GameState
s would produce a new GameState
value.
use vek::{Lerp, Vec3};
/// A data-heavy structure that represents a current game state.
/// It's neither Copy and nor even Clone!
struct GameState {
pub camera_position: Vec3<f32>,
// ... obviously a lot of other members following ...
}
// We can select the Progress type. I chose f64; the default is f32.
impl<'a> Lerp<f64> for &'a GameState {
type Output = GameState;
fn lerp_unclamped(a: Self, b: Self, t: f64) -> GameState {
GameState {
camera_position: Lerp::lerp(a.camera_position, b.camera_position, t as f32),
// ... etc for all relevant members...
}
}
}
let a = GameState { camera_position: Vec3::zero() };
let b = GameState { camera_position: Vec3::unit_x() };
let c = Lerp::lerp(&a, &b, 0.5);
// Hurray! We've got an interpolated state without consuming the two previous ones.
Required Associated Types§
Required Methods§
sourcefn lerp_unclamped(from: Self, to: Self, factor: Factor) -> Self::Output
fn lerp_unclamped(from: Self, to: Self, factor: Factor) -> Self::Output
Returns the linear interpolation of from
to to
with factor
unconstrained,
using the supposedly fastest but less precise implementation.
A possible implementation is from + factor * (to - from)
, a.k.a
factor.mul_add(to - from, from)
.
use vek::ops::Lerp;
assert_eq!(Lerp::lerp_unclamped(10, 20, -1.0_f32), 0);
assert_eq!(Lerp::lerp_unclamped(10, 20, -0.5_f32), 5);
assert_eq!(Lerp::lerp_unclamped(10, 20, 0.0_f32), 10);
assert_eq!(Lerp::lerp_unclamped(10, 20, 0.5_f32), 15);
assert_eq!(Lerp::lerp_unclamped(10, 20, 1.0_f32), 20);
assert_eq!(Lerp::lerp_unclamped(10, 20, 1.5_f32), 25);
Provided Methods§
sourcefn lerp_unclamped_inclusive_range(
range: RangeInclusive<Self>,
factor: Factor,
) -> Self::Output
fn lerp_unclamped_inclusive_range( range: RangeInclusive<Self>, factor: Factor, ) -> Self::Output
Version of lerp_unclamped()
that used a single RangeInclusive
parameter instead of two values.
sourcefn lerp_unclamped_precise(from: Self, to: Self, factor: Factor) -> Self::Output
fn lerp_unclamped_precise(from: Self, to: Self, factor: Factor) -> Self::Output
Returns the linear interpolation of from
to to
with factor
unconstrained,
using a possibly slower but more precise operation.
A possible implementation is from*(1-factor) + to*factor
, a.k.a
from.mul_add(1-factor, to*factor)
.
use vek::ops::Lerp;
assert_eq!(Lerp::lerp_unclamped_precise(10, 20, -1.0_f32), 0);
assert_eq!(Lerp::lerp_unclamped_precise(10, 20, -0.5_f32), 5);
assert_eq!(Lerp::lerp_unclamped_precise(10, 20, 0.0_f32), 10);
assert_eq!(Lerp::lerp_unclamped_precise(10, 20, 0.5_f32), 15);
assert_eq!(Lerp::lerp_unclamped_precise(10, 20, 1.0_f32), 20);
assert_eq!(Lerp::lerp_unclamped_precise(10, 20, 1.5_f32), 25);
sourcefn lerp_unclamped_precise_inclusive_range(
range: RangeInclusive<Self>,
factor: Factor,
) -> Self::Output
fn lerp_unclamped_precise_inclusive_range( range: RangeInclusive<Self>, factor: Factor, ) -> Self::Output
Version of lerp_unclamped_precise()
that used a single RangeInclusive
parameter instead of two values.
sourcefn lerp(from: Self, to: Self, factor: Factor) -> Self::Output
fn lerp(from: Self, to: Self, factor: Factor) -> Self::Output
Alias to lerp_unclamped
which constrains factor
to be between 0 and 1
(inclusive).
use vek::ops::Lerp;
assert_eq!(Lerp::lerp(10, 20, -1.0_f32), 10);
assert_eq!(Lerp::lerp(10, 20, -0.5_f32), 10);
assert_eq!(Lerp::lerp(10, 20, 0.0_f32), 10);
assert_eq!(Lerp::lerp(10, 20, 0.5_f32), 15);
assert_eq!(Lerp::lerp(10, 20, 1.0_f32), 20);
assert_eq!(Lerp::lerp(10, 20, 1.5_f32), 20);
sourcefn lerp_inclusive_range(
range: RangeInclusive<Self>,
factor: Factor,
) -> Self::Output
fn lerp_inclusive_range( range: RangeInclusive<Self>, factor: Factor, ) -> Self::Output
Version of lerp()
that used a single RangeInclusive
parameter instead of two values.
sourcefn lerp_precise(from: Self, to: Self, factor: Factor) -> Self::Output
fn lerp_precise(from: Self, to: Self, factor: Factor) -> Self::Output
Alias to lerp_unclamped_precise
which constrains factor
to be between 0 and 1
(inclusive).
use vek::ops::Lerp;
assert_eq!(Lerp::lerp_precise(10, 20, -1.0_f32), 10);
assert_eq!(Lerp::lerp_precise(10, 20, -0.5_f32), 10);
assert_eq!(Lerp::lerp_precise(10, 20, 0.0_f32), 10);
assert_eq!(Lerp::lerp_precise(10, 20, 0.5_f32), 15);
assert_eq!(Lerp::lerp_precise(10, 20, 1.0_f32), 20);
assert_eq!(Lerp::lerp_precise(10, 20, 1.5_f32), 20);
sourcefn lerp_precise_inclusive_range(
range: RangeInclusive<Self>,
factor: Factor,
) -> Self::Output
fn lerp_precise_inclusive_range( range: RangeInclusive<Self>, factor: Factor, ) -> Self::Output
Version of lerp_precise()
that used a single RangeInclusive
parameter instead of two values.
Object Safety§
Implementations on Foreign Types§
source§impl<'a, Factor> Lerp<Factor> for &'a ArthropodSkeleton
impl<'a, Factor> Lerp<Factor> for &'a ArthropodSkeleton
type Output = ArthropodSkeleton
fn lerp_unclamped_precise( from: &'a ArthropodSkeleton, to: &'a ArthropodSkeleton, factor: Factor, ) -> <&'a ArthropodSkeleton as Lerp<Factor>>::Output
fn lerp_unclamped( from: &'a ArthropodSkeleton, to: &'a ArthropodSkeleton, factor: Factor, ) -> <&'a ArthropodSkeleton as Lerp<Factor>>::Output
source§impl<'a, Factor> Lerp<Factor> for &'a BipedLargeSkeleton
impl<'a, Factor> Lerp<Factor> for &'a BipedLargeSkeleton
type Output = BipedLargeSkeleton
fn lerp_unclamped_precise( from: &'a BipedLargeSkeleton, to: &'a BipedLargeSkeleton, factor: Factor, ) -> <&'a BipedLargeSkeleton as Lerp<Factor>>::Output
fn lerp_unclamped( from: &'a BipedLargeSkeleton, to: &'a BipedLargeSkeleton, factor: Factor, ) -> <&'a BipedLargeSkeleton as Lerp<Factor>>::Output
source§impl<'a, Factor> Lerp<Factor> for &'a BipedSmallSkeleton
impl<'a, Factor> Lerp<Factor> for &'a BipedSmallSkeleton
type Output = BipedSmallSkeleton
fn lerp_unclamped_precise( from: &'a BipedSmallSkeleton, to: &'a BipedSmallSkeleton, factor: Factor, ) -> <&'a BipedSmallSkeleton as Lerp<Factor>>::Output
fn lerp_unclamped( from: &'a BipedSmallSkeleton, to: &'a BipedSmallSkeleton, factor: Factor, ) -> <&'a BipedSmallSkeleton as Lerp<Factor>>::Output
source§impl<'a, Factor> Lerp<Factor> for &'a BirdLargeSkeleton
impl<'a, Factor> Lerp<Factor> for &'a BirdLargeSkeleton
type Output = BirdLargeSkeleton
fn lerp_unclamped_precise( from: &'a BirdLargeSkeleton, to: &'a BirdLargeSkeleton, factor: Factor, ) -> <&'a BirdLargeSkeleton as Lerp<Factor>>::Output
fn lerp_unclamped( from: &'a BirdLargeSkeleton, to: &'a BirdLargeSkeleton, factor: Factor, ) -> <&'a BirdLargeSkeleton as Lerp<Factor>>::Output
source§impl<'a, Factor> Lerp<Factor> for &'a BirdMediumSkeleton
impl<'a, Factor> Lerp<Factor> for &'a BirdMediumSkeleton
type Output = BirdMediumSkeleton
fn lerp_unclamped_precise( from: &'a BirdMediumSkeleton, to: &'a BirdMediumSkeleton, factor: Factor, ) -> <&'a BirdMediumSkeleton as Lerp<Factor>>::Output
fn lerp_unclamped( from: &'a BirdMediumSkeleton, to: &'a BirdMediumSkeleton, factor: Factor, ) -> <&'a BirdMediumSkeleton as Lerp<Factor>>::Output
source§impl<'a, Factor> Lerp<Factor> for &'a CharacterSkeleton
impl<'a, Factor> Lerp<Factor> for &'a CharacterSkeleton
type Output = CharacterSkeleton
fn lerp_unclamped_precise( from: &'a CharacterSkeleton, to: &'a CharacterSkeleton, factor: Factor, ) -> <&'a CharacterSkeleton as Lerp<Factor>>::Output
fn lerp_unclamped( from: &'a CharacterSkeleton, to: &'a CharacterSkeleton, factor: Factor, ) -> <&'a CharacterSkeleton as Lerp<Factor>>::Output
source§impl<'a, Factor> Lerp<Factor> for &'a CrustaceanSkeleton
impl<'a, Factor> Lerp<Factor> for &'a CrustaceanSkeleton
type Output = CrustaceanSkeleton
fn lerp_unclamped_precise( from: &'a CrustaceanSkeleton, to: &'a CrustaceanSkeleton, factor: Factor, ) -> <&'a CrustaceanSkeleton as Lerp<Factor>>::Output
fn lerp_unclamped( from: &'a CrustaceanSkeleton, to: &'a CrustaceanSkeleton, factor: Factor, ) -> <&'a CrustaceanSkeleton as Lerp<Factor>>::Output
source§impl<'a, Factor> Lerp<Factor> for &'a DragonSkeleton
impl<'a, Factor> Lerp<Factor> for &'a DragonSkeleton
type Output = DragonSkeleton
fn lerp_unclamped_precise( from: &'a DragonSkeleton, to: &'a DragonSkeleton, factor: Factor, ) -> <&'a DragonSkeleton as Lerp<Factor>>::Output
fn lerp_unclamped( from: &'a DragonSkeleton, to: &'a DragonSkeleton, factor: Factor, ) -> <&'a DragonSkeleton as Lerp<Factor>>::Output
source§impl<'a, Factor> Lerp<Factor> for &'a FishMediumSkeleton
impl<'a, Factor> Lerp<Factor> for &'a FishMediumSkeleton
type Output = FishMediumSkeleton
fn lerp_unclamped_precise( from: &'a FishMediumSkeleton, to: &'a FishMediumSkeleton, factor: Factor, ) -> <&'a FishMediumSkeleton as Lerp<Factor>>::Output
fn lerp_unclamped( from: &'a FishMediumSkeleton, to: &'a FishMediumSkeleton, factor: Factor, ) -> <&'a FishMediumSkeleton as Lerp<Factor>>::Output
source§impl<'a, Factor> Lerp<Factor> for &'a FishSmallSkeleton
impl<'a, Factor> Lerp<Factor> for &'a FishSmallSkeleton
type Output = FishSmallSkeleton
fn lerp_unclamped_precise( from: &'a FishSmallSkeleton, to: &'a FishSmallSkeleton, factor: Factor, ) -> <&'a FishSmallSkeleton as Lerp<Factor>>::Output
fn lerp_unclamped( from: &'a FishSmallSkeleton, to: &'a FishSmallSkeleton, factor: Factor, ) -> <&'a FishSmallSkeleton as Lerp<Factor>>::Output
source§impl<'a, Factor> Lerp<Factor> for &'a FixtureSkeleton
impl<'a, Factor> Lerp<Factor> for &'a FixtureSkeleton
type Output = FixtureSkeleton
fn lerp_unclamped( _from: &'a FixtureSkeleton, _to: &'a FixtureSkeleton, _factor: Factor, ) -> <&'a FixtureSkeleton as Lerp<Factor>>::Output
fn lerp_unclamped_precise( _from: &'a FixtureSkeleton, _to: &'a FixtureSkeleton, _factor: Factor, ) -> <&'a FixtureSkeleton as Lerp<Factor>>::Output
source§impl<'a, Factor> Lerp<Factor> for &'a GolemSkeleton
impl<'a, Factor> Lerp<Factor> for &'a GolemSkeleton
type Output = GolemSkeleton
fn lerp_unclamped_precise( from: &'a GolemSkeleton, to: &'a GolemSkeleton, factor: Factor, ) -> <&'a GolemSkeleton as Lerp<Factor>>::Output
fn lerp_unclamped( from: &'a GolemSkeleton, to: &'a GolemSkeleton, factor: Factor, ) -> <&'a GolemSkeleton as Lerp<Factor>>::Output
source§impl<'a, Factor> Lerp<Factor> for &'a ItemDropSkeleton
impl<'a, Factor> Lerp<Factor> for &'a ItemDropSkeleton
type Output = ItemDropSkeleton
fn lerp_unclamped_precise( from: &'a ItemDropSkeleton, to: &'a ItemDropSkeleton, factor: Factor, ) -> <&'a ItemDropSkeleton as Lerp<Factor>>::Output
fn lerp_unclamped( from: &'a ItemDropSkeleton, to: &'a ItemDropSkeleton, factor: Factor, ) -> <&'a ItemDropSkeleton as Lerp<Factor>>::Output
source§impl<'a, Factor> Lerp<Factor> for &'a ObjectSkeleton
impl<'a, Factor> Lerp<Factor> for &'a ObjectSkeleton
type Output = ObjectSkeleton
fn lerp_unclamped_precise( from: &'a ObjectSkeleton, to: &'a ObjectSkeleton, factor: Factor, ) -> <&'a ObjectSkeleton as Lerp<Factor>>::Output
fn lerp_unclamped( from: &'a ObjectSkeleton, to: &'a ObjectSkeleton, factor: Factor, ) -> <&'a ObjectSkeleton as Lerp<Factor>>::Output
source§impl<'a, Factor> Lerp<Factor> for &'a PluginSkeleton
impl<'a, Factor> Lerp<Factor> for &'a PluginSkeleton
type Output = PluginSkeleton
fn lerp_unclamped_precise( from: &'a PluginSkeleton, to: &'a PluginSkeleton, factor: Factor, ) -> <&'a PluginSkeleton as Lerp<Factor>>::Output
fn lerp_unclamped( from: &'a PluginSkeleton, to: &'a PluginSkeleton, factor: Factor, ) -> <&'a PluginSkeleton as Lerp<Factor>>::Output
source§impl<'a, Factor> Lerp<Factor> for &'a QuadrupedLowSkeleton
impl<'a, Factor> Lerp<Factor> for &'a QuadrupedLowSkeleton
type Output = QuadrupedLowSkeleton
fn lerp_unclamped_precise( from: &'a QuadrupedLowSkeleton, to: &'a QuadrupedLowSkeleton, factor: Factor, ) -> <&'a QuadrupedLowSkeleton as Lerp<Factor>>::Output
fn lerp_unclamped( from: &'a QuadrupedLowSkeleton, to: &'a QuadrupedLowSkeleton, factor: Factor, ) -> <&'a QuadrupedLowSkeleton as Lerp<Factor>>::Output
source§impl<'a, Factor> Lerp<Factor> for &'a QuadrupedMediumSkeleton
impl<'a, Factor> Lerp<Factor> for &'a QuadrupedMediumSkeleton
type Output = QuadrupedMediumSkeleton
fn lerp_unclamped_precise( from: &'a QuadrupedMediumSkeleton, to: &'a QuadrupedMediumSkeleton, factor: Factor, ) -> <&'a QuadrupedMediumSkeleton as Lerp<Factor>>::Output
fn lerp_unclamped( from: &'a QuadrupedMediumSkeleton, to: &'a QuadrupedMediumSkeleton, factor: Factor, ) -> <&'a QuadrupedMediumSkeleton as Lerp<Factor>>::Output
source§impl<'a, Factor> Lerp<Factor> for &'a QuadrupedSmallSkeleton
impl<'a, Factor> Lerp<Factor> for &'a QuadrupedSmallSkeleton
type Output = QuadrupedSmallSkeleton
fn lerp_unclamped_precise( from: &'a QuadrupedSmallSkeleton, to: &'a QuadrupedSmallSkeleton, factor: Factor, ) -> <&'a QuadrupedSmallSkeleton as Lerp<Factor>>::Output
fn lerp_unclamped( from: &'a QuadrupedSmallSkeleton, to: &'a QuadrupedSmallSkeleton, factor: Factor, ) -> <&'a QuadrupedSmallSkeleton as Lerp<Factor>>::Output
source§impl<'a, Factor> Lerp<Factor> for &'a ShipSkeleton
impl<'a, Factor> Lerp<Factor> for &'a ShipSkeleton
type Output = ShipSkeleton
fn lerp_unclamped_precise( from: &'a ShipSkeleton, to: &'a ShipSkeleton, factor: Factor, ) -> <&'a ShipSkeleton as Lerp<Factor>>::Output
fn lerp_unclamped( from: &'a ShipSkeleton, to: &'a ShipSkeleton, factor: Factor, ) -> <&'a ShipSkeleton as Lerp<Factor>>::Output
source§impl<'a, Factor> Lerp<Factor> for &'a TheropodSkeleton
impl<'a, Factor> Lerp<Factor> for &'a TheropodSkeleton
type Output = TheropodSkeleton
fn lerp_unclamped_precise( from: &'a TheropodSkeleton, to: &'a TheropodSkeleton, factor: Factor, ) -> <&'a TheropodSkeleton as Lerp<Factor>>::Output
fn lerp_unclamped( from: &'a TheropodSkeleton, to: &'a TheropodSkeleton, factor: Factor, ) -> <&'a TheropodSkeleton as Lerp<Factor>>::Output
Implementors§
source§impl<'a, P, O, S, Factor> Lerp<Factor> for &'a vek::transform::repr_c::Transform<P, O, S>
impl<'a, P, O, S, Factor> Lerp<Factor> for &'a vek::transform::repr_c::Transform<P, O, S>
LERP on a Transform
is defined as LERP-ing between the positions and scales,
and performing SLERP between the orientations.
source§impl<'a, P, O, S, Factor> Lerp<Factor> for &'a vek::transform::repr_simd::Transform<P, O, S>
impl<'a, P, O, S, Factor> Lerp<Factor> for &'a vek::transform::repr_simd::Transform<P, O, S>
LERP on a Transform
is defined as LERP-ing between the positions and scales,
and performing SLERP between the orientations.
source§impl<'a, T, Factor> Lerp<Factor> for &'a vek::quaternion::repr_c::Quaternion<T>
impl<'a, T, Factor> Lerp<Factor> for &'a vek::quaternion::repr_c::Quaternion<T>
The Lerp
implementation for quaternion is the “Normalized LERP”.
type Output = Quaternion<T>
source§impl<'a, T, Factor> Lerp<Factor> for &'a vek::quaternion::repr_simd::Quaternion<T>
impl<'a, T, Factor> Lerp<Factor> for &'a vek::quaternion::repr_simd::Quaternion<T>
The Lerp
implementation for quaternion is the “Normalized LERP”.
type Output = Quaternion<T>
source§impl<P, O, S, Factor> Lerp<Factor> for vek::transform::repr_c::Transform<P, O, S>
impl<P, O, S, Factor> Lerp<Factor> for vek::transform::repr_c::Transform<P, O, S>
LERP on a Transform
is defined as LERP-ing between the positions and scales,
and performing SLERP between the orientations.
source§impl<P, O, S, Factor> Lerp<Factor> for vek::transform::repr_simd::Transform<P, O, S>
impl<P, O, S, Factor> Lerp<Factor> for vek::transform::repr_simd::Transform<P, O, S>
LERP on a Transform
is defined as LERP-ing between the positions and scales,
and performing SLERP between the orientations.
source§impl<T, Factor> Lerp<Factor> for vek::quaternion::repr_c::Quaternion<T>
impl<T, Factor> Lerp<Factor> for vek::quaternion::repr_c::Quaternion<T>
The Lerp
implementation for quaternion is the “Normalized LERP”.
type Output = Quaternion<T>
source§impl<T, Factor> Lerp<Factor> for vek::quaternion::repr_simd::Quaternion<T>
impl<T, Factor> Lerp<Factor> for vek::quaternion::repr_simd::Quaternion<T>
The Lerp
implementation for quaternion is the “Normalized LERP”.