Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix https://github.com/rust-lang/rust/pull/18827 related issues. #25

Merged
merged 1 commit into from
Nov 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/gen.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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