Skip to content

Commit

Permalink
Fixed utils::interpolation::InterpolationMethod to be object-safe (wi…
Browse files Browse the repository at this point in the history
…thout associated consts) (rust-lang/rust#29646)
  • Loading branch information
perfah committed Jul 27, 2017
1 parent 9658e75 commit 3b68dd1
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/rustland/utils/interpolation/methods.rs
@@ -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 }
}

0 comments on commit 3b68dd1

Please sign in to comment.