Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed utils::interpolation::InterpolationMethod to be object-safe (wi…
…thout associated consts) (rust-lang/rust#29646)
- Loading branch information
Showing
1 changed file
with
8 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,32 @@ | ||
use common::definitions::DefaultNumericType; | ||
|
||
pub trait InterpolationMethod: Send{ | ||
const left_bound: DefaultNumericType; | ||
const right_bound: DefaultNumericType; | ||
|
||
fn calc_progression(&self, x: DefaultNumericType) -> DefaultNumericType; | ||
fn get_left_bound(&self) -> DefaultNumericType { Self::left_bound } | ||
fn get_right_bound(&self) -> DefaultNumericType { Self::right_bound } | ||
fn get_left_bound(&self) -> DefaultNumericType; | ||
fn get_right_bound(&self) -> DefaultNumericType; | ||
} | ||
|
||
/// An interpolation method that keeps the motion speed at a constant rate. | ||
pub struct LinearInterpolator; | ||
impl InterpolationMethod for LinearInterpolator{ | ||
const left_bound: DefaultNumericType = 0f32; | ||
const right_bound: DefaultNumericType = 10f32; | ||
|
||
fn calc_progression(&self, x: f32) -> f32 { x } | ||
fn get_left_bound(&self) -> DefaultNumericType { 0f32 } | ||
fn get_right_bound(&self) -> DefaultNumericType { 10f32 } | ||
} | ||
|
||
|
||
/// An interpolation method that accelerates the motion quadratically. | ||
pub struct QuadraticInterpolator; | ||
impl InterpolationMethod for QuadraticInterpolator{ | ||
const left_bound: DefaultNumericType = 0f32; | ||
const right_bound: DefaultNumericType = 10f32; | ||
|
||
fn calc_progression(&self, x: f32) -> f32 { x * x } | ||
fn get_left_bound(&self) -> DefaultNumericType { 0f32 } | ||
fn get_right_bound(&self) -> DefaultNumericType { 10f32 } | ||
} | ||
|
||
/// An interpolation method that decelerates the motion. | ||
pub struct DecelerationInterpolator; | ||
impl InterpolationMethod for DecelerationInterpolator{ | ||
const left_bound: DefaultNumericType = 0f32; | ||
const right_bound: DefaultNumericType = 1.57f32; | ||
|
||
fn calc_progression(&self, x: f32) -> f32 { x.sin() * x.sin() } | ||
fn get_left_bound(&self) -> DefaultNumericType { 0f32 } | ||
fn get_right_bound(&self) -> DefaultNumericType { 1.57f32 } | ||
} |