Skip to content

Commit

Permalink
Updated to latest rustc
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchmindtree committed Feb 9, 2015
1 parent c67076f commit b57755d
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 18 deletions.
29 changes: 22 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ version = "0.0.1"
authors = ["mitchmindtree <mitchell.nordine@gmail.com>"]

[dependencies]
rustc-serialize = "0.2.10"
rand = "0.1.2"
rustc-serialize = "0.2.12"

[dependencies.time]
git = "https://github.com/rust-lang/time"
70 changes: 63 additions & 7 deletions src/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,82 @@ impl<P> Envelope<P> where P: Point, <P as Point>::F: Float {
/// Interpolate between points.
#[inline]
fn interpolate(&self, x: <P as Point>::F, start: P, end: P) -> <P as Point>::F {

// NOTE: Temporary fix for assoc types weirdness... Remove when possible!
fn temp_add<T: Float>(a: T, b: T) -> T { a + b }
fn temp_sub<T: Float>(a: T, b: T) -> T { a - b }
fn temp_mul<T: Float>(a: T, b: T) -> T { a * b }
fn temp_div<T: Float>(a: T, b: T) -> T { a / b }

// Find x passed from start of interpolation.
let x_pos = x - start.x();
//let x_pos = x - start.x();
let x_pos = temp_sub(x, start.x());

// Find duration of interpolation.
let duration = end.x() - start.x();
//let duration = end.x() - start.x();
let duration = temp_sub(end.x(), start.x());

// Set gradient for interpolation.
let gradient_y = end.y() - start.y();
//let gradient_y: <P as Point>::F = end.y() - start.y();
let gradient_y = temp_sub(end.y(), start.y());

if gradient_y == Float::zero() { return start.y() }
//let gradient = duration / gradient_y;
let half_gradient_y = gradient_y / two();

//let half_gradient_y: <P as Point>::F = gradient_y / two();
let half_gradient_y = temp_div(gradient_y, two());

// Consider bezier curve.
let y2 = half_gradient_y + start.curve() * half_gradient_y;
let perc_x = x_pos / duration;
//let y2 = half_gradient_y + start.curve() * half_gradient_y;
let y2 = temp_add(half_gradient_y, temp_mul(start.curve(), half_gradient_y));

//let perc_x = x_pos / duration;
let perc_x = temp_div(x_pos, duration);


// Re-adjust linear trajectory.
let ya = bezier_pt(Float::zero(), y2, perc_x);
let yb = bezier_pt(y2, gradient_y, perc_x);
bezier_pt(ya, yb, perc_x) + start.y()

//bezier_pt(ya, yb, perc_x) + start.y()
temp_add(bezier_pt(ya, yb, perc_x), start.y())
}

}

// /// Interpolate between two points and return y for the given x.
// #[inline]
// fn interpolate<P>(x: <P as Point>::F, start: P, end: P) -> <P as Point>::F
// where
// P: Point,
// <P as Point>::F: Float,
// {
//
// // Find x passed from start of interpolation.
// let x_pos = x - start.x();
//
// // Find duration of interpolation.
// let duration = end.x() - start.x();
//
// // Set gradient for interpolation.
// let gradient_y = end.y() - start.y();
//
// // If there is no gradient between the points, simply return y from one of the points.
// if gradient_y == Float::zero() { return start.y() }
//
// let half_gradient_y: <P as Point>::F = gradient_y / two();
//
// // Consider bezier curve.
// let y2 = half_gradient_y + start.curve() * half_gradient_y;
// let perc_x = x_pos / duration;
//
// // Re-adjust linear trajectory.
// let ya = bezier_pt(Float::zero(), y2, perc_x);
// let yb = bezier_pt(y2, gradient_y, perc_x);
//
// bezier_pt(ya, yb, perc_x) + start.y()
// }

/// Get bezier point for bezier curve.
#[inline]
fn bezier_pt<F>(n1: F, n2: F, perc: F) -> F where F: Float {
Expand Down
2 changes: 1 addition & 1 deletion src/gaussian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
//!
use math::map_range;
use rand::{Rand, random};
use std::fmt::Show;
use std::num::{Float, FromPrimitive};
use std::rand::{Rand, random};

static mut NEXT_VALUE: Option<f64> = None;

Expand Down
2 changes: 2 additions & 0 deletions src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub mod prev_iter {
pub mod sample_on {

/// Sample from the current iterator every time an iteration occurs on another iterator.
/// This is primarily used for binding an iterator to another timed iterator. i.e.
/// `(0..1000).sample_on(Fps::new(60.0))`.
pub trait SampleOn: Sized + Iterator {
#[inline]
fn sample_on<O: Iterator>(self, other: O) -> Items<Self, O> {
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
//!
//!
#![feature(core, io, rand, std_misc)]
#![feature(core, io, std_misc)]

extern crate rand;
extern crate "rustc-serialize" as rustc_serialize;
extern crate time;

Expand Down
2 changes: 1 addition & 1 deletion src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//!
use std::num::{Float, FromPrimitive, ToPrimitive};
use std::rand;
use rand;
use math;

/// Signal generic struct for simplifying dsp signal generation.
Expand Down

0 comments on commit b57755d

Please sign in to comment.