From 32369a8c3d3caac2cf19d40281586336a141816b Mon Sep 17 00:00:00 2001 From: Jonas Matser Date: Sat, 15 Nov 2014 15:58:40 +0100 Subject: [PATCH] Fix https://github.com/rust-lang/rust/pull/18827 related issues. --- src/gen.rs | 2 +- src/model.rs | 8 ++++---- src/source/mod.rs | 2 ++ src/source/perlin.rs | 6 +++--- src/source/ridgedmulti.rs | 10 +++++----- src/util.rs | 4 ++-- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/gen.rs b/src/gen.rs index 3de31b9a..89d9043d 100644 --- a/src/gen.rs +++ b/src/gen.rs @@ -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}; diff --git a/src/model.rs b/src/model.rs index 736a6d78..d9c7a560 100644 --- a/src/model.rs +++ b/src/model.rs @@ -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; @@ -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, } } @@ -53,6 +53,6 @@ impl<'a, S:Source> Plane<'a, S> { } pub fn get(&self, x: F, y: F) -> F { - self.source.get(x, y, zero()) + self.source.get(x, y, Float::zero()) } } diff --git a/src/source/mod.rs b/src/source/mod.rs index fb824051..673b84e8 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -1,3 +1,5 @@ +use std::num::Float; + pub use self::perlin::Perlin; pub use self::ridgedmulti::RidgedMulti; diff --git a/src/source/perlin.rs b/src/source/perlin.rs index 8e80a0b4..fa9b5635 100644 --- a/src/source/perlin.rs +++ b/src/source/perlin.rs @@ -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; @@ -98,8 +98,8 @@ impl Perlin { impl Source for Perlin { fn get(&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(); diff --git a/src/source/ridgedmulti.rs b/src/source/ridgedmulti.rs index 99f51f3f..d1531b0e 100644 --- a/src/source/ridgedmulti.rs +++ b/src/source/ridgedmulti.rs @@ -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; @@ -106,8 +106,8 @@ impl RidgedMulti { impl Source for RidgedMulti { fn get(&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(); @@ -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()); diff --git a/src/util.rs b/src/util.rs index aa050d3c..2a041985 100644 --- a/src/util.rs +++ b/src/util.rs @@ -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: T, a: T, b: T) -> T { @@ -32,7 +32,7 @@ pub fn scurve5(t: T) -> T { t * t * t * (t * (t * cast(6i).unwrap() - cast(15i).unwrap()) + cast(10i).unwrap()) } -pub fn clamp(val: T, min: T, max: T) -> T { +pub fn clamp(val: F, min: F, max: F) -> F { if val < min { min } else if val > max {