Skip to content

Commit

Permalink
Fix rust-lang/rust#18827 related issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsr committed Nov 15, 2014
1 parent 0f5cc98 commit 32369a8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/gen.rs
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::num::cast;
use std::num::{cast, Float};

use util::{lerp,scurve3,scurve5};

Expand Down
8 changes: 4 additions & 4 deletions src/model.rs
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::num::{zero,one};
use std::num::Float;

use util::lerp;
use source::Source;
Expand All @@ -28,8 +28,8 @@ impl<'a, S:Source, F:Float> Line<'a, S, F> {

pub fn new(src: &'a S) -> Line<'a, S, F> {
Line {
start: [zero(), zero(), zero()],
end: [one(), one(), one()],
start: [Float::zero(), Float::zero(), Float::zero()],
end: [Float::one(), Float::one(), Float::one()],
source: src,
}
}
Expand All @@ -53,6 +53,6 @@ impl<'a, S:Source> Plane<'a, S> {
}

pub fn get<F:Float>(&self, x: F, y: F) -> F {
self.source.get(x, y, zero())
self.source.get(x, y, Float::zero())
}
}
2 changes: 2 additions & 0 deletions src/source/mod.rs
@@ -1,3 +1,5 @@
use std::num::Float;

pub use self::perlin::Perlin;
pub use self::ridgedmulti::RidgedMulti;

Expand Down
6 changes: 3 additions & 3 deletions src/source/perlin.rs
Expand Up @@ -18,7 +18,7 @@

use std::rand;
use std::rand::Rng;
use std::num::{zero, one, cast};
use std::num::{cast, Float};

use super::Source;
use Quality;
Expand Down Expand Up @@ -98,8 +98,8 @@ impl Perlin {

impl Source for Perlin {
fn get<F:Float>(&self, x: F, y: F, z: F) -> F {
let mut value : F = zero();
let mut cur_persistence = one();
let mut value : F = Float::zero();
let mut cur_persistence = Float::one();

let frequency = cast(self.frequency).unwrap();
let lacunarity = cast(self.lacunarity).unwrap();
Expand Down
10 changes: 5 additions & 5 deletions src/source/ridgedmulti.rs
Expand Up @@ -14,7 +14,7 @@
// limitations under the License.

use std;
use std::num::{zero,one,abs,cast};
use std::num::{cast, Float};
use std::rand::Rng;

use util::clamp;
Expand Down Expand Up @@ -106,8 +106,8 @@ impl RidgedMulti {
impl Source for RidgedMulti {

fn get<F:Float>(&self, x: F, y: F, z: F) -> F {
let mut value : F = zero();
let mut weight : F = one();
let mut value : F = Float::zero();
let mut weight : F = Float::one();

let offset : F = cast(self.offset).unwrap();
let gain = cast(self.gain).unwrap();
Expand All @@ -126,12 +126,12 @@ impl Source for RidgedMulti {
y.clone(),
z.clone(), seed, self.quality);

let signal = abs(signal);
let signal = signal.abs();
let signal = offset - signal;
let signal = signal * signal;
let signal = signal * weight;

weight = clamp(signal * gain, zero(), one());
weight = clamp(signal * gain, Float::zero(), Float::one());

value = value + (signal * cast(self.spectral_weights[i]).unwrap());

Expand Down
4 changes: 2 additions & 2 deletions src/util.rs
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::num::cast;
use std::num::{cast, Float};

#[inline]
pub fn lerp<T: Float>(t: T, a: T, b: T) -> T {
Expand All @@ -32,7 +32,7 @@ pub fn scurve5<T: Float>(t: T) -> T {
t * t * t * (t * (t * cast(6i).unwrap() - cast(15i).unwrap()) + cast(10i).unwrap())
}

pub fn clamp<T: Primitive>(val: T, min: T, max: T) -> T {
pub fn clamp<F: Float>(val: F, min: F, max: F) -> F {
if val < min {
min
} else if val > max {
Expand Down

0 comments on commit 32369a8

Please sign in to comment.